Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 13.1, 12.3.3, 13.0.2, 13.1.1
-
Ubuntu 24.04 x86_64
-
Unexpected results
-
Description
SELECT DISTINCT loses rows when the plan is "Using index for group-by" and the WHERE clause has the form A AND (A OR B). The same query without DISTINCT, and DISTINCT with only A, both return the two expected rows. A AND (A OR B) is equivalent to A.
The wrong output differs between runs of the same script on a new table: the query returns either an empty set or only the row (1,0). It never returned both rows. On 13.0.2 and 13.1.1 both outputs were common (13.0.2: empty in 16 of 40 runs, one row in 24; 13.1.1: empty in 9 of 20, one row in 11); on 12.3.3 the single row was the usual output and the empty set was rare. Repeating the query on the same table gives the same output.
The table is InnoDB with an ascending index; no setting was changed.
How to reproduce
CREATE TABLE t(a INT UNIQUE, b INT NOT NULL, KEY(b, a)); |
INSERT INTO t VALUES (0, 0), (1, 0); |
|
|
SELECT a, b FROM t WHERE a IN (0,1) AND (a IN (0,1) OR b = 5); |
-- (0,0), (1,0) correct
|
|
|
SELECT DISTINCT a, b FROM t WHERE a IN (0,1); |
-- (0,0), (1,0) correct
|
|
|
SELECT DISTINCT a, b FROM t WHERE a IN (0,1) AND (a IN (0,1) OR b = 5); |
-- expected: (0,0), (1,0)
|
-- actual: Empty set, or only (1,0), depending on the run
|
|
|
EXPLAIN SELECT DISTINCT a, b FROM t WHERE a IN (0,1) AND (a IN (0,1) OR b = 5); |
-- type=range key=b Extra: Using where; Using index for group-by; Using temporary |
Attachments
Issue Links
- relates to
-
MDEV-30605 Wrong result while using index for group-by
-
- Closed
-