summaryrefslogtreecommitdiff
path: root/sql/sql_base.cc
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2023-05-17 14:58:11 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2023-05-17 14:58:11 +0200
commit2543673dd22782f59299fd2e72179601892bd967 (patch)
treeb73641bd88c9d1572203c75da618fce1937518e8 /sql/sql_base.cc
parent4e5b771e980edfdad5c5414aa62c81d409d585a4 (diff)
parentef911553f442cbb1baaac2af44c38b54fd058c41 (diff)
downloadmariadb-git-bb-11.1-release.tar.gz
Merge branch '11.0' into 11.1bb-11.1-release
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r--sql/sql_base.cc33
1 files changed, 27 insertions, 6 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index bae35cd3264..8acee122e07 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -6347,7 +6347,10 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, size_t length,
if (cached_field_index < table->s->fields &&
!my_strcasecmp(system_charset_info,
table->field[cached_field_index]->field_name.str, name))
+ {
field= table->field[cached_field_index];
+ DEBUG_SYNC(thd, "table_field_cached");
+ }
else
{
LEX_CSTRING fname= {name, length};
@@ -6809,6 +6812,13 @@ find_field_in_tables(THD *thd, Item_ident *item,
if (last_table)
last_table= last_table->next_name_resolution_table;
+ field_index_t fake_index_for_duplicate_search= NO_CACHED_FIELD_INDEX;
+ /*
+ For the field search it will point to field cache, but for duplicate
+ search it will point to fake_index_for_duplicate_search (no cache
+ present).
+ */
+ field_index_t *current_cache= &(item->cached_field_index);
for (; cur_table != last_table ;
cur_table= cur_table->next_name_resolution_table)
{
@@ -6823,7 +6833,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
SQLCOM_SHOW_FIELDS)
? false : check_privileges,
allow_rowid,
- &(item->cached_field_index),
+ current_cache,
register_tree_change,
&actual_table);
if (cur_field)
@@ -6838,7 +6848,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
item->name.str, db, table_name,
ignored_tables, ref, false,
allow_rowid,
- &(item->cached_field_index),
+ current_cache,
register_tree_change,
&actual_table);
if (cur_field)
@@ -6855,8 +6865,19 @@ find_field_in_tables(THD *thd, Item_ident *item,
Store the original table of the field, which may be different from
cur_table in the case of NATURAL/USING join.
*/
- item->cached_table= (!actual_table->cacheable_table || found) ?
- 0 : actual_table;
+ if (actual_table->cacheable_table /*(1)*/ && !found /*(2)*/)
+ {
+ /*
+ We have just found a field allowed to cache (1) and
+ it is not dublicate search (2).
+ */
+ item->cached_table= actual_table;
+ }
+ else
+ {
+ item->cached_table= NULL;
+ item->cached_field_index= NO_CACHED_FIELD_INDEX;
+ }
DBUG_ASSERT(thd->where);
/*
@@ -6875,6 +6896,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
return (Field*) 0;
}
found= cur_field;
+ current_cache= &fake_index_for_duplicate_search;
}
}
@@ -8332,9 +8354,8 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
table_list;
table_list= table_list->next_local)
{
- if (table_list->merge_underlying_list)
+ if (table_list->is_merged_derived() && table_list->merge_underlying_list)
{
- DBUG_ASSERT(table_list->is_merged_derived());
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
bool res;