mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Changed a rule to be cost based in test_if_cheaper_ordering
- Simplified test by setting read_time=DBL_MAX at start of loop if FORCE INDEX is used - No need to test for 'group by' as the cost compare should handle it. - Only one test change where index scan was replaced with table scan (correct)
This commit is contained in:
@ -1193,7 +1193,7 @@ INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
|
||||
INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
|
||||
EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 index NULL b 5 NULL 128
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using temporary; Using filesort
|
||||
EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using filesort
|
||||
|
@ -30550,6 +30550,13 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
|
||||
add("fanout", fanout);
|
||||
}
|
||||
|
||||
/*
|
||||
Force using an index for sorting if there was no ref key
|
||||
and FORCE INDEX was used.
|
||||
*/
|
||||
if (table->force_index && ref_key < 0)
|
||||
read_time= DBL_MAX;
|
||||
|
||||
Json_writer_array possible_keys(thd,"possible_keys");
|
||||
for (nr=0; nr < table->s->keys ; nr++)
|
||||
{
|
||||
@ -30702,8 +30709,7 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
|
||||
there is either a group by or a FORCE_INDEX
|
||||
- If the new cost is better than read_time
|
||||
*/
|
||||
if (((table->force_index || group) && best_key < 0 && ref_key < 0) ||
|
||||
range_cost < read_time)
|
||||
if (range_cost < read_time)
|
||||
{
|
||||
read_time= range_cost;
|
||||
possible_key.add("chosen", true);
|
||||
|
Reference in New Issue
Block a user