00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #pragma once
00023
00024 #include <drizzled/field.h>
00025 #include <drizzled/item/sum.h>
00026 #include <drizzled/table_reference.h>
00027
00028 #include <queue>
00029
00030 #include <boost/dynamic_bitset.hpp>
00031
00032 namespace drizzled {
00033
00034 typedef struct st_key_part
00035 {
00036 uint16_t key;
00037 uint16_t part;
00038
00039 uint16_t store_length;
00040 uint16_t length;
00041 uint8_t null_bit;
00046 uint8_t flag;
00047 Field *field;
00048 } KEY_PART;
00049
00050
00051 namespace optimizer {
00052
00095 class QuickSelectInterface
00096 {
00097 public:
00098 bool sorted;
00099 ha_rows records;
00100 double read_time;
00101 Table *head;
00106 uint32_t index;
00111 uint32_t max_used_key_length;
00119 uint32_t used_key_parts;
00124 unsigned char *last_rowid;
00125
00129 unsigned char *record;
00130
00131 QuickSelectInterface();
00132 virtual ~QuickSelectInterface(){};
00133
00152 virtual int init() = 0;
00153
00171 virtual int reset(void) = 0;
00173 virtual int get_next() = 0;
00174
00176 virtual void range_end() {}
00177
00178 virtual bool reverse_sorted() const = 0;
00179
00180 virtual bool unique_key_range() const
00181 {
00182 return false;
00183 }
00184
00185 enum
00186 {
00187 QS_TYPE_RANGE= 0,
00188 QS_TYPE_INDEX_MERGE= 1,
00189 QS_TYPE_RANGE_DESC= 2,
00190 QS_TYPE_ROR_INTERSECT= 4,
00191 QS_TYPE_ROR_UNION= 5,
00192 QS_TYPE_GROUP_MIN_MAX= 6
00193 };
00194
00196 virtual int get_type() const = 0;
00197
00212 virtual int init_ror_merged_scan(bool)
00213 {
00214 assert(0);
00215 return 1;
00216 }
00217
00221 virtual void save_last_pos(){};
00222
00229 virtual void add_keys_and_lengths(std::string *key_names,
00230 std::string *used_lengths)=0;
00231
00241 virtual void add_info_string(std::string *)
00242 {}
00243
00248 virtual bool is_keys_used(const boost::dynamic_bitset<>& fields);
00249 };
00250
00255 typedef struct st_quick_range_seq_ctx
00256 {
00257 QuickRange **first;
00258 QuickRange **cur;
00259 QuickRange **last;
00260 } QuickRangeSequenceContext;
00261
00262 range_seq_t quick_range_seq_init(void *init_param, uint32_t n_ranges, uint32_t flags);
00263
00264 uint32_t quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
00265
00274 class SqlSelect : public memory::SqlAlloc
00275 {
00276 public:
00277 QuickSelectInterface *quick;
00278 COND *cond;
00279 Table *head;
00280 internal::io_cache_st *file;
00281 ha_rows records;
00282 double read_time;
00283 key_map quick_keys;
00284 key_map needed_reg;
00285 table_map const_tables;
00286 table_map read_tables;
00287 bool free_cond;
00288
00289 SqlSelect();
00290 ~SqlSelect();
00291 void cleanup();
00292 bool check_quick(Session *session, bool force_quick_range, ha_rows limit);
00293 bool skip_record();
00294 int test_quick_select(Session *session, key_map keys, table_map prev_tables,
00295 ha_rows limit, bool force_quick_range,
00296 bool ordered_output);
00297 };
00298
00299 QuickRangeSelect *get_quick_select_for_ref(Session *session,
00300 Table *table,
00301 table_reference_st *ref,
00302 ha_rows records);
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 QuickRangeSelect *get_quick_select(Parameter *param,
00327 uint32_t index,
00328 SEL_ARG *key_tree,
00329 uint32_t mrr_flags,
00330 uint32_t mrr_buf_size,
00331 memory::Root *alloc);
00332
00333 uint32_t get_index_for_order(Table *table, Order *order, ha_rows limit);
00334
00335 SqlSelect *make_select(Table *head,
00336 table_map const_tables,
00337 table_map read_tables,
00338 COND *conds,
00339 bool allow_null_cond,
00340 int *error);
00341
00342 bool get_quick_keys(Parameter *param,
00343 QuickRangeSelect *quick,
00344 KEY_PART *key,
00345 SEL_ARG *key_tree,
00346 unsigned char *min_key,
00347 uint32_t min_key_flag,
00348 unsigned char *max_key,
00349 uint32_t max_key_flag);
00350
00351 }
00352
00353 }
00354