mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fixed bug#28404.
This patch adds cost estimation for the queries with ORDER BY / GROUP BY and LIMIT. If there was a ref/range access to the table whose rows were required to be ordered in the result set the optimizer always employed this access though a scan by a different index that was compatible with the required order could be cheaper to produce the first L rows of the result set. Now for such queries the optimizer makes a choice between the cheapest ref/range accesses not compatible with the given order and index scans compatible with it. mysql-test/r/distinct.result: Adjusted results for test cases affected fy the fix for bug #28404. mysql-test/r/endspace.result: Adjusted results for test cases affected fy the fix for bug #28404. mysql-test/r/group_by.result: Adjusted results for test cases affected fy the fix for bug #28404. mysql-test/r/group_min_max.result: Adjusted results for test cases affected fy the fix for bug #28404. mysql-test/r/innodb.result: Adjusted results for test cases affected fy the fix for bug #28404. mysql-test/r/innodb_mysql.result: Adjusted results for test cases affected fy the fix for bug #28404. mysql-test/r/merge.result: Adjusted results for test cases affected fy the fix for bug #28404. mysql-test/r/order_by.result: Added a test case for bug #28404. mysql-test/r/select_found.result: Adjusted results for test cases affected fy the fix for bug #28404. mysql-test/r/subselect.result: Adjusted results for test cases affected fy the fix for bug #28404. mysql-test/t/distinct.test: Changed a test case after adding the fix for bug #28404. mysql-test/t/order_by.test: Added a test case for bug #28404. sql/sql_select.cc: Fixed bug#28404. This patch adds cost estimation for the queries with ORDER BY / GROUP BY and LIMIT. Now for such queries the optimizer makes a choice between the cheapest ref/range accesses not compatible with the given order and index scans compatible with it. Modified the function test_if_skip_sort_order to make the above mentioned choice cost based. sql/sql_select.h: Fixed bug#28404. This patch adds cost estimation for the queries with ORDER BY / GROUP BY and LIMIT. Added a new field fot the JOIN_TAB structure.
This commit is contained in:
@ -851,13 +851,13 @@ EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
|
||||
id 1
|
||||
select_type SIMPLE
|
||||
table t1
|
||||
type range
|
||||
type index
|
||||
possible_keys bkey
|
||||
key bkey
|
||||
key_len 5
|
||||
key PRIMARY
|
||||
key_len 4
|
||||
ref NULL
|
||||
rows 16
|
||||
Extra Using where; Using index; Using filesort
|
||||
rows 32
|
||||
Extra Using where; Using index
|
||||
SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
|
||||
a b
|
||||
1 2
|
||||
@ -946,13 +946,13 @@ EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a;
|
||||
id 1
|
||||
select_type SIMPLE
|
||||
table t2
|
||||
type ref
|
||||
type index
|
||||
possible_keys bkey
|
||||
key bkey
|
||||
key_len 5
|
||||
ref const
|
||||
rows 8
|
||||
Extra Using where; Using index; Using filesort
|
||||
key PRIMARY
|
||||
key_len 4
|
||||
ref NULL
|
||||
rows 16
|
||||
Extra Using where; Using index
|
||||
SELECT * FROM t2 WHERE b=1 ORDER BY a;
|
||||
a b c
|
||||
1 1 1
|
||||
|
Reference in New Issue
Block a user