Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 11.8.9
-
Linux x86_64, MariaDB 11.8.9 binary distribution
-
Unexpected results
Description
On MariaDB 11.8.9, enabling big_tables causes COUNT(DISTINCT t.a) to return 2 for a self-join filtered by t.a = 1. All qualifying rows have t.a = 1, so the distinct count should be 1.
Replacing the literal with an equivalent scalar COUNT() subquery returns the correct result. Disabling big_tables also restores the correct result.
The discrepancy was verified using the native mariadb command-line client in a fresh instance.
Reproducer:
Run the following statements in an empty database, using the same connection:
CREATE TABLE t (
|
a INT PRIMARY KEY
|
) ENGINE=InnoDB;
|
|
|
INSERT INTO t VALUES (1), (2);
|
|
|
SET SESSION big_tables = 1;
|
|
|
SELECT COUNT(DISTINCT t.a) AS result
|
FROM t, t AS t2
|
WHERE t.a = 1;
|
|
|
SELECT COUNT(DISTINCT t.a) AS result
|
FROM t, t AS t2
|
WHERE t.a = CAST(
|
(SELECT COUNT(*) FROM (SELECT 1) AS s)
|
AS SIGNED
|
);
|
|
|
SET SESSION big_tables = 0;
|
|
|
SELECT COUNT(DISTINCT t.a) AS result
|
FROM t, t AS t2
|
WHERE t.a = 1;
|
Actual result on 11.8.9-MariaDB:
Query 1, with big_tables=1 and a literal predicate:
result
|
2
|
Query 2, with big_tables=1 and an equivalent scalar-subquery predicate:
result
|
1
|
Query 3, after setting big_tables=0:
result
|
1
|
Expected result:
All three queries should return:
result
|
1
|
The self-join produces two qualifying rows, but t.a is 1 in both rows. COUNT(DISTINCT t.a) must therefore return 1.
The scalar subquery also returns exactly 1, so replacing the literal equality bound must not change the aggregate result.
Attachments
Issue Links
- relates to
-
MDEV-36975 COUNT(DISTINCT column) returns bad result with too low tmp_table_size
-
- Confirmed
-