diff options
| author | Monty <monty@mariadb.org> | 2022-09-25 18:44:48 +0300 |
|---|---|---|
| committer | Sergei Petrunia <sergey@mariadb.com> | 2023-02-02 23:55:08 +0300 |
| commit | 7afa819f727144e8a107e28444e07d54045ab38e (patch) | |
| tree | 80c795559127f609e6fc9806cc234dcc01cbcf4a /mysql-test/main/group_by.test | |
| parent | 009db2288ba8d22c5e8e5e047d8f8694f7097923 (diff) | |
| download | mariadb-git-7afa819f727144e8a107e28444e07d54045ab38e.tar.gz | |
Fix cost calculation for get_best_group_min_max()
If the final range restrictions (SEL_ARG tree) over GROUP BY
columns are single-point, we can compute the number of GROUP BY groups.
Example: in the query:
SELECT ... FROM tbl
WHERE keypart1 IN (1,2,3) and keypart2 IN ('foo','bar')
Other things:
- Fixed cost calculation to more correctly count the number of blocks
that may be read. The old code could use the total blocks in the file
even if a range was available.
Diffstat (limited to 'mysql-test/main/group_by.test')
| -rw-r--r-- | mysql-test/main/group_by.test | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/mysql-test/main/group_by.test b/mysql-test/main/group_by.test index 87f82fde5ce..3aa7f1cd0d3 100644 --- a/mysql-test/main/group_by.test +++ b/mysql-test/main/group_by.test @@ -718,7 +718,8 @@ drop table t1, t2; CREATE TABLE t1 (a tinyint(3), b varchar(255), PRIMARY KEY (a)); INSERT INTO t1 VALUES (1,'-----'), (6,'Allemagne'), (17,'Autriche'), - (25,'Belgique'), (54,'Danemark'), (62,'Espagne'), (68,'France'); + (25,'Belgique'), (54,'Danemark'), (62,'Espagne'), (68,'France'), + (100,"No land"), (101,"No land"); CREATE TABLE t2 (a tinyint(3), b tinyint(3), PRIMARY KEY (a), KEY b (b)); @@ -1168,7 +1169,9 @@ SELECT b from t2 GROUP BY b; # Show that we are using 'range' when there is more NULL rows in the table insert into t2 SELECT NULL, NULL from seq_1_to_10; +EXPLAIN SELECT b from t2 GROUP BY a; --echo # Expect: Using index for group-by +analyze table t2; EXPLAIN SELECT b from t2 GROUP BY a; DROP TABLE t1; @@ -2131,3 +2134,22 @@ drop table t20, t21, t22; --echo # --echo # End of 10.3 tests --echo # + +--echo # +--echo # Test new group_min_max optimization +--echo # + +create table t1 (a int, b int, c int, key(a,b,c)); +insert into t1 select mod(seq,23),mod(seq,13), mod(seq,5) from seq_1_to_10000; + +explain select a from t1 where a in (1,2,3) group by a; +explain select a from t1 where a in (1,2,3) or a = 22 group by a; +explain select a from t1 where a in (1,2,3) and a < 3 group by a; +explain select a,b from t1 where (a) in (1,2,3) and b in (5,6,7) group by a,b; +explain select a,b from t1 where (a,b) in ((1,1),(2,2),(3,3)) group by a,b; +explain select a,b,c from t1 where (a,b) in ((1,1),(2,2),(3,3)) and c=3 group by a,b,c; + +--echo # Will not use index for group-by +explain select a from t1 where a in (1,2,3) and b>1 group by a; +explain select a from t1 where a in (1,2,3) and c=1 group by a; +drop table t1; |
