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
00035 class Join;
00036 class RorIntersectReadPlan;
00037 typedef class Item COND;
00038
00039 namespace internal
00040 {
00041 typedef struct st_io_cache IO_CACHE;
00042 }
00043
00044 typedef struct st_key_part
00045 {
00046 uint16_t key;
00047 uint16_t part;
00048
00049 uint16_t store_length;
00050 uint16_t length;
00051 uint8_t null_bit;
00056 uint8_t flag;
00057 Field *field;
00058 } KEY_PART;
00059
00060
00061 namespace optimizer
00062 {
00063
00064 class Parameter;
00065 class SEL_ARG;
00066
00109 class QuickSelectInterface
00110 {
00111 public:
00112 bool sorted;
00113 ha_rows records;
00114 double read_time;
00115 Table *head;
00120 uint32_t index;
00125 uint32_t max_used_key_length;
00133 uint32_t used_key_parts;
00138 unsigned char *last_rowid;
00139
00143 unsigned char *record;
00144
00145 QuickSelectInterface();
00146 virtual ~QuickSelectInterface(){};
00147
00166 virtual int init() = 0;
00167
00185 virtual int reset(void) = 0;
00187 virtual int get_next() = 0;
00188
00190 virtual void range_end() {}
00191
00192 virtual bool reverse_sorted() const = 0;
00193
00194 virtual bool unique_key_range() const
00195 {
00196 return false;
00197 }
00198
00199 enum
00200 {
00201 QS_TYPE_RANGE= 0,
00202 QS_TYPE_INDEX_MERGE= 1,
00203 QS_TYPE_RANGE_DESC= 2,
00204 QS_TYPE_ROR_INTERSECT= 4,
00205 QS_TYPE_ROR_UNION= 5,
00206 QS_TYPE_GROUP_MIN_MAX= 6
00207 };
00208
00210 virtual int get_type() const = 0;
00211
00226 virtual int init_ror_merged_scan(bool)
00227 {
00228 assert(0);
00229 return 1;
00230 }
00231
00235 virtual void save_last_pos(){};
00236
00243 virtual void add_keys_and_lengths(std::string *key_names,
00244 std::string *used_lengths)=0;
00245
00255 virtual void add_info_string(std::string *)
00256 {}
00257
00262 virtual bool is_keys_used(const boost::dynamic_bitset<>& fields);
00263 };
00264
00265 struct st_qsel_param;
00266 class QuickRange;
00267 class QuickRangeSelect;
00268
00273 typedef struct st_quick_range_seq_ctx
00274 {
00275 QuickRange **first;
00276 QuickRange **cur;
00277 QuickRange **last;
00278 } QuickRangeSequenceContext;
00279
00280 range_seq_t quick_range_seq_init(void *init_param, uint32_t n_ranges, uint32_t flags);
00281
00282 uint32_t quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
00283
00292 class SqlSelect : public memory::SqlAlloc
00293 {
00294 public:
00295 QuickSelectInterface *quick;
00296 COND *cond;
00297 Table *head;
00298 internal::IO_CACHE *file;
00299 ha_rows records;
00300 double read_time;
00301 key_map quick_keys;
00302 key_map needed_reg;
00303 table_map const_tables;
00304 table_map read_tables;
00305 bool free_cond;
00306
00307 SqlSelect();
00308 ~SqlSelect();
00309 void cleanup();
00310 bool check_quick(Session *session, bool force_quick_range, ha_rows limit);
00311 bool skip_record();
00312 int test_quick_select(Session *session, key_map keys, table_map prev_tables,
00313 ha_rows limit, bool force_quick_range,
00314 bool ordered_output);
00315 };
00316
00317 QuickRangeSelect *get_quick_select_for_ref(Session *session,
00318 Table *table,
00319 table_reference_st *ref,
00320 ha_rows records);
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 QuickRangeSelect *get_quick_select(Parameter *param,
00345 uint32_t index,
00346 SEL_ARG *key_tree,
00347 uint32_t mrr_flags,
00348 uint32_t mrr_buf_size,
00349 memory::Root *alloc);
00350
00351 uint32_t get_index_for_order(Table *table, Order *order, ha_rows limit);
00352
00353 SqlSelect *make_select(Table *head,
00354 table_map const_tables,
00355 table_map read_tables,
00356 COND *conds,
00357 bool allow_null_cond,
00358 int *error);
00359
00360 bool get_quick_keys(Parameter *param,
00361 QuickRangeSelect *quick,
00362 KEY_PART *key,
00363 SEL_ARG *key_tree,
00364 unsigned char *min_key,
00365 uint32_t min_key_flag,
00366 unsigned char *max_key,
00367 uint32_t max_key_flag);
00368
00369 }
00370
00371 }
00372