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

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:
Alexander Barkov
2017-09-28 17:26:23 +04:00
parent 3a6d94428f
commit 596baeb1bf
4 changed files with 24 additions and 32 deletions

View File

@@ -4095,6 +4095,8 @@ public:
} }
return 0; return 0;
} }
bool adjust_formal_params_to_actual_params(THD *thd, List<Item> *args);
bool resolve_type_refs(THD *);
}; };

View File

@@ -73,15 +73,15 @@ sp_rcontext *sp_rcontext::create(THD *thd,
if (!ctx) if (!ctx)
return NULL; 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); ctx->m_root_parsing_ctx->retrieve_field_definitions(&field_def_lst);
if (args && 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; return NULL;
if (ctx->alloc_arrays(thd) || 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_table(thd, field_def_lst) ||
ctx->init_var_items(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, bool Row_definition_list::
List<Spvar_definition> &field_def_lst, adjust_formal_params_to_actual_params(THD *thd, List<Item> *args)
List<Item> *args)
{ {
List_iterator<Spvar_definition> it(field_def_lst); List_iterator<Spvar_definition> it(*this);
List_iterator<Item> it_args(*args); List_iterator<Item> it_args(*args);
DBUG_ASSERT(field_def_lst.elements >= args->elements ); DBUG_ASSERT(elements >= args->elements );
Spvar_definition *def; Spvar_definition *def;
Item *arg; Item *arg;
while ((def= it++) && (arg= it_args++)) 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(). This method implementation is very close to fill_schema_table_by_open().
*/ */
bool sp_rcontext::resolve_type_ref(THD *thd, Column_definition *def, bool Qualified_column_ident::resolve_type_ref(THD *thd, Column_definition *def)
Qualified_column_ident *ref)
{ {
Open_tables_backup open_tables_state_backup; Open_tables_backup open_tables_state_backup;
thd->reset_n_backup_open_tables_state(&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 // Make %TYPE variables see temporary tables that shadow permanent tables
thd->temporary_tables= open_tables_state_backup.temporary_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, TL_READ_NO_INSERT,
MDL_SHARED_READ)) && MDL_SHARED_READ)) &&
!check_table_access(thd, SELECT_ACL, table_list, TRUE, UINT_MAX, FALSE) && !check_table_access(thd, SELECT_ACL, table_list, TRUE, UINT_MAX, FALSE) &&
!open_tables_only_view_structure(thd, table_list, !open_tables_only_view_structure(thd, table_list,
thd->mdl_context.has_locks())) 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, if (!(rc= check_column_grant_for_type_ref(thd, table_list,
ref->m_column.str, m_column.str,
ref->m_column.length))) m_column.length)))
{ {
*def= Column_definition(thd, src, NULL/*No defaults,no constraints*/); *def= Column_definition(thd, src, NULL/*No defaults,no constraints*/);
def->flags&= (uint) ~NOT_NULL_FLAG; def->flags&= (uint) ~NOT_NULL_FLAG;
@@ -206,7 +204,7 @@ bool sp_rcontext::resolve_type_ref(THD *thd, Column_definition *def,
} }
} }
else 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(); lex.unit.cleanup();
@@ -223,9 +221,8 @@ bool sp_rcontext::resolve_type_ref(THD *thd, Column_definition *def,
rec t1%ROWTYPE; rec t1%ROWTYPE;
It opens the table "t1" and copies its structure to %ROWTYPE variable. It opens the table "t1" and copies its structure to %ROWTYPE variable.
*/ */
bool sp_rcontext::resolve_table_rowtype_ref(THD *thd, bool Table_ident::resolve_table_rowtype_ref(THD *thd,
Row_definition_list &defs, Row_definition_list &defs)
Table_ident *ref)
{ {
Open_tables_backup open_tables_state_backup; Open_tables_backup open_tables_state_backup;
thd->reset_n_backup_open_tables_state(&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 // Make %ROWTYPE variables see temporary tables that shadow permanent tables
thd->temporary_tables= open_tables_state_backup.temporary_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, TL_READ_NO_INSERT,
MDL_SHARED_READ)) && MDL_SHARED_READ)) &&
!check_table_access(thd, SELECT_ACL, table_list, TRUE, UINT_MAX, FALSE) && !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; Spvar_definition *def;
while ((def= it++)) while ((def= it++))
{ {
if (def->is_column_type_ref() && 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 true;
} }
return false; return false;
@@ -323,7 +320,7 @@ bool sp_rcontext::init_var_items(THD *thd,
Row_definition_list defs; Row_definition_list defs;
Item_field_row *item= new (thd->mem_root) Item_field_row(thd, field); Item_field_row *item= new (thd->mem_root) Item_field_row(thd, field);
if (!(m_var_items[idx]= item) || 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)) item->row_create_items(thd, &defs))
return true; return true;
} }

View File

@@ -340,15 +340,6 @@ private:
/// @retval true on error. /// @retval true on error.
bool init_var_table(THD *thd, List<Spvar_definition> &defs); 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. /// Create and initialize an Item-adapter (Item_field) for each SP-var field.
/// ///
/// param thd Thread handle. /// param thd Thread handle.

View File

@@ -5496,6 +5496,7 @@ public:
{ {
db= *db_name; 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), :Table_ident(thd, db, table, false),
m_column(*column) m_column(*column)
{ } { }
bool resolve_type_ref(THD *thd, Column_definition *def);
}; };