一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|數(shù)據(jù)庫(kù)技術(shù)|

服務(wù)器之家 - 數(shù)據(jù)庫(kù) - Mysql - MySql模糊查詢(xún)json關(guān)鍵字檢索方案示例

MySql模糊查詢(xún)json關(guān)鍵字檢索方案示例

2022-01-17 18:01PHPer自談 Mysql

大家好,本篇文章主要講的是MySql模糊查詢(xún)json關(guān)鍵字檢索方案示例,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話(huà)記得收藏一下哦,方便下次瀏覽

前言

?最近在項(xiàng)目中遇到這樣一個(gè)需求:需要在數(shù)據(jù)表中檢索包含指定內(nèi)容的結(jié)果集,該字段的數(shù)據(jù)類(lèi)型為text,存儲(chǔ)的內(nèi)容是json格式,具體表結(jié)構(gòu)如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
create table `product` (
    `id` int(11) unsigned not null auto_increment comment 'id',
    `name` varchar(100) not null default '' comment '產(chǎn)品名稱(chēng)' collate 'utf8mb4_general_ci',
    `price` decimal(10,2) unsigned not null default '0.00' comment '產(chǎn)品價(jià)格',
    `suit` text not null comment '適用門(mén)店 json格式保存門(mén)店id' collate 'utf8mb4_general_ci',
    `status` tinyint(3) not null default '0' comment '狀態(tài) 1-正常 0-刪除 2-下架',
    `create_date` datetime not null default current_timestamp comment '發(fā)布時(shí)間',
    `update_date` datetime not null default current_timestamp on update current_timestamp comment '修改時(shí)間',
    primary key (`id`) using btree
)
comment='產(chǎn)品表'
collate='utf8mb4_general_ci'
engine=innodb
auto_increment=1
;

表數(shù)據(jù)如下:

MySql模糊查詢(xún)json關(guān)鍵字檢索方案示例

現(xiàn)需求:查找 suit->hotel 中包含10001的數(shù)據(jù)。

通過(guò)谷歌百度查找,大致找到以下幾種方案:

方案一:

?
1
2
select * from product where suit like '%"10001"%';
#like方式不能使用索引,性能不佳,且準(zhǔn)確性不足

方案二:

?
1
2
select * from product where suit locate('"10001"', 'suit') > 0;
# locate方式和like存在相同問(wèn)題

方案三:

?
1
2
select * from product where suit != '' and json_contains('suit'->'$.hotel', '"10001"');
#以mysql內(nèi)置json函數(shù)查找,需要mysql5.7以上版本才能支持,準(zhǔn)確性較高,不能使用全文索引

方案四(最終采用方案):

?
1
2
select * from product where match(suit) against('+"10001"' in boolean mode);
#可使用全文索引,mysql關(guān)鍵字默認(rèn)限制最少4個(gè)字符,可在mysql.ini中修改 ft_min_word_len=2,重啟后生效

match() against() 更多使用方法可查看mysql參考手冊(cè):

https://dev.mysql.com/doc/refman/5.6/ja/fulltext-boolean.html

總結(jié)

到此這篇關(guān)于mysql模糊查詢(xún)json關(guān)鍵字檢索方案示例的文章就介紹到這了,更多相關(guān)mysql json關(guān)鍵字檢索內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!

原文鏈接:https://blog.csdn.net/zxw09332/article/details/121626111

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国内精品视频九九九九 | 99热精品久久 | 欧美男女交配 | 国产一级毛片潘金莲的奶头 | 午夜办公室在线观看高清电影 | 日韩a无吗一区二区三区 | 欧美久在线观看在线观看 | 无码国产成人777爽死在线观看 | 火影忍者小南裸羞羞漫画 | 四虎在线免费播放 | 亚洲精品在线免费 | 99久久999久久久综合精品涩 | 午夜电影三级还珠格格 | 国产精品午夜久久 | 二次元美女互摸隐私互扒 | 国产欧美精品一区二区三区 | 黄a级| 麻豆天美精东果冻传媒在线 | 亚洲精品一区二区三区在线观看 | 久久热r在线视频精品 | 免费午夜剧场 | mm131亚洲精品久久 | 青青青草国产线观 | 久热这里只有精品99国产6 | 我的奶头被客人吸的又肿又红 | 午夜国产福利视频一区 | 亚洲国产精品综合久久网络 | 青青草影院在线观看 | 亚洲 国产精品 日韩 | 亚洲精品第五页 | 国产欧美日韩精品一区二区三区 | 午夜人妻理论片天堂影院 | 5g影院天天5g天天爽大陆 | 99久久er这里只有精品17 | 久久精品一区 | 男人天堂bt | 亚洲激情在线 | 欧美又大又粗又爽视频 | 免费看又黄又爽又猛的视频软件- | 日韩v | 国产亚洲精品一区在线播 |