MySQL(NOT IN)条件在超过一定数量的元素后不正确 return

MySQL (NOT IN) Condition does not return correctly after exceeding certain number of elements

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

上面的 sql 语句工作得很好,但是当我尝试增加元素时 特别地 传递 1000(对于我的情况)例如

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

它只有 returns 几行,有时甚至根本没有。对于 NOT IN 条件

正确小于 1000 returns 的任意数量的元素

然后,我尝试使用 IN 条件如下:

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

它工作得很好,符合预期。如果它适用于 IN 条件,为什么它不适用于 NOT IN 条件?

我真的很茫然,难道我遗漏了什么变量?

我设置或检查的内容:

1) Max_allowed_packet = 1000000000;

2) ID 不包含空值

3) ID 名称 = 'StockID'

看来您可能被一个非常老的错误绊倒了,您将不得不升级 MySQL 的版本。

https://bugs.mysql.com/bug.php?id=15872

如果您阅读到报告底部,您会发现此错误已在 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