我需要一个非常慢的运行查询的帮助(在8 GB RAM上面1/2小时,查询仍然没有返回)
诀窍是我需要匹配2个值,内部查询需要一个连接:
t_outer has 98,229 rows
t1_inner has 256,394 rows
t2_inner has 261,067 rows
查询:
select product
from t_outer
where not exists (select 1
from t1_inner
join t2_inner on t2_inner.pk = t1_inner.pk
where
t_outer.code1 != t1_inner.code1
and t_outer.code2 != t2_inner.code2);
我尝试在所有t1_inner.code1
和t1_inner.code2
上添加非空约束
并且t_outer.code2
和t2_inner.code2.
没有帮助。所有连接字段以及代码字段(innodb, btree)
这里是解释计划,只有三行,但为了便于阅读而分解:
| id | select_type | table | type
| 1 | PRIMARY | imp | index
| 2 | DEPENDENT SUBQUERY | pr | range
| 2 | DEPENDENT SUBQUERY | p | ref
| possible_keys
| PRIMARY,tom2,tom3
| PIDX_1055,tom1
| CODEVERSIONIDX_1,PK_7619F05CE21,PRODUCT_CODE_1
| key | key_len | ref
| tom3 | 42 | NULL
| PIDX_1055 | 9 | NULL
| PK_7619F05CE21 | 8 | bds.pr.P_PRODUCT
| rows | Extra |
| 97470 | Using where; Using index |
| 129573 | Using index condition; Using where |
| 1 | Using where |
谢谢!