[MDEV-19676] HAVING with constant expression on empty table and without GROUP BY loses constant result. Created: 2019-06-03 Updated: 2023-11-28 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5, 10.1, 10.3.15, 10.4.5, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10 |
| Fix Version/s: | 10.4, 10.5, 10.6 |
| Type: | Bug | Priority: | Minor |
| Reporter: | - | Assignee: | Michael Widenius |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | 11.0-sel, optimizer | ||
| Environment: |
MariaDB Docker (Bionic) on Ubuntu Linux 19.4 |
||
| Description |
|
Given the following, minimal sample:
Summary: No result is returned if a constant without aggregate function is selected and a HAVING clause (with a constant expression like 'TRUE'), without an explicit GROUP BY clause is used on an empty table. I expect that a single 1 is returned. This is also the behaviour of Postgres and described here (https://stackoverflow.com/a/53238082). The HAVING groups the empty result into a single, but existing group. HAVING doesn't filter this single row, so a single row and result should be returned. When a explicit GROUP BY is used, or COUNT ( * ) is used additionally, or there exists an entry in the table, a 1 is returned, which is correct. |
| Comments |
| Comment by Elena Stepanova [ 2019-06-03 ] | |||||||||||||||||||||
|
Indeed, PostgreSQL returns a result:
All versions of MariaDB and MySQL return an empty set. | |||||||||||||||||||||
| Comment by Igor Babaev [ 2019-06-04 ] | |||||||||||||||||||||
|
What about
? | |||||||||||||||||||||
| Comment by - [ 2019-06-04 ] | |||||||||||||||||||||
|
@Igor In Postgres, this is an error:
In MariaDB 10.4.5, this also returns an empty result set, like the single 1. Interesting: If I insert some values before, I get these values back:
It seems like HAVING without a GROUP BY is completely 'ignored'. As far as I understand SQL, there should be a implicit grouping when a having occurs. |