mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +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:
@ -538,10 +538,10 @@ PRIMARY KEY (a,b));
|
||||
INSERT INTO t2 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
|
||||
EXPLAIN SELECT DISTINCT a FROM t2;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 range NULL PRIMARY 4 NULL 3 Using index for group-by
|
||||
1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index
|
||||
EXPLAIN SELECT DISTINCT a,a FROM t2;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 range NULL PRIMARY 4 NULL 3 Using index for group-by
|
||||
1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index
|
||||
EXPLAIN SELECT DISTINCT b,a FROM t2;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index
|
||||
@ -754,9 +754,6 @@ INSERT INTO t1(a, b, c) VALUES (1, 1, 1),
|
||||
(1, 2, 1),
|
||||
(1, 2, 2),
|
||||
(1, 2, 3);
|
||||
EXPLAIN SELECT DISTINCT a, b, d, c FROM t1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range NULL PRIMARY 16 NULL 6 Using index for group-by; Using temporary
|
||||
SELECT DISTINCT a, b, d, c FROM t1;
|
||||
a b d c
|
||||
1 1 0 1
|
||||
@ -765,6 +762,13 @@ a b d c
|
||||
1 2 0 1
|
||||
1 2 0 2
|
||||
1 2 0 3
|
||||
EXPLAIN SELECT DISTINCT a, b, d, c FROM t1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 index NULL a 16 NULL 6 Using index
|
||||
INSERT INTO t1 SELECT seq/10,seq/10,seq/10,seq/10,seq from seq_1_to_100;
|
||||
EXPLAIN SELECT DISTINCT a, b, d, c FROM t1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range NULL PRIMARY 16 NULL 10 Using index for group-by; Using temporary
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Bug #46159: simple query that never returns
|
||||
|
Reference in New Issue
Block a user