A cleanup for MDEV-10577 and MDEV-13919: moving a few sp_rcontext methods
Moving a few methods from sp_rcontext to different classes: - Table_ident::resolve_table_rowtype_ref - Qualified_column_ident::resolve_type_ref - Row_definition_list::resolve_table_rowtype_ref - Row_definition_list::adjust_formal_params_to_actual_params It easier to reuse these methods this way in the future.
This commit is contained in:
parent
3a6d94428f
commit
596baeb1bf
@ -4095,6 +4095,8 @@ public:
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bool adjust_formal_params_to_actual_params(THD *thd, List<Item> *args);
|
||||
bool resolve_type_refs(THD *);
|
||||
};
|
||||
|
||||
|
||||
|
@ -73,15 +73,15 @@ sp_rcontext *sp_rcontext::create(THD *thd,
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
|
||||
List<Spvar_definition> field_def_lst;
|
||||
Row_definition_list field_def_lst;
|
||||
ctx->m_root_parsing_ctx->retrieve_field_definitions(&field_def_lst);
|
||||
|
||||
if (args &&
|
||||
ctx->adjust_formal_params_to_actual_params(thd, field_def_lst, args))
|
||||
field_def_lst.adjust_formal_params_to_actual_params(thd, args))
|
||||
return NULL;
|
||||
|
||||
if (ctx->alloc_arrays(thd) ||
|
||||
(resolve_type_refs && ctx->resolve_type_refs(thd, field_def_lst)) ||
|
||||
(resolve_type_refs && field_def_lst.resolve_type_refs(thd)) ||
|
||||
ctx->init_var_table(thd, field_def_lst) ||
|
||||
ctx->init_var_items(thd, field_def_lst))
|
||||
{
|
||||
@ -93,13 +93,12 @@ sp_rcontext *sp_rcontext::create(THD *thd,
|
||||
}
|
||||
|
||||
|
||||
bool sp_rcontext::adjust_formal_params_to_actual_params(THD *thd,
|
||||
List<Spvar_definition> &field_def_lst,
|
||||
List<Item> *args)
|
||||
bool Row_definition_list::
|
||||
adjust_formal_params_to_actual_params(THD *thd, List<Item> *args)
|
||||
{
|
||||
List_iterator<Spvar_definition> it(field_def_lst);
|
||||
List_iterator<Spvar_definition> it(*this);
|
||||
List_iterator<Item> it_args(*args);
|
||||
DBUG_ASSERT(field_def_lst.elements >= args->elements );
|
||||
DBUG_ASSERT(elements >= args->elements );
|
||||
Spvar_definition *def;
|
||||
Item *arg;
|
||||
while ((def= it++) && (arg= it_args++))
|
||||
@ -169,8 +168,7 @@ check_column_grant_for_type_ref(THD *thd, TABLE_LIST *table_list,
|
||||
/**
|
||||
This method implementation is very close to fill_schema_table_by_open().
|
||||
*/
|
||||
bool sp_rcontext::resolve_type_ref(THD *thd, Column_definition *def,
|
||||
Qualified_column_ident *ref)
|
||||
bool Qualified_column_ident::resolve_type_ref(THD *thd, Column_definition *def)
|
||||
{
|
||||
Open_tables_backup open_tables_state_backup;
|
||||
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
|
||||
@ -187,18 +185,18 @@ bool sp_rcontext::resolve_type_ref(THD *thd, Column_definition *def,
|
||||
// Make %TYPE variables see temporary tables that shadow permanent tables
|
||||
thd->temporary_tables= open_tables_state_backup.temporary_tables;
|
||||
|
||||
if ((table_list= lex.select_lex.add_table_to_list(thd, ref, NULL, 0,
|
||||
if ((table_list= lex.select_lex.add_table_to_list(thd, this, NULL, 0,
|
||||
TL_READ_NO_INSERT,
|
||||
MDL_SHARED_READ)) &&
|
||||
!check_table_access(thd, SELECT_ACL, table_list, TRUE, UINT_MAX, FALSE) &&
|
||||
!open_tables_only_view_structure(thd, table_list,
|
||||
thd->mdl_context.has_locks()))
|
||||
{
|
||||
if ((src= lex.query_tables->table->find_field_by_name(&ref->m_column)))
|
||||
if ((src= lex.query_tables->table->find_field_by_name(&m_column)))
|
||||
{
|
||||
if (!(rc= check_column_grant_for_type_ref(thd, table_list,
|
||||
ref->m_column.str,
|
||||
ref->m_column.length)))
|
||||
m_column.str,
|
||||
m_column.length)))
|
||||
{
|
||||
*def= Column_definition(thd, src, NULL/*No defaults,no constraints*/);
|
||||
def->flags&= (uint) ~NOT_NULL_FLAG;
|
||||
@ -206,7 +204,7 @@ bool sp_rcontext::resolve_type_ref(THD *thd, Column_definition *def,
|
||||
}
|
||||
}
|
||||
else
|
||||
my_error(ER_BAD_FIELD_ERROR, MYF(0), ref->m_column.str, ref->table.str);
|
||||
my_error(ER_BAD_FIELD_ERROR, MYF(0), m_column.str, table.str);
|
||||
}
|
||||
|
||||
lex.unit.cleanup();
|
||||
@ -223,9 +221,8 @@ bool sp_rcontext::resolve_type_ref(THD *thd, Column_definition *def,
|
||||
rec t1%ROWTYPE;
|
||||
It opens the table "t1" and copies its structure to %ROWTYPE variable.
|
||||
*/
|
||||
bool sp_rcontext::resolve_table_rowtype_ref(THD *thd,
|
||||
Row_definition_list &defs,
|
||||
Table_ident *ref)
|
||||
bool Table_ident::resolve_table_rowtype_ref(THD *thd,
|
||||
Row_definition_list &defs)
|
||||
{
|
||||
Open_tables_backup open_tables_state_backup;
|
||||
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
|
||||
@ -246,7 +243,7 @@ bool sp_rcontext::resolve_table_rowtype_ref(THD *thd,
|
||||
// Make %ROWTYPE variables see temporary tables that shadow permanent tables
|
||||
thd->temporary_tables= open_tables_state_backup.temporary_tables;
|
||||
|
||||
if ((table_list= lex.select_lex.add_table_to_list(thd, ref, NULL, 0,
|
||||
if ((table_list= lex.select_lex.add_table_to_list(thd, this, NULL, 0,
|
||||
TL_READ_NO_INSERT,
|
||||
MDL_SHARED_READ)) &&
|
||||
!check_table_access(thd, SELECT_ACL, table_list, TRUE, UINT_MAX, FALSE) &&
|
||||
@ -284,14 +281,14 @@ bool sp_rcontext::resolve_table_rowtype_ref(THD *thd,
|
||||
}
|
||||
|
||||
|
||||
bool sp_rcontext::resolve_type_refs(THD *thd, List<Spvar_definition> &defs)
|
||||
bool Row_definition_list::resolve_type_refs(THD *thd)
|
||||
{
|
||||
List_iterator<Spvar_definition> it(defs);
|
||||
List_iterator<Spvar_definition> it(*this);
|
||||
Spvar_definition *def;
|
||||
while ((def= it++))
|
||||
{
|
||||
if (def->is_column_type_ref() &&
|
||||
resolve_type_ref(thd, def, def->column_type_ref()))
|
||||
def->column_type_ref()->resolve_type_ref(thd, def))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -323,7 +320,7 @@ bool sp_rcontext::init_var_items(THD *thd,
|
||||
Row_definition_list defs;
|
||||
Item_field_row *item= new (thd->mem_root) Item_field_row(thd, field);
|
||||
if (!(m_var_items[idx]= item) ||
|
||||
resolve_table_rowtype_ref(thd, defs, def->table_rowtype_ref()) ||
|
||||
def->table_rowtype_ref()->resolve_table_rowtype_ref(thd, defs) ||
|
||||
item->row_create_items(thd, &defs))
|
||||
return true;
|
||||
}
|
||||
|
@ -340,15 +340,6 @@ private:
|
||||
/// @retval true on error.
|
||||
bool init_var_table(THD *thd, List<Spvar_definition> &defs);
|
||||
|
||||
bool resolve_type_refs(THD *, List<Spvar_definition> &defs);
|
||||
bool resolve_type_ref(THD *thd, Column_definition *def,
|
||||
Qualified_column_ident *ref);
|
||||
bool resolve_table_rowtype_ref(THD *thd, Row_definition_list &defs,
|
||||
Table_ident *ref);
|
||||
bool adjust_formal_params_to_actual_params(THD *thd,
|
||||
List<Spvar_definition> &field_def_lst,
|
||||
List<Item> *args);
|
||||
|
||||
/// Create and initialize an Item-adapter (Item_field) for each SP-var field.
|
||||
///
|
||||
/// param thd Thread handle.
|
||||
|
@ -5496,6 +5496,7 @@ public:
|
||||
{
|
||||
db= *db_name;
|
||||
}
|
||||
bool resolve_table_rowtype_ref(THD *thd, Row_definition_list &defs);
|
||||
};
|
||||
|
||||
|
||||
@ -5519,6 +5520,7 @@ public:
|
||||
:Table_ident(thd, db, table, false),
|
||||
m_column(*column)
|
||||
{ }
|
||||
bool resolve_type_ref(THD *thd, Column_definition *def);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user