Bug #121696 Query with IN and != ALL subqueries returns inconsistent results under different execution plans

Submitted: 9 Nov 2:26 Modified: 12 Nov 7:08
Reporter: Hao Wang Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:9.7.2 OS:Any
Assigned to: CPU Architecture:Any

[9 Nov 2:26] Hao Wang
Description:
The same query returns 1 row under the default plan but an empty set under another execution plan. The base data is identical in both cases. The only difference lies in the subquery execution strategy, but the result set differs. 

How to repeat:
mysql> CREATE TABLE t1 (  c2 float,  c3 bit(1));
Query OK, 0 rows affected (0.286 sec)

mysql> INSERT INTO t1 (c2,c3) VALUES (-1.11,b'1');
Query OK, 1 row affected (0.047 sec)

mysql> SELECT * FROM t1, t1 AS t2 WHERE ( (t2.c2 IN (SELECT c3 FROM t1)) != ALL (SELECT c2 FROM t1) );
+-------+------------+-------+------------+
| c2    | c3         | c2    | c3         |
+-------+------------+-------+------------+
| -1.11 | 0x01       | -1.11 | 0x01       |
+-------+------------+-------+------------+
1 row in set (0.015 sec)

-- Run the same query but with hint,the WHERE condition evaluates to true, so expected 1 row, but actually returned 0 rows
mysql> SELECT * FROM t1, t1 AS t2 WHERE ( (t2.c2 IN (SELECT /*+ SUBQUERY(MATERIALIZATION)*/ c3 FROM t1)) != ALL (SELECT c2 FROM t1) );
Empty set (0.010 sec)

mysql> SELECT * FROM t1, t1 AS t2 WHERE true;
+-------+------------+-------+------------+
| c2    | c3         | c2    | c3         |
+-------+------------+-------+------------+
| -1.11 | 0x01       | -1.11 | 0x01       |
+-------+------------+-------+------------+
1 row in set (0.007 sec)
[12 Nov 7:08] Chaithra Marsur Gopala Reddy
Hi Hao Wang,

Thank you for the test case. Verified as described. But we think this is the same issue as that of the problem reported in Bug#121607. So we are closing this as a duplicate.

Thanks,
Chaithra

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.