Skip to content

Commit a00b5d3

Browse files
montywivuvova
authored andcommitted
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)
1 parent 018df60 commit a00b5d3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

mysql-test/suite/innodb/r/innodb_mysql.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
11931193
INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
11941194
EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
11951195
id select_type table type possible_keys key key_len ref rows Extra
1196-
1 SIMPLE t1 index NULL b 5 NULL 128
1196+
1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using temporary; Using filesort
11971197
EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
11981198
id select_type table type possible_keys key key_len ref rows Extra
11991199
1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using filesort

sql/sql_select.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30501,6 +30501,13 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
3050130501
add("fanout", fanout);
3050230502
}
3050330503

30504+
/*
30505+
Force using an index for sorting if there was no ref key
30506+
and FORCE INDEX was used.
30507+
*/
30508+
if (table->force_index && ref_key < 0)
30509+
read_time= DBL_MAX;
30510+
3050430511
Json_writer_array possible_keys(thd,"possible_keys");
3050530512
for (nr=0; nr < table->s->keys ; nr++)
3050630513
{
@@ -30653,8 +30660,7 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
3065330660
there is either a group by or a FORCE_INDEX
3065430661
- If the new cost is better than read_time
3065530662
*/
30656-
if (((table->force_index || group) && best_key < 0 && ref_key < 0) ||
30657-
range_cost < read_time)
30663+
if (range_cost < read_time)
3065830664
{
3065930665
read_time= range_cost;
3066030666
possible_key.add("chosen", true);

0 commit comments

Comments
 (0)