40
40
Item_result_field(), value_assigned(0), thd(0), substitution(0),
41
41
engine(0), old_engine(0), used_tables_cache(0), have_to_be_excluded(0),
42
42
const_item_cache(1), engine_changed(0), changed(0),
414
414
Item_subselect *parent,
415
415
st_select_lex *select_lex,
417
:Item_singlerow_subselect(), was_values(TRUE)
417
:Item_singlerow_subselect(), was_values(true)
419
419
DBUG_ENTER("Item_maxmin_subselect::Item_maxmin_subselect");
445
445
Item_singlerow_subselect::cleanup();
448
By default it is TRUE to avoid TRUE reporting by
448
By default it is true to avoid true reporting by
449
449
Item_func_not_all/Item_func_nop_all if this item was never called.
451
Engine exec() set it to FALSE by reset_value_registration() call.
452
select_max_min_finder_subselect::send_data() set it back to TRUE if some
451
Engine exec() set it to false by reset_value_registration() call.
452
select_max_min_finder_subselect::send_data() set it back to true if some
453
453
value will be found.
456
456
DBUG_VOID_RETURN;
715
715
Item_in_subselect::Item_in_subselect(Item * left_exp,
716
716
st_select_lex *select_lex):
717
Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE),
717
Item_exists_subselect(), left_expr_cache(0), first_execution(true),
718
718
optimizer(0), pushed_cond_guards(NULL), exec_method(NOT_TRANSFORMED),
1120
1120
trigcond(oe $cmp$ ref_or_null_helper<ie>)
1122
1122
the addition is wrapped into trigger only when we want to distinguish
1123
between NULL and FALSE results.
1123
between NULL and false results.
1125
1125
- Otherwise (no aggregates/GROUP BY/HAVING) convert it to one of the
1128
= If we don't need to distinguish between NULL and FALSE subquery:
1128
= If we don't need to distinguish between NULL and false subquery:
1130
1130
SELECT 1 FROM ... WHERE (oe $cmp$ ie) AND subq_where
1237
1237
If we may encounter NULL IN (SELECT ...) and care whether subquery
1238
result is NULL or FALSE, wrap condition in a trig_cond.
1238
result is NULL or false, wrap condition in a trig_cond.
1240
1240
if (!abort_on_null && left_expr->maybe_null)
1762
@retval TRUE memory allocation error occurred
1763
@retval FALSE an execution method was chosen successfully
1762
@retval true memory allocation error occurred
1763
@retval false an execution method was chosen successfully
1766
1766
bool Item_in_subselect::setup_engine()
1768
1768
subselect_hash_sj_engine *new_engine= NULL;
1771
1771
DBUG_ENTER("Item_in_subselect::setup_engine");
1833
1833
but it takes a different kind of collection of items, and the
1834
1834
list we push to is dynamically allocated.
1836
@retval TRUE if a memory allocation error occurred or the cache is
1836
@retval true if a memory allocation error occurred or the cache is
1837
1837
not applicable to the current query
1838
@retval FALSE if success
1838
@retval false if success
1841
1841
bool Item_in_subselect::init_left_expr_cache()
1843
1843
JOIN *outer_join;
1844
1844
Next_select_func end_select;
1845
bool use_result_field= FALSE;
1845
bool use_result_field= false;
1847
1847
outer_join= unit->outer_select()->join;
1848
1848
if (!outer_join || !outer_join->tables)
1851
1851
If we use end_[send | write]_group to handle complete rows of the outer
1852
1852
query, make the cache of the left IN operand use Item_field::result_field
1884
1884
make_cond_for_table() in such a way that it is unchanged when we use
1885
1885
the IN=>EXISTS transformation to compute IN.
1887
@retval TRUE if the predicate is expensive
1888
@retval FALSE otherwise
1887
@retval true if the predicate is expensive
1888
@retval false otherwise
1891
1891
bool Item_in_subselect::is_expensive_processor(uchar *arg)
2289
2289
Scan the table using sequential access until we find at least one row
2290
2290
satisfying select condition.
2292
The caller must set this->empty_result_set=FALSE before calling this
2293
function. This function will set it to TRUE if it finds a matching row.
2292
The caller must set this->empty_result_set=false before calling this
2293
function. This function will set it to true if it finds a matching row.
2300
2300
int subselect_uniquesubquery_engine::scan_table()
2344
2344
Copy ref key and check for null parts in it.
2345
2345
Depending on the nullability and conversion problems this function
2346
2346
recognizes and processes the following states :
2347
1. Partial match on top level. This means IN has a value of FALSE
2347
1. Partial match on top level. This means IN has a value of false
2348
2348
regardless of the data in the subquery table.
2349
2349
Detected by finding a NULL in the left IN operand of a top level
2351
We may actually skip reading the subquery, so return TRUE to skip
2351
We may actually skip reading the subquery, so return true to skip
2352
2352
the table scan in subselect_uniquesubquery_engine::exec and make
2353
the value of the IN predicate a NULL (that is equal to FALSE on
2353
the value of the IN predicate a NULL (that is equal to false on
2355
2355
2. No exact match when IN is nested inside another predicate.
2356
2356
Detected by finding a NULL in the left IN operand when IN is not
2357
2357
a top level predicate.
2358
2358
We cannot have an exact match. But we must proceed further with a
2359
2359
table scan to find out if it's a partial match (and IN has a value
2360
of NULL) or no match (and IN has a value of FALSE).
2361
So we return FALSE to continue with the scan and see if there are
2360
of NULL) or no match (and IN has a value of false).
2361
So we return false to continue with the scan and see if there are
2362
2362
any record that would constitute a partial match (as we cannot
2363
2363
determine that from the index).
2364
2364
3. Error converting the left IN operand to the column type of the
2365
2365
right IN operand. This counts as no match (and IN has the value of
2366
FALSE). We mark the subquery table cursor as having no more rows
2366
false). We mark the subquery table cursor as having no more rows
2367
2367
(to ensure that the processing that follows will not find a match)
2368
and return FALSE, so IN is not treated as returning NULL.
2368
and return false, so IN is not treated as returning NULL.
2372
FALSE - The value of the IN predicate is not known. Proceed to find the
2372
false - The value of the IN predicate is not known. Proceed to find the
2373
2373
value of the IN predicate using the determined values of
2374
2374
null_keypart and table->status.
2375
TRUE - IN predicate has a value of NULL. Stop the processing right there
2375
true - IN predicate has a value of NULL. Stop the processing right there
2376
2376
and return NULL to the outer predicates.
2414
2414
Check if the error is equal to STORE_KEY_FATAL. This is not expressed
2415
2415
using the store_key::store_key_result enum because ref.key_err is a
2416
boolean and we want to detect both TRUE and STORE_KEY_FATAL from the
2417
space of the union of the values of [TRUE, FALSE] and
2416
boolean and we want to detect both true and STORE_KEY_FATAL from the
2417
space of the union of the values of [true, false] and
2418
2418
store_key::store_key_result.
2419
2419
TODO: fix the variable an return types.
2445
2445
This is a special case, we don't need to search for NULL in the table,
2446
2446
instead, the result value is
2447
2447
- NULL if select produces empty row set
2450
In some cases (IN subselect is a top level item, i.e. abort_on_null==TRUE)
2451
the caller doesn't distinguish between NULL and FALSE result and we just
2450
In some cases (IN subselect is a top level item, i.e. abort_on_null==true)
2451
the caller doesn't distinguish between NULL and false result and we just
2453
2453
Otherwise we make a full table scan to see if there is at least one
2528
2528
The value of the predicate is calculated as follows:
2529
2529
1. If oe IS NULL, this is a special case, do a full table scan on
2530
2530
table tbl and search for row that satisfies subq_where. If such
2531
row is found, return NULL, otherwise return FALSE.
2531
row is found, return NULL, otherwise return false.
2532
2532
2. Make an index lookup via key=oe, search for a row that satisfies
2533
subq_where. If found, return TRUE.
2534
3. If check_null==TRUE, make another lookup via key=NULL, search for a
2533
subq_where. If found, return true.
2534
3. If check_null==true, make another lookup via key=NULL, search for a
2535
2535
row that satisfies subq_where. If found, return NULL, otherwise
2539
2539
The step #1 can be optimized further when the index has several key
2554
2554
If this query produces a row, the result is NULL (as we're evaluating
2555
2555
"(const1, NULL) IN { (const1, X), ... }", which has a value of UNKNOWN,
2556
i.e. NULL). If the query produces no rows, the result is FALSE.
2556
i.e. NULL). If the query produces no rows, the result is false.
2558
2558
We currently evaluate (1) by doing a full table scan. (2) can be
2559
2559
evaluated by doing a "ref" scan on "keypart1=const1", which can be much
2877
2877
Report about presence of tables in subquery.
2880
TRUE there are not tables used in subquery
2880
true there are not tables used in subquery
2882
FALSE there are some tables in subquery
2882
false there are some tables in subquery
2884
2884
bool subselect_single_select_engine::no_tables()
2907
2907
Report about presence of tables in subquery.
2910
TRUE there are not tables used in subquery
2910
true there are not tables used in subquery
2912
FALSE there are some tables in subquery
2912
false there are some tables in subquery
2914
2914
bool subselect_union_engine::no_tables()
2916
2916
for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select())
2918
2918
if (sl->table_list.elements)
2926
2926
Report about presence of tables in subquery.
2929
TRUE there are not tables used in subquery
2929
true there are not tables used in subquery
2931
FALSE there are some tables in subquery
2931
false there are some tables in subquery
2934
2934
bool subselect_uniquesubquery_engine::no_tables()
2983
2983
managed (created/filled/etc) internally by the interceptor.
2985
2985
if (!(tmp_result_sink= new select_union))
2987
2987
if (tmp_result_sink->create_result_table(
2988
thd, tmp_columns, TRUE,
2988
thd, tmp_columns, true,
2989
2989
thd->options | TMP_TABLE_ALL_COLUMNS,
2990
"materialized subselect", TRUE))
2990
"materialized subselect", true))
2993
2993
tmp_table= tmp_result_sink->table;
2994
2994
tmp_key= tmp_table->key_info;
3160
3160
immediately after materialization (yet it's done together with
3163
is_materialized= TRUE;
3163
is_materialized= true;
3165
3165
If the subquery returned no rows, the temporary table is empty, so we know
3166
directly that the result of IN is FALSE. We first update the table
3166
directly that the result of IN is false. We first update the table
3167
3167
statistics, then we test if the temporary table for the query result is
3170
3170
tab->table->file->info(HA_STATUS_VARIABLE);
3171
3171
if (!tab->table->file->stats.records)
3173
empty_result_set= TRUE;
3174
item_in->value= FALSE;
3175
/* TODO: check we need this: item_in->null_value= FALSE; */
3173
empty_result_set= true;
3174
item_in->value= false;
3175
/* TODO: check we need this: item_in->null_value= false; */
3178
3178
/* Set tmp_param only if its usable, i.e. tmp_param->copy_field != NULL. */
3179
3179
tmp_param= &(item_in->unit->outer_select()->join->tmp_table_param);