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
/*************************************************************************/
2201
2049
int save_in_field(Field *field, bool no_conversions);
2204
class Item_cache_row: public Item_cache
2206
Item_cache **values;
2207
uint32_t item_count;
2211
:Item_cache(), values(0), item_count(2), save_array(0) {}
2214
'allocate' used only in row transformer, to preallocate space for row
2217
bool allocate(uint32_t num);
2219
'setup' is needed only by row => it not called by simple row subselect
2220
(only by IN subselect (in subselect optimizer))
2222
bool setup(Item *item);
2223
void store(Item *item);
2224
void illegal_method_call(const char *);
2225
void make_field(Send_field *)
2227
illegal_method_call((const char*)"make_field");
2231
illegal_method_call((const char*)"val");
2236
illegal_method_call((const char*)"val_int");
2239
String *val_str(String *)
2241
illegal_method_call((const char*)"val_str");
2244
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
2246
illegal_method_call((const char*)"val_decimal");
2250
enum Item_result result_type() const { return ROW_RESULT; }
2252
uint32_t cols() { return item_count; }
2253
Item *element_index(uint32_t i) { return values[i]; }
2254
Item **addr(uint32_t i) { return (Item **) (values + i); }
2255
bool check_cols(uint32_t c);
2258
void keep_array() { save_array= 1; }
2261
Item_cache::cleanup();
2263
memset(values, 0, item_count*sizeof(Item**));
2272
Item_type_holder used to store type. name, length of Item for UNIONS &
2275
Item_type_holder do not need cleanup() because its time of live limited by
2276
single SP/PS execution.
2278
class Item_type_holder: public Item
2281
TYPELIB *enum_set_typelib;
2282
enum_field_types fld_type;
2284
void get_full_info(Item *item);
2286
/* It is used to count decimal precision in join_types */
2287
int prev_decimal_int_part;
2289
Item_type_holder(Session*, Item*);
2291
Item_result result_type() const;
2292
enum_field_types field_type() const { return fld_type; };
2293
enum Type type() const { return TYPE_HOLDER; }
2296
my_decimal *val_decimal(my_decimal *);
2297
String *val_str(String*);
2298
bool join_types(Session *session, Item *);
2299
Field *make_field_by_type(Table *table);
2300
static uint32_t display_length(Item *item);
2301
static enum_field_types get_real_type(Item *);
2305
2053
class st_select_lex;
2306
2054
void mark_select_range_as_dependent(Session *session,