[MCOL-5222] ORDER BY on UNIONs in outer selects does not work Created: 2022-09-16  Updated: 2023-12-15

Status: Stalled
Project: MariaDB ColumnStore
Component/s: None
Affects Version/s: 22.08.2
Fix Version/s: 23.10

Type: Bug Priority: Major
Reporter: Gagan Goel (Inactive) Assignee: Leonid Fedorov
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Blocks
is blocked by MDEV-30828 ORDER BY clause using an integer (pos... Closed
Relates
relates to MCOL-4901 Allow pushdown of queries involving U... Closed

 Description   

After MDEV-25080 and MCOL-4901, UNIONs in outer select statements are pushed down to ColumnStore.

However, adding an ORDER BY clause to a UNION in outer select is not sorting the final result set as expected. Here is the expected output from InnoDB:

MariaDB [test]> show create table i1;
+-------+-------------------------------------------------------------------------------------------+
| Table | Create Table                                                                              |
+-------+-------------------------------------------------------------------------------------------+
| i1    | CREATE TABLE `i1` (
  `a` varchar(30) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)
 
MariaDB [test]> show create table i2;
+-------+-------------------------------------------------------------------------------------------+
| Table | Create Table                                                                              |
+-------+-------------------------------------------------------------------------------------------+
| i2    | CREATE TABLE `i2` (
  `a` varchar(30) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)
 
MariaDB [test]> select * from i1;
+------+
| a    |
+------+
| abc  |
| bcd  |
| cde  |
+------+
3 rows in set (0.001 sec)
 
MariaDB [test]> select * from i2;
+------+
| a    |
+------+
| bcd  |
| cde  |
| def  |
| efg  |
+------+
4 rows in set (0.001 sec)
 
MariaDB [test]> select a from i1 union all select a from i2 order by a;
+------+
| a    |
+------+
| abc  |
| bcd  |
| bcd  |
| cde  |
| cde  |
| def  |
| efg  |
+------+
7 rows in set (0.002 sec)

Below is what ColumnStore is returning:

MariaDB [test]> show create table t1;
+-------+------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                   |
+-------+------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` varchar(30) DEFAULT NULL
) ENGINE=Columnstore DEFAULT CHARSET=latin1 |
+-------+------------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)
 
MariaDB [test]> show create table t2;
+-------+------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                   |
+-------+------------------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `a` varchar(30) DEFAULT NULL
) ENGINE=Columnstore DEFAULT CHARSET=latin1 |
+-------+------------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)
 
MariaDB [test]> select * from t1;
+------+
| a    |
+------+
| abc  |
| bcd  |
| cde  |
+------+
3 rows in set (0.019 sec)
 
MariaDB [test]> select * from t2;
+------+
| a    |
+------+
| bcd  |
| cde  |
| def  |
| efg  |
+------+
4 rows in set (0.011 sec)
 
MariaDB [test]> select a from t1 union all select a from t2 order by a;
+------+
| a    |
+------+
| abc  |
| bcd  |
| cde  |
| bcd  |
| cde  |
| def  |
| efg  |
+------+
7 rows in set (0.028 sec)



 Comments   
Comment by Gagan Goel (Inactive) [ 2022-09-16 ]

Also update the following MTR tests once this MCOL is fixed:

mysql-test/columnstore/basic/t/mdev-25080.test
mysql-test/columnstore/basic/t/union.test
mysql-test/columnstore/basic/t/mcol641-union.test

Comment by JiraAutomate [ 2023-12-15 ]

Automated message:
----------------------------
Since this issue has not been updated since 6 weeks, it's time to move it back to Stalled.

Generated at Thu Feb 08 02:56:16 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.