当前位置:网站首页>mysql优化,sql执行非常卡顿,不改变sql结构达到10秒内结束
mysql优化,sql执行非常卡顿,不改变sql结构达到10秒内结束
2022-06-23 03:36:00 【CSDN问答】
一个sql执行非常卡顿,不改变sql结构,9万多+8万多数据,达到10秒内结束查询
原sql SELECT * FROM a_itemsListVer WHERE (locate('防水材料,防水卷材', waterproof) > 0 OR itemsListId IN (SELECT itemsListId FROM a_itemsListOtherVer WHERE locate('防水卷材', waterproofMemo) > 0 ))
//样例只保留了部分关键字段。
//表一 9万多条数据
CREATE TABLE a_itemsListVer (id varchar(20) NOT NULL,
itemsListId varchar(20) NOT NULL COMMENT '主项目id',waterproof varchar(150) NOT NULL DEFAULT '',
PRIMARY KEY (id),
KEY fId (itemsListId),
KEY waterproof (waterproof) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;
//样例数据 INSERT INTO a_itemsListVer VALUES ('zgypu9zqg5ys', 'vs6h24c5b79w', '防水卷材');
//表二 8万多条数据
CREATE TABLE a_itemsListOtherVer (id varchar(20) NOT NULL COMMENT 'itemsListVerId相同',itemsListId varchar(20) NOT NULL COMMENT '主项目id',waterproofMemo varchar(200) NOT NULL DEFAULT '',
updateTime datetime NOT NULL COMMENT '更新时间',time datetime NOT NULL COMMENT '创建时间',
PRIMARY KEY (id),
KEY itemsListId (itemsListId),
KEY waterproofMemo (waterproofMemo) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
//样例数据 INSERT INTO a_itemsListOtherVer VALUES ('zgzrzulitiid', 'vs6h24c5b79w', '防水卷材', '2022-6-16 11:06:41', '2022-6-16 11:06:46');
目前运行结果都是超过几分钟。数据库服务器配置2核4G
改造的最后一版还是很卡
SELECT COUNT(*) FROM a_itemsListVer WHERE ( if(locate('防水材料,防水卷材', waterproof)>0 , true ,
if(
locate ((SELECT GROUP_CONCAT(waterproofMemo) FROM a_itemsListOtherVer WHERE itemsListId=a_itemsListVer.itemsListId ),'防水卷材' )>0
,true,0 ) ) )
我想要达到的结果。能正常运行,10秒内结束查询
边栏推荐
- Flink practice tutorial: advanced 7- basic operation and maintenance
- Configuring multi cluster management using kubectl
- Auto rename when uploading pictures on WordPress media
- How to realize data transaction
- Easysearcher cannot find the IP address of easynvr hardware. How to solve it?
- Jmeter- (V) simulated user concurrent login for interface test
- 聊聊内存模型和内存序
- How to get started with apiccloud app and multi terminal development of applet based on zero Foundation
- [leetcode] flip linked list II
- 嵌入式软件测试工具TPT18更新全解析
猜你喜欢
随机推荐
How to store easydss version 3.0 video files in other free disks?
Tencent cloud tcapulusdb helps tmeland, the first virtual Music Carnival in China, and tens of thousands of people cross the new year together!
[leetcode] sum of two numbers II
TDesign update weekly report (the second week of January 2022)
JSON. Function of the stringify() optional parameter
centos7 安装 MySQL 及配置 innodb_ruby
【贪心】leetcode991. Broken Calculator
How to get started with apiccloud app and multi terminal development of applet based on zero Foundation
【owt】owt-client-native-p2p-e2e-test vs2017构建 4 : 第三方库的构建及链接p2pmfc.exe
Navar's Treasure Book: the principle of getting rich without luck
1058 multiple choice questions (20 points)
Firewall and IP security policy configuration
LRU cache
innodb_ruby 视角下 MySQL 记录增删改
The MIUI 13 development version of Xiaomi mobile phone blocks the chrome application and cannot be opened after installation
What is the potential of dmail based on Web3.0? First round financing of $10 million?
Stress testing with locust on rainbow
[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation
【二分】leetcode1011. Capacity To Ship Packages Within D Days
[two points] leetcode1011 Capacity To Ship Packages Within D Days









