在索引字段上选择时避免使用IN(...),这会破坏SELECT查询的性能.
我在这里找到了这个:https://wikis.oracle.com/pages/viewpage.action?pageId = 27263381
你能解释一下吗?为什么这会扼杀性能?我应该使用什么而不是IN.或许"或"声明?
dog*_*ane -1
我相信 IN 的处理方式与一组 OR 相同,因此使用 OR 没有帮助。
另一种方法是创建一个临时表来保存 IN 子句的值,然后在 SELECT 中与该临时表连接。
例如:
CREATE TEMPORARY TABLE temp_table (v VARCHAR)
INSERT INTO temp_table VALUES ('foo')
INSERT INTO temp_table VALUES ('bar')
SELECT * FROM temp_table tmp, orig_table orig
WHERE temp_table.v = orig.value
DROP TEMPORARY TABLE temp_table
Run Code Online (Sandbox Code Playgroud)