diff options
author | unknown <sergefp@mysql.com> | 2005-10-18 14:08:50 +0400 |
---|---|---|
committer | unknown <sergefp@mysql.com> | 2005-10-18 14:08:50 +0400 |
commit | 7d81acb5e91b0e94b169bfb0a09f430f28496d59 (patch) | |
tree | d6d7b767e37101864068ce6dc37173555bab7642 /sql/sql_update.cc | |
parent | 3867a5db376cf225403116c26eaa8c73e4c9b359 (diff) | |
parent | 8ff8fac53dc7423d1fbe229dfb2f112236b7cf2a (diff) | |
download | mariadb-git-7d81acb5e91b0e94b169bfb0a09f430f28496d59.tar.gz |
Merge spetrunia@bk-internal.mysql.com:/home/bk/mysql-4.1
into mysql.com:/home/psergey/mysql-4.1-bug12915-r2
sql/sql_update.cc:
Auto merged
Diffstat (limited to 'sql/sql_update.cc')
-rw-r--r-- | sql/sql_update.cc | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/sql/sql_update.cc b/sql/sql_update.cc index ca40ed554dd..c30749677d6 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -61,7 +61,8 @@ int mysql_update(THD *thd, bool safe_update= thd->options & OPTION_SAFE_UPDATES; bool used_key_is_modified, transactional_table, log_delayed; int error=0; - uint used_index; + uint used_index= MAX_KEY; + bool need_sort= TRUE; #ifndef NO_EMBEDDED_ACCESS_CHECKS uint want_privilege; #endif @@ -145,6 +146,11 @@ int mysql_update(THD *thd, send_ok(thd); // No matching records DBUG_RETURN(0); } + if (!select && limit != HA_POS_ERROR) + { + if (MAX_KEY != (used_index= get_index_for_order(table, order, limit))) + need_sort= FALSE; + } /* If running in safe sql mode, don't allow updates without keys */ if (table->quick_keys.is_clear_all()) { @@ -157,6 +163,7 @@ int mysql_update(THD *thd, } } init_ftfuncs(thd, &thd->lex->select_lex, 1); + /* Check if we are modifying a key that we are used to search with */ if (select && select->quick) { @@ -164,13 +171,15 @@ 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) + { + 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; - used_index= MAX_KEY; - } + if (used_key_is_modified || order) { /* @@ -181,10 +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); + table->file->extra(HA_EXTRA_KEYREAD); //todo: psergey: check } - if (order) + /* note: can actually avoid sorting below.. */ + if (order && need_sort) { /* Doing an ORDER BY; Let filesort find and sort the rows we are going @@ -225,7 +235,11 @@ int mysql_update(THD *thd, DISK_BUFFER_SIZE, MYF(MY_WME))) goto err; - init_read_record(&info,thd,table,select,0,1); + if (used_index == MAX_KEY) + init_read_record(&info,thd,table,select,0,1); + else + init_read_record_idx(&info, thd, table, 1, used_index); + thd->proc_info="Searching rows for update"; uint tmp_limit= limit; @@ -251,6 +265,10 @@ 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) { |