当前位置:网站首页>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秒内结束查询
边栏推荐
- centos7 安装 MySQL 及配置 innodb_ruby
- [machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation
- 选择排序法
- Svn local computer storage configuration
- An implementation of warning bombing
- What if the self incrementing IDs of online MySQL are exhausted?
- 数据加密技术之源代码加密
- Preliminary sequencing problem
- Navar's Treasure Book: the principle of getting rich without luck
- Official announcement! The Hong Kong Zhuhai Macao Bridge is finally here!
猜你喜欢

【二分】leetcode1011. Capacity To Ship Packages Within D Days

Static code block, code block, constructor execution order

The first batch of job hunting after 00: don't misread their "different"

【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现

嵌入式软件测试工具TPT18更新全解析

Jmeter- (V) simulated user concurrent login for interface test

LRU cache

1-1 introduction to VMWare
![Analysis of the number of urban residents covered by basic medical insurance, their treatment and medical treatment in other places in China in 2021 [figure]](/img/81/4d3cb059f700dd9243645e64023be7.jpg)
Analysis of the number of urban residents covered by basic medical insurance, their treatment and medical treatment in other places in China in 2021 [figure]

Insert sort directly
随机推荐
Regeorg actual attack and defense
Banknext microservice: a case study
Nezha panel modifies logo, small icon and other information
China's economy has entered the stage of "the third mock examination coexisting", and JD and Shopify have jointly arranged global DTC
Using jhipster to build microservice architecture
TRTC setaudioroute invalid problem
Jmeter- (V) simulated user concurrent login for interface test
If there is a smart bus visualization platform, can "beginning" restart indefinitely?
Centos7 installing MySQL and configuring InnoDB_ ruby
Initialize MySQL Gorm through yaml file
【LeetCode】23. Merge K ascending linked lists
Even if you don't learn gradle, these common development operations are worth mastering
R tree of search tree
【owt】owt-client-native-p2p-e2e-test vs2017构建 4 : 第三方库的构建及链接p2pmfc.exe
Fetch request details
线上MySQL的自增id用尽怎么办?
How to store easydss version 3.0 video files in other free disks?
Postman calls relevant interfaces of CLS API 3.0
Official announcement! The Hong Kong Zhuhai Macao Bridge is finally here!
Learning summary of spanquery source code