Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
12.1.2
-
None
-
12.1.2-MariaDB-ubu2404
Description
MariaDB's `index_subquery` optimization returns incorrect results when evaluating IN subqueries
CREATE TABLE t18 ( |
c1 BIT, |
c2 BIT NOT NULL, |
UNIQUE (c2, c1) |
);
|
|
|
INSERT INTO t18 (c1, c2) VALUES |
(b'0', b'1'), |
(b'1', b'1'), |
(b'0', b'0'); |
|
|
|
|
mysql> SELECT INET_NTOA('2016-12-24 09:00:00') IN (SELECT c2 FROM t18) AS result; |
+--------+ |
| result |
|
+--------+ |
| 0 |
|
+--------+ |
|
|
-- Test 2: Without index (CORRECT - returns TRUE)
|
mysql> SELECT INET_NTOA('2016-12-24 09:00:00') IN (SELECT c2 FROM t18 USE INDEX ()) AS result; |
+--------+ |
| result |
|
+--------+ |
| 1 |
|
+--------+ |
|
|
-- With index (incorrect result)
|
mysql> EXPLAIN EXTENDED SELECT INET_NTOA('2016-12-24 09:00:00') IN (SELECT c2 FROM t18); |
+----+-------------+-------+---------------+------+---------+------+------+--------------------------+ |
| id | select_type | table | type | key | key_len | ref | rows | Extra | |
+----+-------------+-------+---------------+------+---------+------+------+--------------------------+ |
| 1 | PRIMARY | NULL | NULL | NULL | NULL | NULL | NULL | No tables used | |
| 2 | SUBQUERY | t18 | index_subquery| c2 | 1 | const | 2 | Using index; Using where | |
+----+-------------+-------+---------------+------+---------+------+------+--------------------------+ |
|
|
-- Without index (correct result)
|
mysql> EXPLAIN EXTENDED SELECT INET_NTOA('2016-12-24 09:00:00') IN (SELECT c2 FROM t18 USE INDEX ()); |
+----+-------------+-------+------+---------+------+------+-------------+ |
| id | select_type | table | type | key | key_len | ref | rows | Extra | |
+----+-------------+-------+------+---------+------+------+-------------+ |
| 1 | PRIMARY | NULL | NULL | NULL | NULL | NULL | NULL | No tables | |
| 2 | SUBQUERY | t18 | ALL | NULL | NULL | NULL | 3 | Using where | |
+----+-------------+-------+------+---------+------+------+-------------+ |