1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-36389 Incorrect query results for an indexed text column

Fixes a scenario where an IN subquery returned the wrong result
because the pushed WHERE clause was not retained for downstream
result filtering.  For example:
  CREATE TABLE t1 (c1 TEXT, UNIQUE (c1(1)));
  INSERT INTO t1 (c1) VALUES ('a');
  SELECT 'abc' IN (SELECT c1 FROM t1);
Internally, he 'abc' IN subquery condition becomes the constant
condition:
  'abc' = t1.c1 or t1.c1 is null
Prior to this patch, this condition was incorrectly removed when
converting the subquery engine to an index lookup-based engine.
Now eligible conditions are preserved during such engine rewrites.
This commit is contained in:
Sergei Petrunia
2025-07-23 15:40:53 +03:00
committed by Dave Gosselin
parent 3109d994eb
commit a52362b90c
21 changed files with 201 additions and 119 deletions

View File

@@ -1414,7 +1414,7 @@ WHERE t1.f1 IN (SELECT f1 FROM t1) AND t1.f1 = t2.f1 OR t1.f1 = 9;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where
1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 Using index
2 SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 Using index
SELECT STRAIGHT_JOIN * FROM t1 JOIN t2 ON t2.f2 = t1.f1
WHERE t1.f1 IN (SELECT f1 FROM t1) AND t1.f1 = t2.f1 OR t1.f1 = 9;
f1 f2 f1 f2