134
134
static bool add_ref_to_table_cond(Session *session, JoinTable *join_tab);
135
135
static void free_blobs(Field **ptr); /* Rename this method...conflicts with another in global namespace... */
137
Join::Join(Session *session_arg,
138
List<Item> &fields_arg,
139
uint64_t select_options_arg,
140
select_result *result_arg) :
152
sort_and_group(false),
156
no_field_update(false),
158
resume_nested_loop(false),
159
no_const_tables(false),
160
select_distinct(false),
161
group_optimized_away(false),
165
skip_sort_order(false),
169
hidden_group_fields(false),
171
found_const_table_map(0),
178
fetch_limit(HA_POS_ERROR),
179
session(session_arg),
180
fields_list(fields_arg),
185
exec_tmp_table1(NULL),
186
exec_tmp_table2(NULL),
191
having_history(NULL),
192
select_options(select_options_arg),
194
lock(session_arg->lock),
196
all_fields(fields_arg),
200
ref_pointer_array(NULL),
205
ref_pointer_array_size(0),
206
zero_result_cause(NULL),
209
join_tab_reexec(NULL)
211
select_distinct= test(select_options & SELECT_DISTINCT);
212
if (&fields_list != &fields_arg) /* only copy if not same*/
213
fields_list= fields_arg;
214
memset(&keyuse, 0, sizeof(keyuse));
215
tmp_table_param.init();
216
tmp_table_param.end_write_records= HA_POS_ERROR;
217
rollup.setState(Rollup::STATE_NONE);
221
* This method is currently only used when a subselect EXPLAIN is performed.
222
* I pulled out the init() method and have simply reset the values to what
223
* was previously in the init() method. See the note about the hack in
226
void Join::reset(Session *session_arg,
227
List<Item> &fields_arg,
228
uint64_t select_options_arg,
229
select_result *result_arg)
242
sort_and_group= false;
246
no_field_update= false;
248
resume_nested_loop= false;
249
no_const_tables= false;
250
select_distinct= false;
251
group_optimized_away= false;
255
skip_sort_order= false;
259
hidden_group_fields= false;
261
found_const_table_map= 0;
268
fetch_limit= HA_POS_ERROR;
269
session= session_arg;
270
fields_list= fields_arg;
275
exec_tmp_table1= NULL;
276
exec_tmp_table2= NULL;
281
having_history= NULL;
282
select_options= select_options_arg;
284
lock= session_arg->lock;
286
all_fields= fields_arg;
290
ref_pointer_array= NULL;
295
ref_pointer_array_size= 0;
296
zero_result_cause= NULL;
299
join_tab_reexec= NULL;
300
select_distinct= test(select_options & SELECT_DISTINCT);
301
if (&fields_list != &fields_arg) /* only copy if not same*/
302
fields_list= fields_arg;
303
memset(&keyuse, 0, sizeof(keyuse));
304
tmp_table_param.init();
305
tmp_table_param.end_write_records= HA_POS_ERROR;
306
rollup.setState(Rollup::STATE_NONE);
309
bool Join::is_top_level_join() const
311
return (unit == &session->lex->unit && (unit->fake_select_lex == 0 ||
312
select_lex == unit->fake_select_lex));
316
138
Prepare of whole select (including sub queries in future).
4976
4792
current_map, 0)))
4978
4794
tab->cache.select= (optimizer::SqlSelect*)
4979
session->getMemRoot()->duplicate((unsigned char*) sel, sizeof(optimizer::SqlSelect));
4795
session->memdup((unsigned char*) sel, sizeof(optimizer::SqlSelect));
4980
4796
tab->cache.select->cond= tmp;
4981
4797
tab->cache.select->read_tables= join->const_table_map;
5704
5520
table_count= join->tables;
5705
5521
stat= (JoinTable*) join->session->calloc(sizeof(JoinTable)*table_count);
5706
stat_ref= (JoinTable**) join->session->getMemRoot()->allocate(sizeof(JoinTable*)*MAX_TABLES);
5707
table_vector= (Table**) join->session->getMemRoot()->allocate(sizeof(Table*)*(table_count*2));
5522
stat_ref= (JoinTable**) join->session->alloc(sizeof(JoinTable*)*MAX_TABLES);
5523
table_vector= (Table**) join->session->alloc(sizeof(Table*)*(table_count*2));
5708
5524
if (! stat || ! stat_ref || ! table_vector)
5768
5584
s->embedding_map.reset();
5771
NestedJoin *nested_join= embedding->getNestedJoin();
5587
nested_join_st *nested_join= embedding->getNestedJoin();
5772
5588
s->embedding_map|= nested_join->nj_map;
5773
5589
s->dependent|= embedding->getDepTables();
5774
5590
embedding= embedding->getEmbedding();
5926
5742
join->const_table_map|=table->map;
5927
5743
set_position(join, const_count++, s, (optimizer::KeyUse*) 0);
5928
5744
partial_pos= join->getSpecificPosInPartialPlan(const_count - 1);
5929
if ((tmp= s->joinReadConstTable(partial_pos)))
5745
if ((tmp= join_read_const_table(s, partial_pos)))
5932
5748
return 1; // Fatal error
5978
5794
if (create_ref_for_key(join, s, start_keyuse, found_const_table_map))
5980
5796
partial_pos= join->getSpecificPosInPartialPlan(const_count - 1);
5981
if ((tmp=s->joinReadConstTable(partial_pos)))
5797
if ((tmp=join_read_const_table(s, partial_pos)))
5984
5800
return 1; // Fatal error