【发布时间】:2018-11-21 16:45:51
【问题描述】:
我在为查询的 IN 子句使用子查询时遇到了一些问题。 对 IN .. 值进行硬编码可以让查询快速执行,但使用子查询会减慢一切。有没有办法加快这个查询?
SELECT col1, col2, col3 FROM table1
WHERE ...
and col1 in (SELECT col1 FROM table2)
...
*IN 子句的值将是一个字符串列表
SELECT col1, col2, col3 FROM table1
WHERE ...
and col1 in ('str1', 'str2', 'str3', ...)
...
以上工作正常。
编辑: 我想我把问题简单化了。我尝试执行的查询如下所示:
SELECT col1, col2, col3, ...
FROM table1 t1, table2 t2
WHERE t1.col1 IN (SELECT col FROM table3)
and t1.col2 < 50
and t2.col3 = t1.col3
...
【问题讨论】: