[MDEV-9310] IFNULL() does not work well WITH ROLLUP Created: 2015-12-21 Updated: 2015-12-26 Resolved: 2015-12-26 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | OTHER |
| Affects Version/s: | 10.0, 10.1 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Federico Razzoli | Assignee: | Unassigned |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Look at this test case:
The first result is what one expects, the second result is not. I'm not sure if it is a bug or an expected behavior, but it makes the query useless. Since WITH ROLLUP adds rows with NULL, the IFNULL() function in the SELECT clause should be applied after WITH ROLLUP. |
| Comments |
| Comment by Elena Stepanova [ 2015-12-26 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I don't see any flaw in the logic above, it seems to work strictly according to specification. A function cannot possibly be applied after ROLLUP, but that's not the point and not the reason of the result you are getting. I think it's possible that your query is not quite what you meant it to be. Let's forget ROLLUP for a moment.
and you are running the query
Is it the result you want to get?
Now, that makes much more sense. And back to ROLLUP, it will now work just as expected:
It is still possible however, that you wanted to group by the initial a value. But doing it the way your query does is useless, because you won't know which value the count belongs to – NULL or 1. If you want to see the initial a value, you need to add it to your select list:
And then, ROLLUP will again make sense:
If neither of these variants works for you and you wanted to achieve something different, please elaborate on that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Federico Razzoli [ 2015-12-26 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sorr for the bad example (also using numbers instead of meaningful values didn't help). Yes, your last 2 queries are what I meant. Selecting both a and IFNULL(a, 1) solves the problem. |