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

MDEV-5816: Stored programs: validation of stored program statements

This is the prerequisite patch to move the data member
LEX::trg_table_fields to the class sp_head and rename it as
m_trg_table_fields.

This data member is used for handling OLD/NEW pseudo-rows inside
a trigger body and in order to be able to re-parse a trigger body
the data member must be moved from the struct LEX to the class sp_head.
This commit is contained in:
Dmitry Shulga
2023-07-19 17:47:08 +07:00
parent 9f34225ec4
commit 66d88176e9
5 changed files with 14 additions and 22 deletions

View File

@@ -801,12 +801,6 @@ sp_head::init(LEX *lex)
if (!lex->spcont) if (!lex->spcont)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
/*
Altough trg_table_fields list is used only in triggers we init for all
types of stored procedures to simplify reset_lex()/restore_lex() code.
*/
lex->trg_table_fields.empty();
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
@@ -2492,8 +2486,6 @@ sp_head::merge_lex(THD *thd, LEX *oldlex, LEX *sublex)
sublex->set_trg_event_type_for_tables(); sublex->set_trg_event_type_for_tables();
oldlex->trg_table_fields.push_back(&sublex->trg_table_fields);
/* If this substatement is unsafe, the entire routine is too. */ /* If this substatement is unsafe, the entire routine is too. */
DBUG_PRINT("info", ("sublex->get_stmt_unsafe_flags: 0x%x", DBUG_PRINT("info", ("sublex->get_stmt_unsafe_flags: 0x%x",
sublex->get_stmt_unsafe_flags())); sublex->get_stmt_unsafe_flags()));

View File

@@ -952,6 +952,15 @@ protected:
push_backpatch(THD *thd, sp_instr *, sp_label *, List<bp_t> *list, push_backpatch(THD *thd, sp_instr *, sp_label *, List<bp_t> *list,
backpatch_instr_type itype); backpatch_instr_type itype);
public:
/*
List of all items (Item_trigger_field objects) representing fields in
old/new version of row in trigger. We use this list for checking whenever
all such fields are valid at trigger creation time and for binding these
fields to TABLE object at table open (altough for latter pointer to table
being opened is probably enough).
*/
SQL_I_List<Item_trigger_field> m_trg_table_fields;
}; // class sp_head : public Sql_alloc }; // class sp_head : public Sql_alloc

View File

@@ -239,7 +239,7 @@ bool LEX::set_trigger_new_row(const LEX_CSTRING *name, Item *val)
Let us add this item to list of all Item_trigger_field Let us add this item to list of all Item_trigger_field
objects in trigger. objects in trigger.
*/ */
trg_table_fields.link_in_list(trg_fld, &trg_fld->next_trg_field); sphead->m_trg_table_fields.link_in_list(trg_fld, &trg_fld->next_trg_field);
return sphead->add_instr(sp_fld); return sphead->add_instr(sp_fld);
} }
@@ -7883,7 +7883,7 @@ Item *LEX::create_and_link_Item_trigger_field(THD *thd,
in trigger. in trigger.
*/ */
if (likely(trg_fld)) if (likely(trg_fld))
trg_table_fields.link_in_list(trg_fld, &trg_fld->next_trg_field); sphead->m_trg_table_fields.link_in_list(trg_fld, &trg_fld->next_trg_field);
return trg_fld; return trg_fld;
} }

View File

@@ -3536,14 +3536,6 @@ public:
/* Characterstics of trigger being created */ /* Characterstics of trigger being created */
st_trg_chistics trg_chistics; st_trg_chistics trg_chistics;
/*
List of all items (Item_trigger_field objects) representing fields in
old/new version of row in trigger. We use this list for checking whenever
all such fields are valid at trigger creation time and for binding these
fields to TABLE object at table open (altough for latter pointer to table
being opened is probably enough).
*/
SQL_I_List<Item_trigger_field> trg_table_fields;
/* /*
stmt_definition_begin is intended to point to the next word after stmt_definition_begin is intended to point to the next word after
@@ -5102,7 +5094,6 @@ public:
spcont= oldlex->spcont; spcont= oldlex->spcont;
/* Keep the parent trigger stuff too */ /* Keep the parent trigger stuff too */
trg_chistics= oldlex->trg_chistics; trg_chistics= oldlex->trg_chistics;
trg_table_fields.empty();
sp_lex_in_use= false; sp_lex_in_use= false;
} }
}; };

View File

@@ -939,7 +939,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
*/ */
old_field= new_field= table->field; old_field= new_field= table->field;
for (trg_field= lex->trg_table_fields.first; for (trg_field= lex->sphead->m_trg_table_fields.first;
trg_field; trg_field= trg_field->next_trg_field) trg_field; trg_field= trg_field->next_trg_field)
{ {
/* /*
@@ -1797,7 +1797,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const LEX_CSTRING *db,
in old/new versions of row in trigger into lists containing all such in old/new versions of row in trigger into lists containing all such
objects for the trigger_list with same action and timing. objects for the trigger_list with same action and timing.
*/ */
trigger->trigger_fields= lex.trg_table_fields.first; trigger->trigger_fields= sp->m_trg_table_fields.first;
/* /*
Also let us bind these objects to Field objects in table being Also let us bind these objects to Field objects in table being
opened. opened.
@@ -1807,7 +1807,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const LEX_CSTRING *db,
SELECT)... SELECT)...
Anyway some things can be checked only during trigger execution. Anyway some things can be checked only during trigger execution.
*/ */
for (Item_trigger_field *trg_field= lex.trg_table_fields.first; for (Item_trigger_field *trg_field= sp->m_trg_table_fields.first;
trg_field; trg_field;
trg_field= trg_field->next_trg_field) trg_field= trg_field->next_trg_field)
{ {