224
223
engine->exclude();
227
session->setWhere("checking transformed subquery");
226
session->where= "checking transformed subquery";
228
227
if (! (*ref)->fixed)
230
229
ret= (*ref)->fix_fields(session, ref);
232
session->setWhere(save_where);
231
session->where= save_where;
236
234
// Is it one field subselect?
831
int2_class_decimal(E_DEC_FATAL_ERROR, value, 0, decimal_value);
829
int2my_decimal(E_DEC_FATAL_ERROR, value, 0, decimal_value);
832
830
return decimal_value;
949
947
if (was_null && !value)
951
int2_class_decimal(E_DEC_FATAL_ERROR, value, 0, decimal_value);
949
int2my_decimal(E_DEC_FATAL_ERROR, value, 0, decimal_value);
952
950
return decimal_value;
1117
1115
if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards)
1119
if (!(pushed_cond_guards= (bool*)join->session->getMemRoot()->allocate(sizeof(bool))))
1117
if (!(pushed_cond_guards= (bool*)join->session->alloc(sizeof(bool))))
1120
1118
return(RES_ERROR);
1121
1119
pushed_cond_guards[0]= true;
1385
1383
if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards)
1387
if (!(pushed_cond_guards= (bool*)join->session->getMemRoot()->allocate(sizeof(bool) *
1385
if (!(pushed_cond_guards= (bool*)join->session->alloc(sizeof(bool) *
1388
1386
left_expr->cols())))
1389
1387
return(RES_ERROR);
1390
1388
for (uint32_t i= 0; i < cols_num; i++)
1652
1650
Item_in_subselect::select_in_like_transformer(Join *join, const Comp_creator *func)
1654
1652
Select_Lex *current= session->lex->current_select, *up;
1655
const char *save_where= session->where();
1653
const char *save_where= session->where;
1656
1654
Item_subselect::trans_res res= RES_ERROR;
2143
int init_read_record_seq(JoinTable *tab);
2144
int join_read_always_key_or_null(JoinTable *tab);
2145
int join_read_next_same_or_null(ReadRecord *info);
2145
2147
int subselect_single_select_engine::exec()
2147
char const *save_where= session->where();
2149
char const *save_where= session->where;
2148
2150
Select_Lex *save_select= session->lex->current_select;
2149
2151
session->lex->current_select= select_lex;
2150
2152
if (!join->optimized)
2154
2156
unit->set_limit(unit->global_parameters);
2155
2157
if (join->optimize())
2157
session->setWhere(save_where);
2159
session->where= save_where;
2159
2161
session->lex->current_select= save_select;
2160
2162
return(join->error ? join->error : 1);
2162
if (save_join_if_explain())
2164
if (select_lex->uncacheable.none() && session->lex->describe &&
2165
!(join->select_options & SELECT_DESCRIBE) &&
2166
join->need_tmp && item->const_item())
2169
Force join->join_tmp creation, because this subquery will be replaced
2170
by a simple select from the materialization temp table by optimize()
2171
called by EXPLAIN and we need to preserve the initial query structure
2172
so we can display it.
2174
select_lex->uncacheable.set(UNCACHEABLE_EXPLAIN);
2175
select_lex->master_unit()->uncacheable.set(UNCACHEABLE_EXPLAIN);
2176
if (join->init_save_join_tab())
2165
2179
if (item->engine_changed)
2232
2246
tab->read_record.read_record= tab->save_read_record;
2235
session->setWhere(save_where);
2249
session->where= save_where;
2236
2250
session->lex->current_select= save_select;
2237
2251
return(join->error||session->is_fatal_error);
2239
session->setWhere(save_where);
2253
session->where= save_where;
2240
2254
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
2258
int subselect_union_engine::exec()
2284
char const *save_where= session->where();
2260
char const *save_where= session->where;
2285
2261
int res= unit->exec();
2286
session->setWhere(save_where);
2262
session->where= save_where;
2315
2290
if (table->cursor->inited)
2316
2291
table->cursor->endIndexScan();
2318
if ((error= table->cursor->startTableScan(1)))
2320
table->print_error(error, MYF(0));
2324
assert(table->getSession());
2293
table->cursor->startTableScan(1);
2325
2294
table->cursor->extra_opt(HA_EXTRA_CACHE,
2326
table->getSession()->variables.read_buff_size);
2295
current_session->variables.read_buff_size);
2327
2296
table->null_row= 0;
2498
2467
return(scan_table());
2500
2469
if (!table->cursor->inited)
2502
error= table->cursor->startIndexScan(tab->ref.key, 0);
2506
error= table->report_error(error);
2507
return (error != 0);
2470
table->cursor->startIndexScan(tab->ref.key, 0);
2511
2471
error= table->cursor->index_read_map(table->record[0],
2512
2472
tab->ref.key_buff,
2513
2473
make_prev_keypart_map(tab->ref.key_parts),
2620
2580
return(scan_table());
2622
2582
if (!table->cursor->inited)
2624
error= table->cursor->startIndexScan(tab->ref.key, 1);
2628
error= table->report_error(error);
2583
table->cursor->startIndexScan(tab->ref.key, 1);
2632
2584
error= table->cursor->index_read_map(table->record[0],
2633
2585
tab->ref.key_buff,
2634
2586
make_prev_keypart_map(tab->ref.key_parts),
3068
3020
- here we initialize only those members that are used by
3069
3021
subselect_uniquesubquery_engine, so these objects are incomplete.
3071
if (!(tab= (JoinTable*) session->getMemRoot()->allocate(sizeof(JoinTable))))
3023
if (!(tab= (JoinTable*) session->alloc(sizeof(JoinTable))))
3073
new (tab) JoinTable();
3074
3025
tab->table= tmp_table;
3075
3026
tab->ref.key= 0; /* The only temp table index. */
3076
3027
tab->ref.key_length= tmp_key->key_length;
3077
3028
if (!(tab->ref.key_buff=
3078
3029
(unsigned char*) session->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) ||
3079
3030
!(tab->ref.key_copy=
3080
(StoredKey**) session->getMemRoot()->allocate((sizeof(StoredKey*) *
3031
(StoredKey**) session->alloc((sizeof(StoredKey*) *
3081
3032
(tmp_key_parts + 1)))) ||
3082
3033
!(tab->ref.items=
3083
(Item**) session->getMemRoot()->allocate(sizeof(Item*) * tmp_key_parts)))
3034
(Item**) session->alloc(sizeof(Item*) * tmp_key_parts)))
3086
3037
KeyPartInfo *cur_key_part= tmp_key->key_part;
3185
3136
session->lex->current_select= materialize_engine->select_lex;
3186
3137
if ((res= materialize_join->optimize()))
3189
if (materialize_engine->save_join_if_explain())
3192
3139
materialize_join->exec();
3193
3140
if ((res= test(materialize_join->error || session->is_fatal_error)))