My Project
Classes | Defines | Typedefs | Enumerations | Functions
sql_select.h File Reference

classes to use when handling where clause More...

#include "procedure.h"
#include <myisam.h>
#include "sql_array.h"
#include "records.h"
#include "opt_range.h"
#include "filesort.h"
#include "mem_root_array.h"
#include "sql_executor.h"
#include "opt_explain_format.h"
#include <functional>

Go to the source code of this file.

Classes

class  Key_use
struct  st_table_ref
struct  st_position
struct  st_join_table
class  Join_tab_compare_default
class  Join_tab_compare_straight
class  Join_tab_compare_embedded_first
struct  st_select_check
class  store_key
class  store_key_field
class  store_key_item
class  store_key_const_item

Defines

#define LOWER_BITS(type, A)   ((type) (((type) 1 << (A)) -1))
#define KEY_OPTIMIZE_EXISTS   1
#define KEY_OPTIMIZE_REF_OR_NULL   2
#define FT_KEYPART   (MAX_REF_PARTS+10)
#define TAB_INFO_HAVE_VALUE   1
#define TAB_INFO_USING_INDEX   2
#define TAB_INFO_USING_WHERE   4
#define TAB_INFO_FULL_SCAN_ON_NULL   8
#define SJ_OPT_NONE   0
#define SJ_OPT_DUPS_WEEDOUT   1
#define SJ_OPT_LOOSE_SCAN   2
#define SJ_OPT_FIRST_MATCH   3
#define SJ_OPT_MATERIALIZE_LOOKUP   4
#define SJ_OPT_MATERIALIZE_SCAN   5

Typedefs

typedef Mem_root_array
< Key_use, true > 
Key_use_array
typedef st_table_ref TABLE_REF
typedef st_position POSITION
typedef st_join_table JOIN_TAB
typedef Bounds_checked_array
< Item_null_result * > 
Item_null_array
typedef struct st_select_check SELECT_CHECK

Enumerations

enum  join_type {
  JT_UNKNOWN, JT_SYSTEM, JT_CONST, JT_EQ_REF,
  JT_REF, JT_ALL, JT_RANGE, JT_INDEX_SCAN,
  JT_FT, JT_REF_OR_NULL, JT_UNIQUE_SUBQUERY, JT_INDEX_SUBQUERY,
  JT_INDEX_MERGE
}
enum  quick_type { QS_NONE, QS_RANGE, QS_DYNAMIC_RANGE }

Functions

bool sj_is_materialize_strategy (uint strategy)
void count_field_types (SELECT_LEX *select_lex, TMP_TABLE_PARAM *param, List< Item > &fields, bool reset_with_sum_func)
uint find_shortest_key (TABLE *table, const key_map *usable_keys)
bool simple_pred (Item_func *func_item, Item **args, bool *inv_order)
int opt_sum_query (THD *thd, TABLE_LIST *tables, List< Item > &all_fields, Item *conds)
int refpos_order_cmp (const void *arg, const void *a, const void *b)
bool error_if_full_join (JOIN *join)
bool handle_select (THD *thd, select_result *result, ulong setup_tables_done_option)
bool mysql_select (THD *thd, TABLE_LIST *tables, uint wild_num, List< Item > &list, Item *conds, SQL_I_List< ORDER > *order, SQL_I_List< ORDER > *group, Item *having, ulonglong select_type, select_result *result, SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
void free_underlaid_joins (THD *thd, SELECT_LEX *select)
void calc_used_field_length (THD *thd, JOIN_TAB *join_tab)
bool optimizer_flag (THD *thd, uint flag)
uint get_index_for_order (ORDER *order, TABLE *table, SQL_SELECT *select, ha_rows limit, bool *need_sort, bool *reverse)
ORDERsimple_remove_const (ORDER *order, Item *where)
bool const_expression_in_where (Item *cond, Item *comp_item, Field *comp_field=NULL, Item **const_item=NULL)
bool test_if_subpart (ORDER *a, ORDER *b)
void calc_group_buffer (JOIN *join, ORDER *group)
bool test_if_skip_sort_order (JOIN_TAB *tab, ORDER *order, ha_rows select_limit, const bool no_changes, const key_map *map, const char *clause_type)
bool make_join_readinfo (JOIN *join, ulonglong options, uint no_jbuf_after)
bool create_ref_for_key (JOIN *join, JOIN_TAB *j, Key_use *org_keyuse, table_map used_tables)
bool types_allow_materialization (Item *outer, Item *inner)
 Check if two items are compatible wrt. materialization.
bool and_conditions (Item **e1, Item *e2)
uint actual_key_parts (KEY *key_info)
uint actual_key_flags (KEY *key_info)
int test_if_order_by_key (ORDER *order, TABLE *table, uint idx, uint *used_key_parts=NULL)

Detailed Description

classes to use when handling where clause


Define Documentation

#define LOWER_BITS (   type,
 
)    ((type) (((type) 1 << (A)) -1))

Returns a constant of type 'type' with the 'A' lowest-weight bits set. Example: LOWER_BITS(uint, 3) == 7. Requirement: A < sizeof(type) * 8.


Typedef Documentation

A position of table within a join order. This structure is primarily used as a part of join->positions and join->best_positions arrays.

One POSITION element contains information about:

  • Which table is accessed
  • Which access method was chosen = Its cost and #of output records
  • Semi-join strategy choice. Note that there are two different representation formats: 1. The one used during join optimization 2. The one used at plan refinement/code generation stage. We call fix_semijoin_strategies_for_picked_join_order() to switch between #1 and #2. See that function's comment for more details.
  • Semi-join optimization state. When we're running join optimization, we main a state for every semi-join strategy which are various variables that tell us if/at which point we could consider applying the strategy. The variables are really a function of join prefix but they are too expensive to re-caclulate for every join prefix we consider, so we maintain current state in join->positions[#tables_in_prefix]. See advance_sj_state() for details.

This class has to stay a POD, because it is memcpy'd in many places.


Enumeration Type Documentation

enum quick_type

Bits describing quick select type


Function Documentation

int opt_sum_query ( THD *  thd,
TABLE_LIST tables,
List< Item > &  all_fields,
Item conds 
)

Substitutes constants for some COUNT(), MIN() and MAX() functions.

Parameters:
thdthread handler
tableslist of leaves of join table tree
all_fieldsAll fields to be returned
condsWHERE clause
Note:
This function is only called for queries with aggregate functions and no GROUP BY part. This means that the result set shall contain a single row only
Return values:
0no errors
1if all items were resolved
HA_ERR_KEY_NOT_FOUNDon impossible conditions
HA_ERR_...if a deadlock or a lock wait timeout happens, for example
ER_...e.g. ER_SUBQUERY_NO_1_ROW
bool simple_pred ( Item_func func_item,
Item **  args,
bool *  inv_order 
)

Test if the predicate compares a field with constants.

Parameters:
func_itemPredicate item
[out]argsHere we store the field followed by constants
[out]inv_orderIs set to 1 if the predicate is of the form 'const op field'
Return values:
0func_item is a simple predicate: a field is compared with constants
1Otherwise
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines