12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
210
210
// did we changed top item of WHERE condition
211
211
if (unit->outer_select()->where == (*ref))
213
unit->outer_select()->where= substitution; // correct WHERE for PS
212
unit->outer_select()->where= substitution; // correct WHERE for PS
215
213
else if (unit->outer_select()->having == (*ref))
217
unit->outer_select()->having= substitution; // correct HAVING for PS
214
unit->outer_select()->having= substitution; // correct HAVING for PS
220
216
(*ref)= substitution;
221
217
substitution->name= name;
222
218
if (have_to_be_excluded)
227
session->setWhere("checking transformed subquery");
230
ret= (*ref)->fix_fields(session, ref);
232
session->setWhere(save_where);
221
session->where= "checking transformed subquery";
223
ret= (*ref)->fix_fields(session, ref);
224
session->where= save_where;
236
227
// Is it one field subselect?
247
if (engine->uncacheable())
238
if ((uncacheable= engine->uncacheable()))
249
const_item_cache= false;
250
if (engine->uncacheable(UNCACHEABLE_RAND))
241
if (uncacheable & UNCACHEABLE_RAND)
252
242
used_tables_cache|= RAND_TABLE_BIT;
258
session->setWhere(save_where);
247
session->where= save_where;
283
272
if (item->walk(processor, walk_subquery, argument))
286
for (order= (Order*) lex->order_list.first ; order; order= order->next)
275
for (order= (order_st*) lex->order_list.first ; order; order= order->next)
288
277
if ((*order->item)->walk(processor, walk_subquery, argument))
291
for (order= (Order*) lex->group_list.first ; order; order= order->next)
280
for (order= (order_st*) lex->group_list.first ; order; order= order->next)
293
282
if ((*order->item)->walk(processor, walk_subquery, argument))
393
382
void Item_subselect::update_used_tables()
395
if (! engine->uncacheable())
384
if (!engine->uncacheable())
397
386
// did all used tables become static?
398
387
if (!(used_tables_cache & ~engine->upper_select_const_tables()))
399
const_item_cache= true;
831
int2_class_decimal(E_DEC_FATAL_ERROR, value, 0, decimal_value);
820
int2my_decimal(E_DEC_FATAL_ERROR, value, 0, decimal_value);
832
821
return decimal_value;
949
938
if (was_null && !value)
951
int2_class_decimal(E_DEC_FATAL_ERROR, value, 0, decimal_value);
940
int2my_decimal(E_DEC_FATAL_ERROR, value, 0, decimal_value);
952
941
return decimal_value;
1111
1100
(char *)"<no matter>",
1112
1101
(char *)in_left_expr_name);
1114
master_unit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1103
master_unit->uncacheable|= UNCACHEABLE_DEPENDENT;
1117
1106
if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards)
1119
if (!(pushed_cond_guards= (bool*)join->session->getMemRoot()->allocate(sizeof(bool))))
1108
if (!(pushed_cond_guards= (bool*)join->session->alloc(sizeof(bool))))
1120
1109
return(RES_ERROR);
1121
1110
pushed_cond_guards[0]= true;
1175
1164
Select_Lex *select_lex= join->select_lex;
1177
select_lex->uncacheable.set(UNCACHEABLE_DEPENDENT);
1166
select_lex->uncacheable|= UNCACHEABLE_DEPENDENT;
1178
1167
if (join->having || select_lex->with_sum_func ||
1179
1168
select_lex->group_list.elements)
1380
1369
optimizer->keep_top_level_cache();
1382
1371
session->lex->current_select= current;
1383
master_unit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1372
master_unit->uncacheable|= UNCACHEABLE_DEPENDENT;
1385
1374
if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards)
1387
if (!(pushed_cond_guards= (bool*)join->session->getMemRoot()->allocate(sizeof(bool) *
1376
if (!(pushed_cond_guards= (bool*)join->session->alloc(sizeof(bool) *
1388
1377
left_expr->cols())))
1389
1378
return(RES_ERROR);
1390
1379
for (uint32_t i= 0; i < cols_num; i++)
1652
1641
Item_in_subselect::select_in_like_transformer(Join *join, const Comp_creator *func)
1654
1643
Select_Lex *current= session->lex->current_select, *up;
1655
const char *save_where= session->where();
1644
const char *save_where= session->where;
1656
1645
Item_subselect::trans_res res= RES_ERROR;
2041
2030
select_lex->where,
2042
2031
select_lex->order_list.elements +
2043
2032
select_lex->group_list.elements,
2044
(Order*) select_lex->order_list.first,
2045
(Order*) select_lex->group_list.first,
2033
(order_st*) select_lex->order_list.first,
2034
(order_st*) select_lex->group_list.first,
2046
2035
select_lex->having,
2047
2036
select_lex, select_lex->master_unit()))
2134
int init_read_record_seq(JoinTable *tab);
2135
int join_read_always_key_or_null(JoinTable *tab);
2136
int join_read_next_same_or_null(ReadRecord *info);
2145
2138
int subselect_single_select_engine::exec()
2147
char const *save_where= session->where();
2140
char const *save_where= session->where;
2148
2141
Select_Lex *save_select= session->lex->current_select;
2149
2142
session->lex->current_select= select_lex;
2150
2143
if (!join->optimized)
2154
2147
unit->set_limit(unit->global_parameters);
2155
2148
if (join->optimize())
2157
session->setWhere(save_where);
2150
session->where= save_where;
2159
2152
session->lex->current_select= save_select;
2160
2153
return(join->error ? join->error : 1);
2162
if (save_join_if_explain())
2155
if (!select_lex->uncacheable && session->lex->describe &&
2156
!(join->select_options & SELECT_DESCRIBE) &&
2157
join->need_tmp && item->const_item())
2160
Force join->join_tmp creation, because this subquery will be replaced
2161
by a simple select from the materialization temp table by optimize()
2162
called by EXPLAIN and we need to preserve the initial query structure
2163
so we can display it.
2165
select_lex->uncacheable|= UNCACHEABLE_EXPLAIN;
2166
select_lex->master_unit()->uncacheable|= UNCACHEABLE_EXPLAIN;
2167
if (join->init_save_join_tab())
2165
2170
if (item->engine_changed)
2170
if (select_lex->uncacheable.any() &&
2171
! select_lex->uncacheable.test(UNCACHEABLE_EXPLAIN) &&
2175
if (select_lex->uncacheable &&
2176
select_lex->uncacheable != UNCACHEABLE_EXPLAIN
2174
2179
if (join->reinit())
2176
session->setWhere(save_where);
2181
session->where= save_where;
2177
2182
session->lex->current_select= save_select;
2181
2186
item->assigned((executed= 0));
2232
2237
tab->read_record.read_record= tab->save_read_record;
2235
session->setWhere(save_where);
2240
session->where= save_where;
2236
2241
session->lex->current_select= save_select;
2237
2242
return(join->error||session->is_fatal_error);
2239
session->setWhere(save_where);
2244
session->where= save_where;
2240
2245
session->lex->current_select= save_select;
2245
subselect_single_select_engine::save_join_if_explain()
2248
Save this JOIN to join->tmp_join since the original layout will be
2249
replaced when JOIN::exec() calls make_simple_join() if:
2250
1) We are executing an EXPLAIN query
2251
2) An uncacheable flag has not been set for the select_lex. If
2252
set, JOIN::optimize() has already saved the JOIN
2253
3) Call does not come from select_describe()). If it does,
2254
JOIN::exec() will not call make_simple_join() and the JOIN we
2255
plan to save will not be replaced anyway.
2256
4) A temp table is needed. This is what triggers JOIN::exec() to
2257
make a replacement JOIN by calling make_simple_join().
2258
5) The Item_subselect is cacheable
2260
if (session->lex->describe && // 1
2261
select_lex->uncacheable.none() && // 2
2262
!(join->select_options & SELECT_DESCRIBE) && // 3
2263
join->need_tmp && // 4
2264
item->const_item()) // 5
2267
Save this JOIN to join->tmp_join since the original layout will
2268
be replaced when JOIN::exec() calls make_simple_join() due to
2269
need_tmp==TRUE. The original layout is needed so we can describe
2270
the query. No need to do this if uncacheable != 0 since in this
2271
case the JOIN has already been saved during JOIN::optimize()
2273
select_lex->uncacheable.set(UNCACHEABLE_EXPLAIN);
2274
select_lex->master_unit()->uncacheable.set(UNCACHEABLE_EXPLAIN);
2275
if (join->init_save_join_tab())
2282
2249
int subselect_union_engine::exec()
2284
char const *save_where= session->where();
2251
char const *save_where= session->where;
2285
2252
int res= unit->exec();
2286
session->setWhere(save_where);
2253
session->where= save_where;
2315
2281
if (table->cursor->inited)
2316
2282
table->cursor->endIndexScan();
2318
if ((error= table->cursor->startTableScan(1)))
2320
table->print_error(error, MYF(0));
2324
assert(table->getSession());
2284
table->cursor->startTableScan(1);
2325
2285
table->cursor->extra_opt(HA_EXTRA_CACHE,
2326
table->getSession()->variables.read_buff_size);
2286
current_session->variables.read_buff_size);
2327
2287
table->null_row= 0;
2498
2458
return(scan_table());
2500
2460
if (!table->cursor->inited)
2502
error= table->cursor->startIndexScan(tab->ref.key, 0);
2506
error= table->report_error(error);
2507
return (error != 0);
2461
table->cursor->startIndexScan(tab->ref.key, 0);
2511
2462
error= table->cursor->index_read_map(table->record[0],
2512
2463
tab->ref.key_buff,
2513
2464
make_prev_keypart_map(tab->ref.key_parts),
2620
2571
return(scan_table());
2622
2573
if (!table->cursor->inited)
2624
error= table->cursor->startIndexScan(tab->ref.key, 1);
2628
error= table->report_error(error);
2574
table->cursor->startIndexScan(tab->ref.key, 1);
2632
2575
error= table->cursor->index_read_map(table->record[0],
2633
2576
tab->ref.key_buff,
2634
2577
make_prev_keypart_map(tab->ref.key_parts),
2693
bool subselect_single_select_engine::uncacheable()
2695
return select_lex->uncacheable.any();
2699
bool subselect_single_select_engine::uncacheable(uint32_t bit_pos)
2701
return select_lex->uncacheable.test(bit_pos);
2705
bool subselect_union_engine::uncacheable()
2707
return unit->uncacheable.any();
2711
bool subselect_union_engine::uncacheable(uint32_t bit_pos)
2713
return unit->uncacheable.test(bit_pos);
2636
uint8_t subselect_single_select_engine::uncacheable()
2638
return select_lex->uncacheable;
2642
uint8_t subselect_union_engine::uncacheable()
2644
return unit->uncacheable;
3068
2999
- here we initialize only those members that are used by
3069
3000
subselect_uniquesubquery_engine, so these objects are incomplete.
3071
if (!(tab= (JoinTable*) session->getMemRoot()->allocate(sizeof(JoinTable))))
3002
if (!(tab= (JoinTable*) session->alloc(sizeof(JoinTable))))
3073
new (tab) JoinTable();
3074
3004
tab->table= tmp_table;
3075
3005
tab->ref.key= 0; /* The only temp table index. */
3076
3006
tab->ref.key_length= tmp_key->key_length;
3077
3007
if (!(tab->ref.key_buff=
3078
3008
(unsigned char*) session->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) ||
3079
3009
!(tab->ref.key_copy=
3080
(StoredKey**) session->getMemRoot()->allocate((sizeof(StoredKey*) *
3010
(StoredKey**) session->alloc((sizeof(StoredKey*) *
3081
3011
(tmp_key_parts + 1)))) ||
3082
3012
!(tab->ref.items=
3083
(Item**) session->getMemRoot()->allocate(sizeof(Item*) * tmp_key_parts)))
3013
(Item**) session->alloc(sizeof(Item*) * tmp_key_parts)))
3086
3016
KeyPartInfo *cur_key_part= tmp_key->key_part;
3185
3115
session->lex->current_select= materialize_engine->select_lex;
3186
3116
if ((res= materialize_join->optimize()))
3189
if (materialize_engine->save_join_if_explain())
3192
3118
materialize_join->exec();
3193
3119
if ((res= test(materialize_join->error || session->is_fatal_error)))