Skip to content

Commit

Permalink
MDEV-5816: Stored programs: validation of stored program statements
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmitryshulga committed Jul 20, 2023
1 parent 9f34225 commit 66d8817
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
8 changes: 0 additions & 8 deletions sql/sp_head.cc
Expand Up @@ -801,12 +801,6 @@ sp_head::init(LEX *lex)
if (!lex->spcont)
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;
}

Expand Down Expand Up @@ -2492,8 +2486,6 @@ sp_head::merge_lex(THD *thd, LEX *oldlex, LEX *sublex)

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. */
DBUG_PRINT("info", ("sublex->get_stmt_unsafe_flags: 0x%x",
sublex->get_stmt_unsafe_flags()));
Expand Down
9 changes: 9 additions & 0 deletions sql/sp_head.h
Expand Up @@ -952,6 +952,15 @@ class sp_head :private Query_arena,
push_backpatch(THD *thd, sp_instr *, sp_label *, List<bp_t> *list,
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


Expand Down
4 changes: 2 additions & 2 deletions sql/sql_lex.cc
Expand Up @@ -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
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);
}
Expand Down Expand Up @@ -7883,7 +7883,7 @@ Item *LEX::create_and_link_Item_trigger_field(THD *thd,
in trigger.
*/
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;
}
Expand Down
9 changes: 0 additions & 9 deletions sql/sql_lex.h
Expand Up @@ -3536,14 +3536,6 @@ struct LEX: public Query_tables_list

/* Characterstics of trigger being created */
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
Expand Down Expand Up @@ -5102,7 +5094,6 @@ class sp_lex_local: public st_lex_local
spcont= oldlex->spcont;
/* Keep the parent trigger stuff too */
trg_chistics= oldlex->trg_chistics;
trg_table_fields.empty();
sp_lex_in_use= false;
}
};
Expand Down
6 changes: 3 additions & 3 deletions sql/sql_trigger.cc
Expand Up @@ -939,7 +939,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
*/
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)
{
/*
Expand Down Expand Up @@ -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
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
opened.
Expand All @@ -1807,7 +1807,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const LEX_CSTRING *db,
SELECT)...
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->next_trg_field)
{
Expand Down

0 comments on commit 66d8817

Please sign in to comment.