Mysql
 sql >> Cơ Sở Dữ Liệu >  >> RDS >> Mysql

Bất kỳ cách nào để đạt được tìm kiếm giống như văn bản đầy đủ trên InnoDB

sử dụng bảng đầy đủ myisam để lập chỉ mục trở lại các bảng innodb của bạn, ví dụ:

Xây dựng hệ thống của bạn bằng cách sử dụng innodb:

create table users (...) engine=innodb;

create table forums (...) engine=innodb;

create table threads
(
forum_id smallint unsigned not null,
thread_id int unsigned not null default 0,
user_id int unsigned not null,
subject varchar(255) not null, -- gonna want to search this... !!
created_date datetime not null,
next_reply_id int unsigned not null default 0,
view_count int unsigned not null default 0,
primary key (forum_id, thread_id) -- composite clustered PK index
)
engine=innodb;

Bây giờ là bảng tìm kiếm đầy đủ văn bản mà chúng tôi sẽ sử dụng chỉ để lập chỉ mục trở lại các bảng innodb của chúng tôi. Bạn có thể duy trì các hàng trong bảng này bằng cách sử dụng trình kích hoạt hoặc cập nhật hàng loạt hàng đêm, v.v.

create table threads_ft
(
forum_id smallint unsigned not null,
thread_id int unsigned not null default 0,
subject varchar(255) not null,
fulltext (subject), -- fulltext index on subject
primary key (forum_id, thread_id) -- composite non-clustered index 
)
engine=myisam;

Cuối cùng là thủ tục tìm kiếm được lưu trữ mà bạn gọi từ php / ứng dụng của mình:

drop procedure if exists ft_search_threads;
delimiter #

create procedure ft_search_threads
(
in p_search varchar(255)
)
begin

select
 t.*,
 f.title as forum_title,
 u.username,
 match(tft.subject) against (p_search in boolean mode) as rank
from
 threads_ft tft
inner join threads t on tft.forum_id = t.forum_id and tft.thread_id = t.thread_id
inner join forums f on t.forum_id = f.forum_id
inner join users u on t.user_id = u.user_id
where
 match(tft.subject) against (p_search in boolean mode) 
order by 
 rank desc
limit 100;

end;

call ft_search_threads('+innodb +clustered +index');

Hy vọng điều này sẽ giúp :)



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. cách nhận thời gian tải tính bằng mili giây hoặc micro giây trong mysql

  2. Ngăn chặn SQL Injection trong C

  3. Làm cách nào để lấy các từ phổ biến nhất trong bảng thông qua mysql?

  4. Cách thực hiện đếm trên một truy vấn liên hợp

  5. Làm thế nào để chặn yêu cầu DB? (MySQL)