[MDEV-3875] Wrong result (missing row) on a DISTINCT query with the same subquery in the SELECT list and GROUP BY Created: 2012-11-21 Updated: 2013-01-27 Resolved: 2013-01-27 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.0, 5.5.28, 5.3.10, 5.2.12, 5.1.62 |
| Fix Version/s: | 10.0.1, 5.5.29, 5.3.12 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Sergei Golubchik |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | upstream | ||
| Issue Links: |
|
||||
| Description |
|
The following test case
returns two rows only:
while the same query without the view returns 3 rows:
EXPLAIN with the default optimizer_switch:
Reproducible with the default optimizer_switch as well as with all OFF values, except for in_to_exists or materialization that have to be on to run the query. Also reproducible on all current versions of MariaDB, and on MySQL 5.1 and 5.5; but not reproducible on MySQL 5.6 revno 4458. |
| Comments |
| Comment by Oleksandr Byelkin [ 2012-11-29 ] |
|
The suspiciouse thing is DEPENDENT SUBQUERY #4 because here is only one subquery and it should be (and is) DEPENDENT SUBQUERY #3 |
| Comment by Oleksandr Byelkin [ 2012-11-30 ] |
|
The materialized temporary table of the view gets only two rows. |
| Comment by Oleksandr Byelkin [ 2013-01-23 ] |
|
2 subqueries could be explained by show create view: |
| Comment by Oleksandr Byelkin [ 2013-01-23 ] |
|
The problem is not connected to view, equivalent query also return wrong result: |
| Comment by Oleksandr Byelkin [ 2013-01-23 ] |
|
Fast workaround will be print names in ORDER BY/GROUP BY lists if they are present, but it will not fix the problem above. |
| Comment by Oleksandr Byelkin [ 2013-01-23 ] |
|
A bit better formatted query for new test suite: select distinct |
| Comment by Oleksandr Byelkin [ 2013-01-23 ] |
|
the last variant is still reproducible on MySQL 5.6 (when view is working OK) which makes me thing that in 5.6 put just workaround |
| Comment by Oleksandr Byelkin [ 2013-01-23 ] |
|
In MySQL they solved the problem with Item::print_for_order. It makes views a bit more optimized, but does not solve the problem in general. |
| Comment by Oleksandr Byelkin [ 2013-01-23 ] |
|
As Serg mentioned it could be http://bugs.mysql.com/bug.php?id=66896 |
| Comment by Oleksandr Byelkin [ 2013-01-23 ] |
|
remove_duplicates (sql_select.cc) do not take into account null_ptr of fields, it uses for comparison only fields data without NULL flag. |
| Comment by Oleksandr Byelkin [ 2013-01-24 ] |
|
Distinct index of temporary table to implement DISTINCT clause used only in case of absence of GROUP BY clause. |
| Comment by Oleksandr Byelkin [ 2013-01-24 ] |
|
create table t1(i int, g int); insert into t1 select distinct i from t1 group by g; drop table t1; |
| Comment by Sergei Golubchik [ 2013-01-27 ] |
|
pushed in 5.3 |