MySQL中WHERE后跟着N多个OR条件会怎样...
- GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。
- GreatSQL是MySQL的国产分支版本,使用上与MySQL一致。
- 作者:叶金荣
- 文章来源:社区原创
可能会执行非常慢,线上生产环境千万别写出这种SQL ...
背景交代
用 tpcc-mysql
工具生成 50个仓库 的测试数据,表 order_line
共有 37970973 条记录。
某工具在运行过程中,会产生下面的SQL进行查询,WHERE后跟了N多个条件:
mysql> select * from order_line where
(ol_w_id = '1' and ol_d_id = '1' and ol_o_id = '2221' and ol_number = '5')
or (ol_w_id = '1' and ol_d_id = '1' and ol_o_id = '2225' and ol_number = '1')
or (ol_w_id = '1' and ol_d_id = '1' and ol_o_id = '2155' and ol_number = '2')
...