查询效率慢,求优化策略

create table g_same_item_to_item
(
id bigint auto_increment comment ‘主键’
primary key,
same_item_id bigint not null comment ‘同一事项id’,
item_id bigint null comment ‘实施事项id’,
constraint same_item_id_2
unique (same_item_id, item_id)
)。这个sql查询要5秒 select /* PARALLEL(10) */ * from g_same_item_to_item force index(SAME_ITEM_ID_3) where item_id in (20656579, 20658989, 20658031, 20714733, 20656211, 20717119, 20716651, 20715809, 20712755, 20711825, 20715075,
20716239, 20715107, 20659169, 20711995, 20718719, 20711353, 20714209, 20713975, 20659465, 20713261, 20659181,
20658659, 20657761, 20711209, 20657045, 20657931, 20714367, 20712883, 20657167, 20659323, 20657371, 20717495,
20657185, 20657487, 20656781, 20718181, 20659491, 20658737, 20657867, 20658161, 20657881, 20716543, 20658821,
20657929, 20658279, 20657723, 20658695, 20656581, 20656443, 20658627, 20715217, 20657995, 20656409, 20657549,
20713753, 20658081, 20659355, 20659539, 20659205, 20712313, 20659361, 20658595, 20657037, 20658167, 20659333,
20656199, 20657189, 20714241, 20659051, 20656471, 20658555, 20658377, 20659489, 20659053, 20657007, 20658121,
20718397, 20714017, 20718833, 20657283, 20658145, 20711999, 20659317, 20656509, 20658363, 20714021, 20658243,
20656549, 20658711, 20713375, 20657003, 20658353, 20656675, 20657785, 20656055, 20656753, 20656521, 20716391,
20656935, 20656627, 20656033, 20714089, 20712377, 20658343, 20655977, 20658509, 20657805, 20715999, 20658209,
20656831, 20658089, 20718375, 20656171, 20658809, 20658843, 20659243, 20658571, 20657389, 20656179, 20656315,
20658155, 20718123, 20711859, 20713151, 20714559, 20657849, 20656329, 20658229, 20717343, 20715029, 20657273,
20656395, 20657843, 20656619, 20659395, 20659425, 20658961, 20713977, 20657835, 20716635, 20658663, 20658311,
20715585, 20658179, 20656019, 20718241, 20711547, 20717203, 20656235, 20712847, 20656807, 20710933, 20717959,
20657709, 20711469, 20659235, 20657607, 20712907, 20657239, 20711505, 20657251, 20718585, 20715627, 20657977,
20658385, 20713415, 20712491, 20658319, 20712817, 20712621, 20714589, 20717475, 20715653, 20715793, 20658163,
20658581, 20656513, 20715297, 20656515, 20717937, 20657411, 20656817, 20718069, 20711601, 20656921, 20715343,
20656291, 20656973, 20711229, 20713447, 20655987, 11175564, 20656839, 20657207, 20658393, 20656243, 20657255,
20656229, 20658845, 20657841, 20659457, 20713761, 20718661, 20657943, 20657559, 20658593, 20656233, 20659469,
20717327, 20713225, 20658087, 20656071, 20717605, 20657351, 20659525, 20713109, 20658109, 20711337, 20657489,
20716847, 20657361, 20717403, 20659325, 20712645, 20712173, 20657219, 20716657, 20717933, 20658093, 20712397,
20713147, 20658037, 20718851, 20718803, 20713093, 20715369, 22429832, 20712215, 20711993, 20713087, 20656397,
22440030, 20656255, 20712543, 22399324, 20714245, 20658413, 20656037, 20657745, 20712169, 20656939, 20656387); 有没有优化手段

看一下执行计划

执行计划呢


刚刚看响应又变700毫秒了 响应有波动 并且查询200百多id 要700毫秒 也是有点慢了

麻烦看下怎么进行优化 一百多id 能不能控制在一百毫秒内

完整的表结构发下,执行计划发全了,你强制使用那个SAME_ITEM_ID_3 这个索引的意义是什么

– 开启show trace
SET ob_enable_show_trace=ON;
– 执行sql
select /* PARALLEL(10) */ * from g_same_item_to_item force index(SAME_ITEM_ID_3) where item_id in()
– 查看各阶段耗时
SHOW TRACE;