mirror of
https://github.com/MariaDB/server.git
synced 2025-11-08 00:28:29 +03:00
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:
@@ -4448,7 +4448,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
|
||||
{
|
||||
@@ -4478,14 +4478,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
|
||||
|
||||
@@ -2446,6 +2446,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);
|
||||
@@ -5068,7 +5073,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;
|
||||
}
|
||||
|
||||
@@ -5083,10 +5088,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);
|
||||
|
||||
@@ -2581,6 +2581,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_ident_db db;
|
||||
Lex_ident_table table_name;
|
||||
Lex_ident_i_s_table schema_table_name;
|
||||
|
||||
Reference in New Issue
Block a user