Skip to content

Commit 7215fe7

Browse files
MDEV-37252 Do not check is_key_used in get_index_for_order
This allows UPDATE to use ORDER BY indexes in the update columns.
1 parent ce7ab46 commit 7215fe7

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

mysql-test/main/explain_non_select.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ id select_type table type possible_keys key key_len ref rows Extra
7272
# This should use an index, possible_keys=NULL because there is no WHERE
7373
explain update t1 set a=a+1 order by a limit 2;
7474
id select_type table type possible_keys key key_len ref rows Extra
75-
1 SIMPLE t1 ALL NULL NULL NULL NULL 512 Using filesort
75+
1 SIMPLE t1 index NULL a 5 NULL 2 Using buffer
7676
# This should use range, possible_keys={a,b}
7777
explain update t1 set filler='fooo' where a<20 and b < 10;
7878
id select_type table type possible_keys key key_len ref rows Extra

mysql-test/main/update.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ update t1 set a=9999 order by a limit 1;
288288
update t1 set b=9999 order by a limit 1;
289289
show status like 'handler_read%';
290290
Variable_name Value
291-
Handler_read_first 1
291+
Handler_read_first 2
292292
Handler_read_key 0
293293
Handler_read_last 0
294294
Handler_read_next 0
295295
Handler_read_prev 0
296296
Handler_read_retry 0
297297
Handler_read_rnd 2
298298
Handler_read_rnd_deleted 0
299-
Handler_read_rnd_next 9
299+
Handler_read_rnd_next 0
300300
flush status;
301301
delete from t1 order by a limit 1;
302302
show status like 'handler_read%';

sql/sql_select.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33411,8 +33411,7 @@ uint get_index_for_order(ORDER *order, TABLE *table, SQL_SELECT *select,
3341133411
double new_cost;
3341233412
if (test_if_cheaper_ordering(FALSE, NULL, order, table,
3341333413
table->keys_in_use_for_order_by, -1, limit,
33414-
&key, &direction, &limit, &new_cost) &&
33415-
!is_key_used(table, key, table->write_set))
33414+
&key, &direction, &limit, &new_cost))
3341633415
{
3341733416
*need_sort= FALSE;
3341833417
*scanned_limit= limit;

0 commit comments

Comments
 (0)