1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-10-31 18:30:33 +03:00
Files
mariadb-columnstore-engine/mysql-test/columnstore/basic/r/mcs37_select_distinct.result
Alexey Antipovsky cfa9a7ff2c feat(optimizer): MCOL-5250 rewrite queries with DISTINCT (#3666)
* feat(optimizer): MCOL-5250 rewrite queries with DISTINCT

... as aggregated queries.
So query
```
SELECT DISTINCT <cols list>
FROM <from list>
WHERE <where clause>
HAVING <having clause>
ORDER BY <orderby list>
LIMIT <limit>
```
will become
```
SELECT *
FROM
  (
    SELECT <cols list>
    FROM <from list>
    WHERE <where clause>
    HAVING <having clause>
  ) a
GROUP BY 1,2,3,...,N
ORDER BY <orderby list>
LIMIT limit
```

* move ORDER BY to the outer query

* fix test

* reuse cloneWORecursiveSelects() in clone()

* fix subselect columns processing
2025-09-22 16:16:37 +04:00

57 lines
887 B
Plaintext

DROP DATABASE IF EXISTS mcs37_db;
CREATE DATABASE mcs37_db;
USE mcs37_db;
CREATE TABLE t1(col1 INT, col2 CHAR(5))ENGINE=Columnstore;
INSERT INTO t1 VALUES(NULL, NULL),(1,'a'),(1,'b'),(1,'c'),(2,'dd'),(3,'eee');
SELECT COUNT(DISTINCT col1) FROM t1;
COUNT(DISTINCT col1)
3
SELECT COUNT(DISTINCT col2) FROM t1;
COUNT(DISTINCT col2)
5
SELECT DISTINCT col1 FROM t1;
col1
1
2
3
NULL
SELECT DISTINCT col1 FROM t1 ORDER BY col1 DESC;
col1
3
2
1
NULL
SELECT DISTINCT col2 FROM t1;
col2
NULL
a
b
c
dd
eee
CREATE TABLE t2(col1 INT)ENGINE=Columnstore;
INSERT INTO t2 SELECT DISTINCT col1 FROM t1;
SELECT * FROM t2;
col1
1
2
3
NULL
CREATE TABLE t3 (name varchar(255));
INSERT INTO t3 VALUES ('aa'),('ab'),('ac'),('ad'),('ae');
SELECT DISTINCT * FROM t3;
name
aa
ab
ac
ad
ae
SELECT DISTINCT name FROM t3 ORDER BY name LIMIT 2;
name
aa
ab
SELECT DISTINCT 1 FROM t3 LIMIT 3;
1
1
DROP DATABASE mcs37_db;