[MDEV-10253] select field group by field with rollup Created: 2016-06-19 Updated: 2022-01-25 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | OTHER |
| Affects Version/s: | 10.1.14, 5.5, 10.0, 10.1, 10.2 |
| Fix Version/s: | 10.2 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Philip orleans | Assignee: | Oleksandr Byelkin |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | upstream | ||
| Environment: |
Linux |
||
| Description |
|
I tested this issue with MsSQL server, on identical data and table. In MsSQL it works correctly. Suppose you have a table with field1, field2, etc.
in MariaDB the result is correct and looks like this, where x and y are the contents of columns field1 and field2
That is: the null on the lower left indicates that this is the grouping field. However, suppose that this column is a string, and then we are grouping on a part of the column. Here is a concrete example.
By contrast, in MsSQL, this identical query is correct:
|
| Comments |
| Comment by Elena Stepanova [ 2016-06-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The result is reproducible on all versions of MySQL and MariaDB available to me. Here is the MySQL manual page about ROLLUP. Importantly, it says:
Now, if we look at the query in question and its result set,
the column in the result set is Name, because it is called so in the SELECT list. However, GROUP BY refers to SUBSTRING(field1,1,instr(field1, '-')-1), which is certainly not a lexical match to Name. If we modify the query like to use Name in GROUP BY, we get the expected result:
So, if a column nickname is used, it needs to be used consistently. Further, if we remove the column nickname from the SELECT list in the initial query, we still don't get the result we expect:
I assume it's because with all those non-alphanumeric symbols in SUBSTRING(field1,1,instr(field1, '-')-1), the match just does not work.*
* maybe there is something to fix in there bar, could you please take a look and see whether, from your point of view, there is anything to fix here (or to convert to a feature request)? If not, please feel free to close. If you are unsure, please reassign to whomever you think it should belong to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Philip orleans [ 2016-06-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
the alternative does not really work If this worked, I would get "Total" on the lower left, but I do not. No matter how you do it, in MariaDB there is no way to get to the right result. it does not work either, because there is never a null in the lower left. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-06-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, it's hard to keep up, because your requirements change on the fly. In the initial description you said
So, with the consistent use of the column alias it does work, the lower left NULL is present. If you want to use this NULL in the query, it's a totally different story. Once again, I recommend reading documentation, it really helps. From the same page:
Regarding
This is simply impossible, paid enterprise databases themselves don't offer results identical to each other. I'm pretty sure if you try Oracle, you'll get something different from MSSQL. Best we can try to do is to conform to the standard. If you find that the described behavior is different from the standard, it might be a valid feature request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Philip orleans [ 2016-06-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
You cannot show the word NULL to a final user in a report. The NULL is only useful if it will be replaced by a meaningful word. I wrote a system whith hundreds of reports, and went straight from Select ..group by with rollup to the customer, only because that NULL can be detected in MsSQL. In MsSQL, they have a function called grouping(fieldname) as boolean, that tells you when your are in the intersection of a group, and then you may show what that subtotal means. I think that we need to allow the coder a similar functionality. It is not me, it is something that the industry finds clearly lacking in comparison with MsSQL. We need to be better than MsSQL, not worse. As you know, MsSQL is being written for Linux. If we act with your frame of mind, this database will disappear from the industry without trace. As Donal Trump says, "believe me, I know" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Philip orleans [ 2021-01-07 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I wonder if we are ever going to do this. |