国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|數據庫技術|

服務器之家 - 數據庫 - Mysql - MySql模糊查詢json關鍵字檢索方案示例

MySql模糊查詢json關鍵字檢索方案示例

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

大家好,本篇文章主要講的是MySql模糊查詢json關鍵字檢索方案示例,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下哦,方便下次瀏覽

前言

?最近在項目中遇到這樣一個需求:需要在數據表中檢索包含指定內容的結果集,該字段的數據類型為text,存儲的內容是json格式,具體表結構如下:

?
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 '產品名稱' collate 'utf8mb4_general_ci',
    `price` decimal(10,2) unsigned not null default '0.00' comment '產品價格',
    `suit` text not null comment '適用門店 json格式保存門店id' collate 'utf8mb4_general_ci',
    `status` tinyint(3) not null default '0' comment '狀態 1-正常 0-刪除 2-下架',
    `create_date` datetime not null default current_timestamp comment '發布時間',
    `update_date` datetime not null default current_timestamp on update current_timestamp comment '修改時間',
    primary key (`id`) using btree
)
comment='產品表'
collate='utf8mb4_general_ci'
engine=innodb
auto_increment=1
;

表數據如下:

MySql模糊查詢json關鍵字檢索方案示例

現需求:查找 suit->hotel 中包含10001的數據。

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

方案一:

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

方案二:

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

方案三:

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

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

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

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

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

總結

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 免费在线a| 亚洲精品成人 | 亚洲国产福利一区 | 亚洲狼人色| 午夜精品视频在线观看 | 亚洲一区 日韩精品 中文字幕 | 国产视频亚洲 | 有码一区| 亚洲电影第二页 | 97操视频| 国外爱爱视频 | 日韩一区二区在线播放 | 欧美精品在线看 | 久久精品影片 | 亚洲视频免费观看 | 中文字幕精品视频 | 国内精品在线视频 | 日韩精品视频在线播放 | 亚洲国产成人av好男人在线观看 | 欧美精品一区二区视频 | 淫语视频| 91丨九色丨国产 | 欧美区日韩区 | 精品中文字幕一区二区 | 日韩电影在线看 | 日韩在线一区二区三区 | 成人在线h| 龙珠z国语291集普通话 | 黄网在线免费观看 | 精品久久久久久久久久久久久久久久久久 | 欧美精品一区二区三区四区五区 | 国产一区二区三区四区五区密私 | 亚洲精品www久久久久久广东 | 色视频www在线播放国产人成 | 五月婷婷激情 | 成人黄色在线观看 | 日韩国产欧美视频 | 嫩草91| 欧美日韩中文字幕在线 | 国产亚洲一区二区三区 | 亚洲精品一区久久久久久 |