Commit 0dd9ec97 authored by Monty's avatar Monty Committed by Sergei Petrunia

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)
parent 1c88ac60
...@@ -1193,7 +1193,7 @@ INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1; ...@@ -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; INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b; EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
id select_type table type possible_keys key key_len ref rows Extra 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; 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 id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using filesort 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, ...@@ -30550,6 +30550,13 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
add("fanout", fanout); 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"); Json_writer_array possible_keys(thd,"possible_keys");
for (nr=0; nr < table->s->keys ; nr++) for (nr=0; nr < table->s->keys ; nr++)
{ {
...@@ -30702,8 +30709,7 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table, ...@@ -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 there is either a group by or a FORCE_INDEX
- If the new cost is better than read_time - If the new cost is better than read_time
*/ */
if (((table->force_index || group) && best_key < 0 && ref_key < 0) || if (range_cost < read_time)
range_cost < read_time)
{ {
read_time= range_cost; read_time= range_cost;
possible_key.add("chosen", true); possible_key.add("chosen", true);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment