summaryrefslogtreecommitdiff
path: root/sql/sql_update.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_update.cc')
-rw-r--r--sql/sql_update.cc24
1 files changed, 11 insertions, 13 deletions
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index c30749677d6..b6bce800b0e 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -148,7 +148,7 @@ int mysql_update(THD *thd,
}
if (!select && limit != HA_POS_ERROR)
{
- if (MAX_KEY != (used_index= get_index_for_order(table, order, limit)))
+ if ((used_index= get_index_for_order(table, order, limit)) != MAX_KEY)
need_sort= FALSE;
}
/* If running in safe sql mode, don't allow updates without keys */
@@ -171,14 +171,14 @@ int mysql_update(THD *thd,
used_key_is_modified= (!select->quick->unique_key_range() &&
check_if_key_used(table, used_index, fields));
}
- else if (used_index != MAX_KEY)
+ else
{
- used_key_is_modified= check_if_key_used(table, used_index, fields);
+ used_key_is_modified= 0;
+ if (used_index == MAX_KEY) // no index for sort order
+ used_index= table->file->key_used_on_scan;
+ if (used_index != MAX_KEY)
+ used_key_is_modified= check_if_key_used(table, used_index, fields);
}
- else if ((used_index=table->file->key_used_on_scan) < MAX_KEY)
- used_key_is_modified=check_if_key_used(table, used_index, fields);
- else
- used_key_is_modified=0;
if (used_key_is_modified || order)
{
@@ -190,11 +190,11 @@ int mysql_update(THD *thd,
if (used_index < MAX_KEY && old_used_keys.is_set(used_index))
{
table->key_read=1;
- table->file->extra(HA_EXTRA_KEYREAD); //todo: psergey: check
+ table->file->extra(HA_EXTRA_KEYREAD);
}
/* note: can actually avoid sorting below.. */
- if (order && need_sort)
+ if (order && (need_sort || used_key_is_modified))
{
/*
Doing an ORDER BY; Let filesort find and sort the rows we are going
@@ -204,6 +204,7 @@ int mysql_update(THD *thd,
SORT_FIELD *sortorder;
ha_rows examined_rows;
+ used_index= MAX_KEY; // For call to init_read_record()
table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
MYF(MY_FAE | MY_ZEROFILL));
if (!(sortorder=make_unireg_sortorder(order, &length)) ||
@@ -265,10 +266,7 @@ int mysql_update(THD *thd,
error= 1; // Aborted
limit= tmp_limit;
end_read_record(&info);
-
- /* if we got here we must not use index in the main update loop below */
- used_index= MAX_KEY;
-
+
/* Change select to use tempfile */
if (select)
{