3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; either version 2 of the License, or
6
(at your option) any later version.
5
the Free Software Foundation; version 2 of the License.
8
7
This program is distributed in the hope that it will be useful,
9
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
97
96
bool fix_fields(THD *thd, Item **ref);
98
virtual bool exec(bool full_scan);
99
98
virtual void fix_length_and_dec();
100
99
table_map used_tables() const;
101
100
table_map not_null_tables() const { return 0; }
250
250
bool transformed;
252
252
/* Used to trigger on/off conditions that were pushed down to subselect */
253
bool enable_pushed_conds;
253
bool *pushed_cond_guards;
255
bool *get_cond_guard(int i)
257
return pushed_cond_guards ? pushed_cond_guards + i : NULL;
259
void set_cond_guard_var(int i, bool v) { pushed_cond_guards[i]= v; }
260
bool have_guarded_conds() { return test(pushed_cond_guards); }
254
262
Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery
256
264
Item_in_subselect(Item * left_expr, st_select_lex *select_lex);
257
265
Item_in_subselect()
258
266
:Item_exists_subselect(), optimizer(0), abort_on_null(0), transformed(0),
259
enable_pushed_conds(TRUE), upper_item(0)
267
pushed_cond_guards(NULL), upper_item(0)
262
270
subs_type substype() { return IN_SUBS; }
344
full_scan TRUE - Pushed-down predicates are disabled, the engine
345
must disable made based on those predicates.
346
FALSE - Pushed-down predicates are in effect.
348
354
Execute the engine. The result of execution is subquery value that is
349
355
either captured by previously set up select_result-based 'sink' or
350
356
stored somewhere by the exec() method itself.
352
A required side effect: if full_scan==TRUE, subselect_engine->no_rows()
353
should return correct result.
358
A required side effect: If at least one pushed-down predicate is
359
disabled, subselect_engine->no_rows() must return correct result after
357
1 - Either an execution error, or the engine was be "changed", and
364
1 - Either an execution error, or the engine was "changed", and the
358
365
caller should call exec() again for the new engine.
360
virtual int exec(bool full_scan)= 0;
367
virtual int exec()= 0;
361
368
virtual uint cols()= 0; /* return number of columns in select */
362
369
virtual uint8 uncacheable()= 0; /* query is uncacheable */
363
370
enum Item_result type() { return res_type; }
364
371
enum_field_types field_type() { return res_field_type; }
365
372
virtual void exclude()= 0;
366
bool may_be_null() { return maybe_null; };
373
virtual bool may_be_null() { return maybe_null; };
367
374
virtual table_map upper_select_const_tables()= 0;
368
375
static table_map calc_const_tables(TABLE_LIST *);
369
376
virtual void print(String *str)= 0;
431
439
struct st_join_table;
443
A subquery execution engine that evaluates the subquery by doing one index
444
lookup in a unique index.
446
This engine is used to resolve subqueries in forms
448
outer_expr IN (SELECT tbl.unique_key FROM tbl WHERE subq_where)
452
(oe1, .. oeN) IN (SELECT uniq_key_part1, ... uniq_key_partK
453
FROM tbl WHERE subqwhere)
455
i.e. the subquery is a single table SELECT without GROUP BY, aggregate
432
459
class subselect_uniquesubquery_engine: public subselect_engine
435
462
st_join_table *tab;
463
Item *cond; /* The WHERE condition of subselect */
438
465
TRUE<=> last execution produced empty set. Valid only when left
439
466
expression is NULL.
472
499
/* FALSE for 'ref', TRUE for 'ref-or-null'. */
502
The "having" clause. This clause (further reffered to as "artificial
503
having") was inserted by subquery transformation code. It contains
504
Item(s) that have a side-effect: they record whether the subquery has
505
produced a row with NULL certain components. We need to use it for cases
507
(oe1, oe2) IN (SELECT t.key, t.no_key FROM t1)
508
where we do index lookup on t.key=oe1 but need also to check if there
509
was a row such that t.no_key IS NULL.
511
NOTE: This is currently here and not in the uniquesubquery_engine. Ideally
512
it should have been in uniquesubquery_engine in order to allow execution of
515
(oe1, oe2) IN (SELECT primary_key, non_key_maybe_null_field FROM tbl)
517
We could use uniquesubquery_engine for the first component and let
518
Item_is_not_null_test( non_key_maybe_null_field) to handle the second.
520
However, subqueries like the above are currently not handled by index
521
lookup-based subquery engines, the engine applicability check misses
522
them: it doesn't switch the engine for case of artificial having and
523
[eq_]ref access (only for artifical having + ref_or_null or no having).
524
The above example subquery is handled as a full-blown SELECT with eq_ref
527
Due to this limitation, the "artificial having" currently needs to be
528
checked by only in indexsubquery_engine.
476
533
// constructor can assign THD because it will be called after JOIN::prepare
477
534
subselect_indexsubquery_engine(THD *thd, st_join_table *tab_arg,
478
535
Item_subselect *subs, Item *where,
536
Item *having_arg, bool chk_null)
480
537
:subselect_uniquesubquery_engine(thd, tab_arg, subs, where),
538
check_null(chk_null),
483
int exec(bool full_scan);
484
542
void print (String *str);