mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Merge spetrunia@bk-internal.mysql.com:/home/bk/mysql-4.1
into mysql.com:/home/psergey/mysql-4.1-bug12915-r2
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user