Simplify NEXTVAL(sequence) when used with DEFAULT

Instead of adding another TABLE_LIST to
Item_func_nextval->table_list->next_local, update instead
Item_func_nextval->table_list->table with the correct table.

This removes all checking of table_list->table and table_list->next_local
when using sequences.
This commit is contained in:
Monty 2025-09-14 19:08:25 +03:00 committed by Sergei Golubchik
parent 516f68af9e
commit 72341bc255
3 changed files with 13 additions and 13 deletions

View File

@ -4241,7 +4241,7 @@ protected:
bool check_access(THD *, privilege_t);
public:
Item_func_nextval(THD *thd, TABLE_LIST *table_list_arg):
Item_longlong_func(thd), table_list(table_list_arg) {}
Item_longlong_func(thd), table_list(table_list_arg), table(0) {}
longlong val_int() override;
LEX_CSTRING func_name_cstring() const override
{
@ -4270,14 +4270,8 @@ public:
*/
void update_table()
{
if (!(table= table_list->table))
{
/*
If nextval was used in DEFAULT then next_local points to
the table_list used by to open the sequence table
*/
table= table_list->next_local->table;
}
table= table_list->table;
DBUG_ASSERT(table);
}
bool const_item() const override { return 0; }
Item *do_get_copy(THD *thd) const override

View File

@ -2423,6 +2423,11 @@ retry_share:
DBUG_ASSERT(table->file->pushed_cond == NULL);
table_list->updatable= 1; // It is not derived table nor non-updatable VIEW
table_list->table= table;
if (table_list->linked_table)
{
/* Update link for sequence tables in default */
table_list->linked_table->table= table;
}
if (!from_share && table->vcol_fix_expr(thd))
DBUG_RETURN(true);
@ -5052,7 +5057,7 @@ add_internal_tables(THD *thd, Query_tables_list *prelocking_ctx,
next_local value as it may have been changed by a previous
statement using the same table.
*/
tables->next_local= tmp;
tmp->linked_table= tables;
continue;
}
@ -5067,10 +5072,10 @@ add_internal_tables(THD *thd, Query_tables_list *prelocking_ctx,
&prelocking_ctx->query_tables_last,
tables->for_insert_data);
/*
Store link to the new table_list that will be used by open so that
Item_func_nextval() can find it
Store link to the sequences table so that we can in open_table() update
it to point to the opened table.
*/
tables->next_local= tl;
tl->linked_table= tables;
DBUG_PRINT("info", ("table name: %s added", tables->table_name.str));
} while ((tables= tables->next_global));
DBUG_RETURN(FALSE);

View File

@ -2414,6 +2414,7 @@ struct TABLE_LIST
TABLE_LIST *next_local;
/* link in a global list of all queries tables */
TABLE_LIST *next_global, **prev_global;
TABLE_LIST *linked_table; // For sequence tables used in default
LEX_CSTRING db;
LEX_CSTRING table_name;
LEX_CSTRING schema_table_name;