~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.h

mergeĀ fromĀ lp

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
20
20
#ifndef DRIZZLED_SQL_SELECT_H
21
21
#define DRIZZLED_SQL_SELECT_H
22
22
 
23
 
#include <drizzled/cached_item.h>
24
 
#include <drizzled/session.h>
25
 
#include <drizzled/field/varstring.h>
26
 
#include <drizzled/item/null.h>
 
23
#include "drizzled/cached_item.h"
 
24
#include "drizzled/session.h"
 
25
#include "drizzled/field/varstring.h"
 
26
#include "drizzled/item/null.h"
27
27
 
28
28
class select_result;
29
29
 
30
30
/**
31
 
  @file
32
 
 
33
 
  @brief
34
 
  classes to use when handling where clause
35
 
*/
 
31
 * @file API and Classes to use when handling where clause
 
32
 */
36
33
 
37
34
/* PREV_BITS only used in sql_select.cc */
38
35
#define PREV_BITS(type,A)       ((type) (((type) 1 << (A)) -1))
44
41
#define KEY_OPTIMIZE_EXISTS             1
45
42
#define KEY_OPTIMIZE_REF_OR_NULL        2
46
43
 
47
 
typedef struct keyuse_t {
48
 
  Table *table;
49
 
  Item  *val;                           /**< or value if no field */
 
44
typedef struct keyuse_t 
 
45
{
 
46
  Table *table; /**< Pointer to the table this key belongs to */
 
47
  Item *val;    /**< or value if no field */
50
48
  table_map used_tables;
51
 
  uint  key, keypart;
52
 
  uint32_t optimize; // 0, or KEY_OPTIMIZE_*
 
49
  uint32_t key;
 
50
  uint32_t keypart;
 
51
  uint32_t optimize; /**< 0, or KEY_OPTIMIZE_* */
53
52
  key_part_map keypart_map;
54
 
  ha_rows      ref_table_rows;
 
53
  ha_rows ref_table_rows;
55
54
  /**
56
55
    If true, the comparison this value was created from will not be
57
56
    satisfied if val has NULL 'value'.
58
57
  */
59
58
  bool null_rejecting;
60
 
  /*
 
59
  /**
61
60
    !NULL - This KEYUSE was created from an equality that was wrapped into
62
61
            an Item_func_trig_cond. This means the equality (and validity of
63
62
            this KEYUSE element) can be turned on and off. The on/off state
68
67
    NULL  - Otherwise (the source equality can't be turned off)
69
68
  */
70
69
  bool *cond_guard;
71
 
  /*
 
70
  /**
72
71
     0..64    <=> This was created from semi-join IN-equality # sj_pred_no.
73
72
     MAX_UINT  Otherwise
74
73
  */
75
 
  uint32_t         sj_pred_no;
 
74
  uint32_t sj_pred_no;
76
75
} KEYUSE;
77
76
 
78
77
class StoredKey;
79
78
 
80
79
typedef struct st_table_ref
81
80
{
82
 
  bool          key_err;
83
 
  uint32_t      key_parts;                ///< num of ...
84
 
  uint32_t      key_length;               ///< length of key_buff
85
 
  int32_t       key;                      ///< key no
86
 
  unsigned char *key_buff;                ///< value to look for with key
87
 
  unsigned char *key_buff2;               ///< key_buff+key_length
88
 
  StoredKey     **key_copy;               //
89
 
  Item          **items;                  ///< val()'s for each keypart
90
 
  /*
 
81
  bool key_err;
 
82
  uint32_t key_parts; /**< num of key parts */
 
83
  uint32_t key_length; /**< length of key_buff */
 
84
  int32_t key; /**< key no (index) */
 
85
  unsigned char *key_buff; /**< value to look for with key */
 
86
  unsigned char *key_buff2; /**< key_buff+key_length */
 
87
  StoredKey **key_copy; /**< No idea what this does... */
 
88
  Item **items; /**< val()'s for each keypart */
 
89
  /**
91
90
    Array of pointers to trigger variables. Some/all of the pointers may be
92
91
    NULL.  The ref access can be used iff
93
92
 
98
97
    access created from such condition is not valid when at least one of the
99
98
    underlying conditions is switched off (see subquery code for more details)
100
99
  */
101
 
  bool          **cond_guards;
 
100
  bool **cond_guards;
102
101
  /**
103
102
    (null_rejecting & (1<<i)) means the condition is '=' and no matching
104
103
    rows will be produced if items[i] IS NULL (see add_not_null_conds())
105
104
  */
106
105
  key_part_map  null_rejecting;
107
 
  table_map     depend_map;               ///< Table depends on these tables.
108
 
  /* null byte position in the key_buf. Used for REF_OR_NULL optimization */
 
106
  table_map     depend_map; /**< Table depends on these tables. */
 
107
  /** null byte position in the key_buf. Used for REF_OR_NULL optimization */
109
108
  unsigned char *null_ref_key;
110
 
 
111
 
  /*
 
109
  /**
112
110
    true <=> disable the "cache" as doing lookup with the same key value may
113
111
    produce different results (because of Index Condition Pushdown)
114
112
  */
115
 
  bool          disable_cache;
 
113
  bool disable_cache;
116
114
} TABLE_REF;
117
115
 
118
116
class JOIN;
148
146
  JT_INDEX_MERGE
149
147
};
150
148
 
151
 
/* Values for JOIN_TAB::packed_info */
152
 
#define TAB_INFO_HAVE_VALUE 1
153
 
#define TAB_INFO_USING_INDEX 2
154
 
#define TAB_INFO_USING_WHERE 4
155
 
#define TAB_INFO_FULL_SCAN_ON_NULL 8
156
 
 
157
149
class SJ_TMP_TABLE;
158
150
 
159
151
typedef enum_nested_loop_state (*Next_select_func)(JOIN *, struct st_join_table *, bool);
168
160
enum_nested_loop_state end_write_group(JOIN *join, JOIN_TAB *join_tab, bool end_of_records);
169
161
 
170
162
/**
171
 
  Information about a position of table within a join order. Used in join
172
 
  optimization.
173
 
*/
 
163
 * Information about a position of table within a join order. Used in join
 
164
 * optimization.
 
165
 */
174
166
typedef struct st_position
175
167
{
176
 
  /*
 
168
  /**
177
169
    The "fanout": number of output rows that will be produced (after
178
170
    pushed down selection condition is applied) per each row combination of
179
171
    previous tables.
180
172
  */
181
173
  double records_read;
182
174
 
183
 
  /*
 
175
  /**
184
176
    Cost accessing the table in course of the entire complete join execution,
185
177
    i.e. cost of one access method use (e.g. 'range' or 'ref' scan ) times
186
178
    number the access method will be invoked.
188
180
  double read_time;
189
181
  JOIN_TAB *table;
190
182
 
191
 
  /*
 
183
  /**
192
184
    NULL  -  'index' or 'range' or 'index_merge' or 'ALL' access is used.
193
185
    Other - [eq_]ref[_or_null] access is used. Pointer to {t.keypart1 = expr}
194
186
  */
195
187
  KEYUSE *key;
196
188
 
197
 
  /* If ref-based access is used: bitmap of tables this table depends on  */
 
189
  /** If ref-based access is used: bitmap of tables this table depends on  */
198
190
  table_map ref_depend_map;
199
191
 
200
192
  bool use_insideout_scan;
229
221
  uint32_t num_values;           /* number of values in the above array      */
230
222
} SARGABLE_PARAM;
231
223
 
232
 
/// Used when finding key fields
233
 
typedef struct key_field_t {
234
 
  Field         *field;
235
 
  Item          *val;                   ///< May be empty if diff constant
236
 
  uint          level;
237
 
  uint          optimize; // KEY_OPTIMIZE_*
238
 
  bool          eq_func;
 
224
/**
 
225
 * Structure used when finding key fields
 
226
 */
 
227
typedef struct key_field_t 
 
228
{
 
229
  Field *field;
 
230
  Item *val; /**< May be empty if diff constant */
 
231
  uint32_t level;
 
232
  uint32_t optimize; /**< KEY_OPTIMIZE_* */
 
233
  bool eq_func;
239
234
  /**
240
235
    If true, the condition this struct represents will not be satisfied
241
236
    when val IS NULL.
242
237
  */
243
 
  bool          null_rejecting;
244
 
  bool          *cond_guard; /* See KEYUSE::cond_guard */
245
 
  uint32_t          sj_pred_no; /* See KEYUSE::sj_pred_no */
 
238
  bool null_rejecting;
 
239
  bool *cond_guard; /**< @see KEYUSE::cond_guard */
 
240
  uint32_t sj_pred_no; /**< @see KEYUSE::sj_pred_no */
246
241
} KEY_FIELD;
247
242
 
248
243
/*****************************************************************************