[MDEV-17796] WHERE filter is ignored by DISTINCT IFNULL(GROUP_CONCAT(X), Y) with GROUP BY + ORDER BY Created: 2018-11-22 Updated: 2019-04-25 Resolved: 2019-04-24 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.2.5, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.2.24, 10.3.15, 10.4.5 |
| Type: | Bug | Priority: | Major |
| Reporter: | Berengar Lehr | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
docker container |
||
| Attachments: |
|
| Description |
|
Run the attached sql and you will find a query that returns rows that where explicitly filtered.
The issue relates to versions, including 10.2.[5-18] 10.3 10.4 but not 10.0.[26-38], 10.1 and 5.5 (tested with the latest docker releases). It does not appear in all mysql versions (5.5, 5.6, 5.7) but mysql_5.7 returns the following error:
(line 28 is the beginning of the SELECT stmt. |
| Comments |
| Comment by Alice Sherepa [ 2018-11-26 ] | ||||||||||||||||||||||||||||||||||||||
|
Thanks a lot for the report and the test case!
| ||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2019-04-15 ] | ||||||||||||||||||||||||||||||||||||||
|
The following query works fine:
The query
is one with non-deterministic semantic: in ORDER BY v1 does not functionally depend on id. | ||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2019-04-15 ] | ||||||||||||||||||||||||||||||||||||||
|
The explanation why it's not a bug see in Igor's comment | ||||||||||||||||||||||||||||||||||||||
| Comment by Berengar Lehr [ 2019-04-23 ] | ||||||||||||||||||||||||||||||||||||||
|
I'm sorry, I don't get it. Either it's for some reason I absolutely not yet don't understand an invalid query (as the error in mysql, not in mariadb, indicates). | ||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2019-04-23 ] | ||||||||||||||||||||||||||||||||||||||
|
igor, I don't quite agree. You are right that the semantic is non-deterministic. And there is no guarantee what v1 value out of all rows for a particular group of id will be used for ORDER BY. But it still does not mean that values filtered out by WHERE could appear in the result set. WHERE is applied first, then GROUP BY and ORDER BY. And in this query WHERE removes rows from the result set quite deterministically, as far as I can see. | ||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2019-04-24 ] | ||||||||||||||||||||||||||||||||||||||
|
The following query that respects functional dependencies from grouping columns
still returns a wrong result set:
| ||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2019-04-24 ] | ||||||||||||||||||||||||||||||||||||||
|
A fix for this bug was pushed into 10.2 |