1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

WL#3527: Extend IGNORE INDEX so places where index is ignored

can be specified
Currently MySQL allows one to specify what indexes to ignore during
join optimization. The scope of the current USE/FORCE/IGNORE INDEX 
statement is only the FROM clause, while all other clauses are not 
affected.

However, in certain cases, the optimizer
may incorrectly choose an index for sorting and/or grouping, and
produce an inefficient query plan.

This task provides the means to specify what indexes are
ignored/used for what operation in a more fine-grained manner, thus
making it possible to manually force a better plan. We do this
by extending the current IGNORE/USE/FORCE INDEX syntax to:

IGNORE/USE/FORCE INDEX [FOR {JOIN | ORDER | GROUP BY}]

so that:
- if no FOR is specified, the index hint will apply everywhere.
- if MySQL is started with the compatibility option --old_mode then
  an index hint without a FOR clause works as in 5.0 (i.e, the 
  index will only be ignored for JOINs, but can still be used to
  compute ORDER BY).

See the WL#3527 for further details.
This commit is contained in:
gkodinov/kgeorge@macbook.gmz
2007-03-05 19:08:41 +02:00
parent 6a49f0cd93
commit b9c82eaa89
25 changed files with 727 additions and 458 deletions

View File

@ -130,7 +130,7 @@ int mysql_update(THD *thd,
#endif
uint table_count= 0;
ha_rows updated, found;
key_map old_used_keys;
key_map old_covering_keys;
TABLE *table;
SQL_SELECT *select;
READ_RECORD info;
@ -168,8 +168,8 @@ int mysql_update(THD *thd,
thd->proc_info="init";
table= table_list->table;
/* Calculate "table->used_keys" based on the WHERE */
table->used_keys= table->s->keys_in_use;
/* Calculate "table->covering_keys" based on the WHERE */
table->covering_keys= table->s->keys_in_use;
table->quick_keys.clear_all();
#ifndef NO_EMBEDDED_ACCESS_CHECKS
@ -179,7 +179,7 @@ int mysql_update(THD *thd,
if (mysql_prepare_update(thd, table_list, &conds, order_num, order))
DBUG_RETURN(1);
old_used_keys= table->used_keys; // Keys used in WHERE
old_covering_keys= table->covering_keys; // Keys used in WHERE
/* Check the fields we are going to modify */
#ifndef NO_EMBEDDED_ACCESS_CHECKS
table_list->grant.want_privilege= table->grant.want_privilege= want_privilege;
@ -228,7 +228,7 @@ int mysql_update(THD *thd,
limit= 0; // Impossible WHERE
}
// Don't count on usage of 'only index' when calculating which key to use
table->used_keys.clear_all();
table->covering_keys.clear_all();
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (prune_partitions(thd, table, conds))
@ -303,7 +303,7 @@ int mysql_update(THD *thd,
We can't update table directly; We must first search after all
matching rows before updating the table!
*/
if (used_index < MAX_KEY && old_used_keys.is_set(used_index))
if (used_index < MAX_KEY && old_covering_keys.is_set(used_index))
{
table->key_read=1;
table->mark_columns_used_by_index(used_index);
@ -1091,7 +1091,7 @@ int multi_update::prepare(List<Item> &not_used_values,
}
/*
We have to check values after setup_tables to get used_keys right in
We have to check values after setup_tables to get covering_keys right in
reference tables
*/
@ -1118,7 +1118,7 @@ int multi_update::prepare(List<Item> &not_used_values,
update.link_in_list((byte*) tl, (byte**) &tl->next_local);
tl->shared= table_count++;
table->no_keyread=1;
table->used_keys.clear_all();
table->covering_keys.clear_all();
table->pos_in_table_list= tl;
}
}