当前位置:网站首页>MySQL optimization, the SQL execution is very stuck, and the SQL structure will not be changed until it ends in 10 seconds

MySQL optimization, the SQL execution is very stuck, and the SQL structure will not be changed until it ends in 10 seconds

2022-06-23 03:48:00 CSDN Q & A

One sql The execution is very catchy , Don't change sql structure ,9 More than ten thousand +8 More than ten thousand data , achieve 10 End query in seconds
primary sql SELECT * FROM a_itemsListVer WHERE (locate(' Waterproof material , Waterproofing membrane ', waterproof) > 0 OR itemsListId IN (SELECT itemsListId FROM a_itemsListOtherVer WHERE locate(' Waterproofing membrane ', waterproofMemo) > 0 ))

// The example only retains some key fields .
// Table 1 9 More than 10000 pieces of data
CREATE TABLE a_itemsListVer (
id varchar(20) NOT NULL,

itemsListId varchar(20) NOT NULL COMMENT ' Main item id',
waterproof varchar(150) NOT NULL DEFAULT '',

PRIMARY KEY (id),
KEY fId (itemsListId),

KEY waterproof (waterproof) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;
// Sample data INSERT INTO a_itemsListVer VALUES ('zgypu9zqg5ys', 'vs6h24c5b79w', ' Waterproofing membrane ');

// Table two 8 More than 10000 pieces of data
CREATE TABLE a_itemsListOtherVer (
id varchar(20) NOT NULL COMMENT 'itemsListVerId identical ',
itemsListId varchar(20) NOT NULL COMMENT ' Main item id',
waterproofMemo varchar(200) NOT NULL DEFAULT '',

updateTime datetime NOT NULL COMMENT ' Update time ',
time datetime NOT NULL COMMENT ' Creation time ',
PRIMARY KEY (id),
KEY itemsListId (itemsListId),

KEY waterproofMemo (waterproofMemo) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
// Sample data INSERT INTO a_itemsListOtherVer VALUES ('zgzrzulitiid', 'vs6h24c5b79w', ' Waterproofing membrane ', '2022-6-16 11:06:41', '2022-6-16 11:06:46');

At present, the running results are more than a few minutes . Database server configuration 2 nucleus 4G
The last version of the transformation is still too laggy

SELECT COUNT(*) FROM a_itemsListVer WHERE ( if(locate(' Waterproof material , Waterproofing membrane ', waterproof)>0 , true ,
if(
locate ((SELECT GROUP_CONCAT(waterproofMemo) FROM a_itemsListOtherVer WHERE itemsListId=a_itemsListVer.itemsListId ),' Waterproofing membrane ' )>0
,true,0 ) ) )

What I want to achieve . Normal operation ,10 End query in seconds
原网站

版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206161148004297.html