mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Adjust costs for doing index scan in cost_group_min_max()
The idea is that when doing a tree dive (once per group), we need to compare key values, which is fast. For each new group, we have to compare the full where clause for the row. Compared to original code, the cost of group_min_max() has slightly increased which affects some test with only a few rows. main.group_min_max and main.distinct have been modified to show the effect of the change. The patch also adjust the number of groups in case of quick selects: - For simple WHERE clauses, ensure that we have at least as many groups as we have conditions on the used group-by key parts. The assumption is that each condition will create at least one group. - Ensure that there are no more groups than rows found by quick_select Test changes: - For some small tables there has been a change of Using index for group-by -> Using index for group-by (scanning) Range -> Index and Using index for group-by -> Using index
This commit is contained in:
@ -4,13 +4,16 @@ drop table if exists t1, t2;
|
||||
#
|
||||
CREATE TABLE t1 (a INT,b INT,KEY a (a,b));
|
||||
INSERT INTO `t1` VALUES (0,580092),(3000,894076),(4000,805483),(4000,913540),(6000,611137),(8000,171602),(9000,599495),(9000,746305),(10000,272829),(10000,847519),(12000,258869),(12000,929028),(13000,288970),(15000,20971),(15000,105839),(16000,788272),(17000,76914),(18000,827274),(19000,802258),(20000,123677),(20000,587729),(22000,701449),(25000,31565),(25000,230782),(25000,442887),(25000,733139),(25000,851020);
|
||||
SELECT COUNT(*) from t1 where a IN (10000, 1000000, 3000);
|
||||
COUNT(*)
|
||||
3
|
||||
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range a a 5 NULL 1 Using where; Using index for group-by
|
||||
1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
|
||||
alter table t1 partition by hash(a) partitions 1;
|
||||
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range a a 5 NULL 1 Using where; Using index for group-by
|
||||
1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
|
||||
alter table t1 remove partitioning;
|
||||
insert into t1 (a,b) select seq,seq from seq_4001_to_4100;
|
||||
insert into t1 (a,b) select seq,seq from seq_10001_to_10100;
|
||||
|
Reference in New Issue
Block a user