=== modified file 'mysql-test/r/key.result' --- mysql-test/r/key.result 2013-11-20 11:05:39 +0000 +++ mysql-test/r/key.result 2014-03-13 12:15:10 +0000 @@ -612,3 +612,30 @@ SELECT 1 as RES FROM t1 AS t1_outer WHER (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; RES DROP TABLE t1; +# +# Bug#18144: Cost with FORCE/USE index seems incorrect in some cases. +# +# We are interested in showing that the cost for the last plan is higher +# than for the preceding two plans. +# +CREATE TABLE t1( a INT, b INT, KEY( a ) ); +INSERT INTO t1 values (1, 2), (1, 3), (2, 3), (2, 4), (3, 4), (3, 5); +EXPLAIN SELECT a, SUM( b ) FROM t1 GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +SHOW STATUS LIKE 'Last_query_cost'; +Variable_name Value +Last_query_cost 9.212184 +EXPLAIN SELECT a, SUM( b ) FROM t1 USE INDEX( a ) GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +SHOW STATUS LIKE 'Last_query_cost'; +Variable_name Value +Last_query_cost 9.212184 +EXPLAIN SELECT a, SUM( b ) FROM t1 FORCE INDEX( a ) GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL a 5 NULL 6 +SHOW STATUS LIKE 'Last_query_cost'; +Variable_name Value +Last_query_cost 14.199000 +DROP TABLE t1; === modified file 'mysql-test/t/key.test' --- mysql-test/t/key.test 2007-12-05 19:33:36 +0000 +++ mysql-test/t/key.test 2014-03-13 11:32:19 +0000 @@ -561,3 +561,23 @@ SELECT 1 as RES FROM t1 AS t1_outer WHER (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; DROP TABLE t1; + +--echo # +--echo # Bug#18144: Cost with FORCE/USE index seems incorrect in some cases. +--echo # +--echo # We are interested in showing that the cost for the last plan is higher +--echo # than for the preceding two plans. +--echo # +CREATE TABLE t1( a INT, b INT, KEY( a ) ); +INSERT INTO t1 values (1, 2), (1, 3), (2, 3), (2, 4), (3, 4), (3, 5); + +EXPLAIN SELECT a, SUM( b ) FROM t1 GROUP BY a; +SHOW STATUS LIKE 'Last_query_cost'; + +EXPLAIN SELECT a, SUM( b ) FROM t1 USE INDEX( a ) GROUP BY a; +SHOW STATUS LIKE 'Last_query_cost'; + +EXPLAIN SELECT a, SUM( b ) FROM t1 FORCE INDEX( a ) GROUP BY a; +SHOW STATUS LIKE 'Last_query_cost'; + +DROP TABLE t1;