00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <drizzled/optimizer/range.h>
00023
00024 #include <vector>
00025
00026 namespace drizzled
00027 {
00028
00029 namespace optimizer
00030 {
00031
00064 class QuickGroupMinMaxSelect : public QuickSelectInterface
00065 {
00066
00067 private:
00068
00069 Cursor *cursor;
00070 Join *join;
00071 KeyInfo *index_info;
00072 unsigned char *record;
00073 unsigned char *tmp_record;
00074 unsigned char *group_prefix;
00075 uint32_t group_prefix_len;
00076 uint32_t group_key_parts;
00077 unsigned char *last_prefix;
00078 bool have_min;
00079 bool have_max;
00080 bool seen_first_key;
00081 KeyPartInfo *min_max_arg_part;
00082 uint32_t min_max_arg_len;
00083 unsigned char *key_infix;
00084 uint32_t key_infix_len;
00085 std::vector<QuickRange *> min_max_ranges;
00086 uint32_t real_prefix_len;
00087 uint32_t real_key_parts;
00088 List<Item_sum> *min_functions;
00089 List<Item_sum> *max_functions;
00090 List<Item_sum>::iterator *min_functions_it;
00091 List<Item_sum>::iterator *max_functions_it;
00092
00093 public:
00094
00095
00096
00097
00098
00099 memory::Root alloc;
00100 QuickRangeSelect *quick_prefix_select;
00102 private:
00103
00125 int next_prefix();
00126
00146 int next_min_in_range();
00147
00167 int next_max_in_range();
00168
00191 int next_min();
00192
00208 int next_max();
00209
00232 void update_min_result();
00233
00255 void update_max_result();
00256
00257 public:
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 QuickGroupMinMaxSelect(Table *table,
00283 Join *join,
00284 bool have_min,
00285 bool have_max,
00286 KeyPartInfo *min_max_arg_part,
00287 uint32_t group_prefix_len,
00288 uint32_t group_key_parts,
00289 uint32_t used_key_parts,
00290 KeyInfo *index_info,
00291 uint use_index,
00292 double read_cost,
00293 ha_rows records,
00294 uint key_infix_len,
00295 unsigned char *key_infix,
00296 memory::Root *parent_alloc);
00297
00298 ~QuickGroupMinMaxSelect();
00299
00317 bool add_range(SEL_ARG *sel_range);
00318
00339 void update_key_stat();
00340
00358 void adjust_prefix_ranges();
00359
00360 bool alloc_buffers();
00361
00378 int init();
00379
00394 int reset();
00395
00422 int get_next();
00423
00424 bool reverse_sorted() const
00425 {
00426 return false;
00427 }
00428
00429 bool unique_key_range() const
00430 {
00431 return false;
00432 }
00433
00434 int get_type() const
00435 {
00436 return QS_TYPE_GROUP_MIN_MAX;
00437 }
00438
00452 void add_keys_and_lengths(std::string *key_names, std::string *used_lengths);
00453
00454 };
00455
00456
00457 }
00458
00459 }
00460