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