[MDEV-26168] Broken Sort operation with Union and Count Created: 2021-07-16  Updated: 2021-07-16

Status: Open
Project: MariaDB Server
Component/s: Data Manipulation - Subquery
Affects Version/s: 10.5.10
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Jared Karlow Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: Columnstore
Environment:

Ubuntu 20.04.2 LTS focal



 Description   

Simple unions break sorting.

Here's a relatively simple query format that demonstrates this on a columnstore table:

SELECT
label,
count
FROM (
SELECT
label,
COUNT(my_table.id) as count
FROM my_table
GROUP BY label
UNION ALL
SELECT "NONE" as label, 0 as count
UNION ALL
SELECT "NONE" as label, -1 as count

) AS A ORDER BY count

This will yield a sort order where -1 is considered the largest value.

This is likely a signed/unsigned integer issue.

Of note:

  • Does not break on a Sum, have not tested other grouping operations
  • Have not tested other sort engines
  • Did not break in our previous version of columnstore some ~4 years ago

Active Workaround:
replace literal for -1 with cast(-1 AS float) acts as workaround


Generated at Thu Feb 08 09:43:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.