My Project
Query Resolver


bool subquery_allows_materialization (Item_in_subselect *predicate, THD *thd, SELECT_LEX *select_lex, const SELECT_LEX *outer)
bool fix_inner_refs (THD *thd, List< Item > &all_fields, SELECT_LEX *select, Ref_ptr_array ref_pointer_array, ORDER *group_list)
int setup_order (THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables, List< Item > &fields, List< Item > &all_fields, ORDER *order)
int JOIN::prepare (TABLE_LIST *tables, uint wind_num, Item *conds, uint og_num, ORDER *order, ORDER *group, Item *having, SELECT_LEX *select, SELECT_LEX_UNIT *unit)
bool JOIN::rollup_init ()

Function Documentation

bool fix_inner_refs ( THD *  thd,
List< Item > &  all_fields,
SELECT_LEX *  select,
Ref_ptr_array  ref_pointer_array,
ORDER group_list 

Fix fields referenced from inner selects.

thdThread handle
all_fieldsList of all fields used in select
selectCurrent select
ref_pointer_arrayArray of references to Items used in current select
group_listGROUP BY list (is NULL by default)

The function serves 3 purposes

  • adds fields referenced from inner query blocks to the current select list
  • fixes references (Item_ref objects) to these fields.

If a field isn't already on the select list and the ref_pointer_array is provided then it is added to the all_fields list and the pointer to it is saved in the ref_pointer_array.

The class to access the outer field is determined by the following rules:

-#. If the outer field isn't used under an aggregate function then the Item_ref class should be used.

-#. If the outer field is used under an aggregate function and this function is, in turn, aggregated in the query block where the outer field was resolved or some query nested therein, then the Item_direct_ref class should be used. Also it should be used if we are grouping by a subquery containing the outer field.

The resolution is done here and not at the fix_fields() stage as it can be done only after aggregate functions are fixed and pulled up to selects where they are to be aggregated.

When the class is chosen it substitutes the original field in the Item_outer_ref object.

After this we proceed with fixing references (Item_outer_ref objects) to this field from inner subqueries.

Return values:
trueAn error occured.
int JOIN::prepare ( TABLE_LIST tables_init,
uint  wild_num,
Item conds_init,
uint  og_num,
ORDER order_init,
ORDER group_init,
Item having_init,
SELECT_LEX *  select_lex_arg,
SELECT_LEX_UNIT *  unit_arg 

Prepare of whole select (including sub queries in future).

Add check of calculation of GROUP functions and fields: SELECT COUNT(*)+table.col1 from table1;
Return values:
-1on error
0on success

Allocate memory needed for other rollup functions.

int setup_order ( THD *  thd,
Ref_ptr_array  ref_pointer_array,
TABLE_LIST tables,
List< Item > &  fields,
List< Item > &  all_fields,
ORDER order 

Change order to point at item in select list.

If item isn't a number and doesn't exists in the select list, add it to the the field list.

bool subquery_allows_materialization ( Item_in_subselect predicate,
THD *  thd,
SELECT_LEX *  select_lex,
const SELECT_LEX *  outer 

Check if the subquery predicate can be executed via materialization.

predicateIN subquery predicate
select_lexSELECT_LEX of the subquery
outerParent SELECT_LEX (outer to subquery)
TRUE if subquery allows materialization, FALSE otherwise.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines