27
27
void item_init(void); /* Init item functions */
29
class Name_resolution_context;
31
31
void dummy_error_processor(Session *session, void *data);
33
33
void view_error_processor(Session *session, void *data);
36
Instances of Name_resolution_context store the information necesary for
37
name resolution of Items and other context analysis of a query made in
40
This structure is a part of SELECT_LEX, a pointer to this structure is
41
assigned when an item is created (which happens mostly during parsing
42
(sql_yacc.yy)), but the structure itself will be initialized after parsing
45
TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
46
separate SELECT_LEX which allow to remove tricks of changing this
47
structure before and after INSERT/CREATE and its SELECT to make correct
48
field name resolution.
50
struct Name_resolution_context: Sql_alloc
53
The name resolution context to search in when an Item cannot be
54
resolved in this context (the context of an outer select)
56
Name_resolution_context *outer_context;
59
List of tables used to resolve the items of this context. Usually these
60
are tables from the FROM clause of SELECT statement. The exceptions are
61
INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
62
subquery is not moved to a separate SELECT_LEX. For these types of
63
statements we have to change this member dynamically to ensure correct
64
name resolution of different parts of the statement.
66
TableList *table_list;
68
In most cases the two table references below replace 'table_list' above
69
for the purpose of name resolution. The first and last name resolution
70
table references allow us to search only in a sub-tree of the nested
71
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
74
TableList *first_name_resolution_table;
76
Last table to search in the list of leaf table references that begins
77
with first_name_resolution_table.
79
TableList *last_name_resolution_table;
82
SELECT_LEX item belong to, in case of merged VIEW it can differ from
83
SELECT_LEX where item was created, so we can't use table_list/field_list
86
st_select_lex *select_lex;
89
Processor of errors caused during Item name resolving, now used only to
90
hide underlying tables in errors about views (i.e. it substitute some
93
void (*error_processor)(Session *, void *);
94
void *error_processor_data;
97
When true items are resolved in this context both against the
98
SELECT list and this->table_list. If false, items are resolved
99
only against this->table_list.
101
bool resolve_in_select_list;
104
Security context of this name resolution context. It's used for views
105
and is non-zero only if the view is defined with SQL SECURITY DEFINER.
107
Security_context *security_ctx;
109
Name_resolution_context()
110
:outer_context(0), table_list(0), select_lex(0),
111
error_processor_data(0),
117
resolve_in_select_list= false;
118
error_processor= &dummy_error_processor;
119
first_name_resolution_table= NULL;
120
last_name_resolution_table= NULL;
123
void resolve_in_table_list_only(TableList *tables)
125
table_list= first_name_resolution_table= tables;
126
resolve_in_select_list= false;
129
void process_error(Session *session)
131
(*error_processor)(session, error_processor_data);
137
Store and restore the current state of a name resolution context.
140
class Name_resolution_context_state
143
TableList *save_table_list;
144
TableList *save_first_name_resolution_table;
145
TableList *save_next_name_resolution_table;
146
bool save_resolve_in_select_list;
147
TableList *save_next_local;
150
Name_resolution_context_state() {} /* Remove gcc warning */
153
/* Save the state of a name resolution context. */
154
void save_state(Name_resolution_context *context, TableList *table_list)
156
save_table_list= context->table_list;
157
save_first_name_resolution_table= context->first_name_resolution_table;
158
save_resolve_in_select_list= context->resolve_in_select_list;
159
save_next_local= table_list->next_local;
160
save_next_name_resolution_table= table_list->next_name_resolution_table;
163
/* Restore a name resolution context from saved state. */
164
void restore_state(Name_resolution_context *context, TableList *table_list)
166
table_list->next_local= save_next_local;
167
table_list->next_name_resolution_table= save_next_name_resolution_table;
168
context->table_list= save_table_list;
169
context->first_name_resolution_table= save_first_name_resolution_table;
170
context->resolve_in_select_list= save_resolve_in_select_list;
173
TableList *get_first_name_resolution_table()
175
return save_first_name_resolution_table;
180
37
/*************************************************************************/