1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-33971 NAME_CONST in WHERE clause replaced by inner item

Improve performance of queries like
  SELECT * FROM t1 WHERE field = NAME_CONST('a', 4);
by, in this example, replacing the WHERE clause with field = 4
in the case of ref access.

The rewrite is done during fix_fields and we disambiguate this
case from other cases of NAME_CONST by inspecting where we are
in parsing.  We rely on THD::where to accomplish this.  To
improve performance there, we change the type of THD::where to
be an enumeration, so we can avoid string comparisons during
Item_name_const::fix_fields.  Consequently, this patch also
changes all usages of THD::where to conform likewise.
This commit is contained in:
Dave Gosselin
2024-04-26 12:13:31 -04:00
committed by Dave Gosselin
parent a0a7b1c128
commit 02e38e2ece
20 changed files with 310 additions and 75 deletions

View File

@@ -142,11 +142,11 @@ Item* convert_charset_partition_constant(Item *item, CHARSET_INFO *cs)
THD *thd= current_thd;
Name_resolution_context *context= &thd->lex->current_select->context;
TABLE_LIST *save_list= context->table_list;
const char *save_where= thd->where;
THD_WHERE save_where= thd->where;
item= item->safe_charset_converter(thd, cs);
context->table_list= NULL;
thd->where= "convert character set partition constant";
thd->where= THD_WHERE::CONVERT_CHARSET_CONST;
if (item && item->fix_fields_if_needed(thd, (Item**)NULL))
item= NULL;
thd->where= save_where;
@@ -841,7 +841,7 @@ static bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
func_expr->walk(&Item::change_context_processor, 0,
&lex.first_select_lex()->context);
thd->where= "partition function";
thd->where= THD_WHERE::PARTITION_FUNCTION;
/*
In execution we must avoid the use of thd->change_item_tree since
we might release memory before statement is completed. We do this