Details
Description
A COUNT() query containing EXISTS and subqueries returns wrong results.
Sometimes disabling the optimizer switch exists_to_in works as expected, I can't always reproduce this behaviour thou.
Dropping an index (see sample.txt) also seems to fix, but there it's still 1 row off: 468 vs 469)
Attachments
Activity
Field | Original Value | New Value |
---|---|---|
Comment |
[ {code:sql|title=Test case 1 (where switching exists_to_in off fixes the problem)}
DROP TABLE IF EXISTS t1, t2, t3; CREATE TABLE t1 (a INT NOT NULL); INSERT INTO t1 VALUES (1),(1),(1),(5),(5); CREATE TABLE t2 (b INT); INSERT INTO t2 VALUES (5),(1); CREATE TABLE t3 (c INT, KEY(c)); INSERT INTO t3 VALUES (5),(5); SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE b = t1.a) AND EXISTS (SELECT 1 FROM t3 WHERE c = t1.a); SET optimizer_switch='exists_to_in=off'; SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE b = t1.a) AND EXISTS (SELECT 1 FROM t3 WHERE c = t1.a); DROP TABLE t1, t2, t3; {code} {noformat:title=Result with the default switch (wrong)} +---+ | a | +---+ | 5 | | 5 | | 5 | | 5 | +---+ 4 rows in set (0.00 sec) {noformat} {noformat:title=Result with exists_to_in=OFF (correct)} +---+ | a | +---+ | 5 | | 5 | +---+ 2 rows in set (0.00 sec) {noformat} ] |
Fix Version/s | 10.1 [ 16100 ] | |
Fix Version/s | 10.2 [ 14601 ] | |
Affects Version/s | 10.0 [ 16000 ] | |
Affects Version/s | 10.1 [ 16100 ] | |
Affects Version/s | 10.2 [ 14601 ] | |
Assignee | Oleksandr Byelkin [ sanja ] | |
Summary | Wrong results in COUNT() query with EXISTS | Wrong results in COUNT() query with EXISTS and exists_to_in |
Status | Open [ 1 ] | Confirmed [ 10101 ] |
Sprint | 10.2.10 [ 183 ] |
Status | Confirmed [ 10101 ] | In Progress [ 3 ] |
Affects Version/s | 5.5 [ 15800 ] |
Fix Version/s | 5.5 [ 15800 ] | |
Fix Version/s | 10.0 [ 16000 ] |
Assignee | Oleksandr Byelkin [ sanja ] | Sergei Petrunia [ psergey ] |
Status | In Progress [ 3 ] | In Review [ 10002 ] |
Sprint | 10.2.10 [ 183 ] | 10.2.10, 5.5.58 [ 183, 197 ] |
Sprint | 10.2.10, 5.5.58 [ 183, 197 ] | 10.2.10, 5.5.58, 10.1.29 [ 183, 197, 202 ] |
Sprint | 10.2.10, 5.5.58, 10.1.29 [ 183, 197, 202 ] | 10.2.10, 5.5.58, 10.1.29, 10.1.30 [ 183, 197, 202, 215 ] |
Assignee | Sergei Petrunia [ psergey ] | Oleksandr Byelkin [ sanja ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Assignee | Oleksandr Byelkin [ sanja ] | Alice Sherepa [ alice ] |
Sprint | 10.2.10, 5.5.58, 10.1.29, 10.1.30 [ 183, 197, 202, 215 ] | 10.2.10, 5.5.58, 10.1.29, 10.1.30, 10.2.12 [ 183, 197, 202, 215, 216 ] |
Sprint | 10.2.10, 5.5.58, 10.1.29, 10.1.30, 10.2.12 [ 183, 197, 202, 215, 216 ] | 10.2.10, 5.5.58, 10.1.29, 10.1.30, 10.2.12, 5.5.59 [ 183, 197, 202, 215, 216, 221 ] |
Assignee | Alice Sherepa [ alice ] | Oleksandr Byelkin [ sanja ] |
Fix Version/s | 5.5.59 [ 22612 ] | |
Fix Version/s | 10.0.34 [ 22613 ] | |
Fix Version/s | 10.3.4 [ 22904 ] | |
Fix Version/s | 10.1.31 [ 22907 ] | |
Fix Version/s | 10.2.13 [ 22910 ] | |
Fix Version/s | 10.2 [ 14601 ] | |
Fix Version/s | 5.5 [ 15800 ] | |
Fix Version/s | 10.0 [ 16000 ] | |
Fix Version/s | 10.1 [ 16100 ] | |
Resolution | Fixed [ 1 ] | |
Status | Stalled [ 10000 ] | Closed [ 6 ] |
Workflow | MariaDB v3 [ 82827 ] | MariaDB v4 [ 152902 ] |
Zendesk Related Tickets | 145664 |
claudio.nanni, the 1-row difference between the conditional SELECT and unconditional one seems to be legitimate, at least in the attached test case.
There is one line in sceb205fa121 with dia34a99d3bc = 21, which is naturally counted by the unconditional SELECT. The WHERE clause in the conditional SELECT has two EXISTS:
For the first EXISTS, there is no row in ed8ec6a6b8d1 which would have values (21,4,34), so the row is excluded from the count.