sql處理千萬資料查詢緩慢問題

2022-09-08 23:27:29 字數 1496 閱讀 8561

給需要查詢的字段增加全文索引

alter table 表名 add fulltext ( `字段`)

增加完全文索引後如下sql

select * from `表名` where match(加了索引字段) against ('

查詢內容

' in boolean mode)

全文索引分三種模式:

一、自然語言查詢。這是mysql預設的全文搜尋方式

select  id,title from post where match(content) against ('

search keyword

')

或者顯式宣告使用自然語言搜尋方式

select  id,title from post where match(content) against ('

search keyword

' in natural language mode)

由於自然語言搜尋方式是預設模式,所以可以省略宣告模式的「in natural language mode」部分。

自然語言搜尋模式的麼特點:

1.忽略停詞(stopword),英語中頻繁出現的and/or/to等詞被認為是沒有實際搜尋的意義,搜尋這些不會獲得任何結果。

2.如果某個詞在資料集中頻繁出現的機率超過了50%,也會被認為是停詞,所以如果資料庫中只有一行資料,不管你怎麼全文搜尋都不能獲得結果。

3.搜尋結果都具有乙個相關度的資料,返回結果自動按相關度由高到低排列。

4.只針對獨立的單詞進行檢索,而不考慮單詞的區域性匹配,如搜尋box時,就不會將boxing作為檢索目標。

二、布林查詢。這種查詢方式的特點是沒有自然查詢模式中的50%規則,即便有詞語在資料集中頻繁出現的機率超過50%,也會被作為搜尋目標進行檢索並返回結果,而且檢索時單詞的區域性匹配也會被作為目標進行檢索。sql示例

select  id,title from post where match(content) against ('

search keyword

' in boolean mode)

三、帶子查詢擴充套件的自然語言查詢。 

select  id,title from post where match(content) against ('

search keyword

' in boolean mode with expansion)

暫時沒有明白這種模式。

如:

select * from info where match(title,info) against("

+mysql -yoursql"in

boolean mode);

select * from info where match(title,info) against('

+configured +database

');

MySQL處理千萬級資料查詢 分頁

mysql資料庫優化處理實現千萬級快速分頁分析,來看下吧。資料表 collect id,title info vtype 就這4個字段,其中 title 用定長,info 用text,id 是逐漸,vtype是tinyint,vtype是索引。這是乙個基本的新聞系統的簡單模型。現在往裡面填充資料,填...

MySQL處理千萬級資料查詢 分頁

mysql資料庫優化處理實現千萬級快速分頁分析,來看下吧。資料表 collect id,title info vtype 就這4個字段,其中 title 用定長,info 用text,id 是逐漸,vtype是tinyint,vtype是索引。這是乙個基本的新聞系統的簡單模型。現在往裡面填充資料,填...

MySQL處理千萬級資料查詢 分頁

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!mysql資料庫優化處理實現千萬級快速分頁分析,來看下吧。資料表 collect id,title info vtype 就這4個字段,其中 title 用定長,info 用text,id 是逐漸,vtype是tinyint,vtype是索引。這是...