mysql(不在)条件在超过一定数量的元素后不能正确返回

kb5ga3dv  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(297)
Select * From Table_Name Where MyColumnID NOT IN (1,2,3,4,5);

上面的sql语句工作得非常好,但是当我尝试增加元素时,特别是对于例如。

Select * From Table_Name Where MyColumnID NOT IN (1,2,3,4,5,...1000 and more);

它只返回几行,有时甚至根本不返回。任何少于1000的元素都会正确返回not in条件
然后,我尝试在以下条件下使用:

Select * From Table_Name Where MyColumnID IN (1,2,3,4,5,...9000 and more);

它工作得非常好,正如预期的那样。如果它对处于不利条件的人有效,为什么它对处于不利条件的人无效呢?
我真的很茫然,是不是我遗漏了什么变量?
我设置或检查的内容:
1) 允许的最大\u包数=1000000000;
2) id不包含空值
3) id名称='stockid'

q5lcpyga

q5lcpyga1#

看起来你可能被一个很老的bug绊倒了,你必须升级你的mysql版本。
看见
https://bugs.mysql.com/bug.php?id=15872
如果你读到报告的底部,你会发现这个bug在5.0.25中被修复了

[15 Aug 2006 17:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/10495

ChangeSet@1.2257, 2006-08-15 21:08:22+04:00, sergefp@mysql.com +3 -0
  BUG#21282: Incorrect query results for "t.key NOT IN (<big const list>) 
  In fix for BUG#15872, a condition of type "t.key NOT IN (c1, .... cN)"
  where N>1000, was incorrectly converted to
    (-inf < X < c_min) OR (c_max < X)
  Now this conversion is removed, we dont produce any range lists for such
  conditions.

[29 Aug 2006 13:23] Evgeny Potemkin
Fixed in 5.0.25

[4 Sep 2006 11:41] Evgeny Potemkin
Fixed in 5.1.12

相关问题