~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/opt_range.h

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
15
19
 
16
20
 
17
21
/* classes to use when handling where clause */
18
22
 
19
 
#ifndef _opt_range_h
20
 
#define _opt_range_h
 
23
#ifndef DRIZZLED_OPT_RANGE_H
 
24
#define DRIZZLED_OPT_RANGE_H
21
25
 
22
26
#ifdef USE_PRAGMA_INTERFACE
23
27
#pragma interface                       /* gcc class implementation */
24
28
#endif
25
29
 
26
30
typedef struct st_key_part {
27
 
  uint16           key,part;
 
31
  uint16_t           key,part;
28
32
  /* See KEY_PART_INFO for meaning of the next two: */
29
 
  uint16           store_length, length;
30
 
  uint8            null_bit;
 
33
  uint16_t           store_length, length;
 
34
  uint8_t            null_bit;
31
35
  /*
32
36
    Keypart flags (0 when this structure is used by partition pruning code
33
37
    for fake partitioning index description)
34
38
  */
35
 
  uint8 flag;
 
39
  uint8_t flag;
36
40
  Field            *field;
37
41
  Field::imagetype image_type;
38
42
} KEY_PART;
40
44
 
41
45
class QUICK_RANGE :public Sql_alloc {
42
46
 public:
43
 
  uchar *min_key,*max_key;
44
 
  uint16 min_length,max_length,flag;
 
47
  unsigned char *min_key,*max_key;
 
48
  uint16_t min_length,max_length,flag;
45
49
  key_part_map min_keypart_map, // bitmap of used keyparts in min_key
46
50
               max_keypart_map; // bitmap of used keyparts in max_key
47
51
#ifdef HAVE_purify
48
 
  uint16 dummy;                                 /* Avoid warnings on 'flag' */
 
52
  uint16_t dummy;                                       /* Avoid warnings on 'flag' */
49
53
#endif
50
54
  QUICK_RANGE();                                /* Full range */
51
 
  QUICK_RANGE(const uchar *min_key_arg, uint min_length_arg,
 
55
  QUICK_RANGE(const unsigned char *min_key_arg, uint32_t min_length_arg,
52
56
              key_part_map min_keypart_map_arg,
53
 
              const uchar *max_key_arg, uint max_length_arg,
 
57
              const unsigned char *max_key_arg, uint32_t max_length_arg,
54
58
              key_part_map max_keypart_map_arg,
55
 
              uint flag_arg)
56
 
    : min_key((uchar*) sql_memdup(min_key_arg,min_length_arg+1)),
57
 
      max_key((uchar*) sql_memdup(max_key_arg,max_length_arg+1)),
58
 
      min_length((uint16) min_length_arg),
59
 
      max_length((uint16) max_length_arg),
60
 
      flag((uint16) flag_arg),
 
59
              uint32_t flag_arg)
 
60
    : min_key((unsigned char*) sql_memdup(min_key_arg,min_length_arg+1)),
 
61
      max_key((unsigned char*) sql_memdup(max_key_arg,max_length_arg+1)),
 
62
      min_length((uint16_t) min_length_arg),
 
63
      max_length((uint16_t) max_length_arg),
 
64
      flag((uint16_t) flag_arg),
61
65
      min_keypart_map(min_keypart_map_arg),
62
66
      max_keypart_map(max_keypart_map_arg)
63
67
    {
117
121
  bool sorted;
118
122
  ha_rows records;  /* estimate of # of records to be retrieved */
119
123
  double  read_time; /* time to perform this retrieval          */
120
 
  TABLE   *head;
 
124
  Table   *head;
121
125
  /*
122
126
    Index this quick select uses, or MAX_KEY for quick selects
123
127
    that use several indexes
124
128
  */
125
 
  uint index;
 
129
  uint32_t index;
126
130
 
127
131
  /*
128
132
    Total length of first used_key_parts parts of the key.
129
133
    Applicable if index!= MAX_KEY.
130
134
  */
131
 
  uint max_used_key_length;
 
135
  uint32_t max_used_key_length;
132
136
 
133
137
  /*
134
138
    Max. number of (first) key parts this quick select uses for retrieval.
137
141
 
138
142
    For QUICK_GROUP_MIN_MAX_SELECT it includes MIN/MAX argument keyparts.
139
143
  */
140
 
  uint used_key_parts;
 
144
  uint32_t used_key_parts;
141
145
 
142
146
  QUICK_SELECT_I();
143
147
  virtual ~QUICK_SELECT_I(){};
212
216
      0     Ok
213
217
      other Error
214
218
  */
215
 
  virtual int init_ror_merged_scan(bool reuse_handler __attribute__((__unused__)))
 
219
  virtual int init_ror_merged_scan(bool reuse_handler __attribute__((unused)))
216
220
  { assert(0); return 1; }
217
221
 
218
222
  /*
234
238
    This function is implemented only by quick selects that merge other quick
235
239
    selects output and/or can produce output suitable for merging.
236
240
  */
237
 
  virtual void add_info_string(String *str __attribute__((__unused__))) {};
 
241
  virtual void add_info_string(String *str __attribute__((unused))) {};
238
242
  /*
239
243
    Return 1 if any index used by this quick select
240
244
    uses field which is marked in passed bitmap.
245
249
    rowid of last row retrieved by this quick select. This is used only when
246
250
    doing ROR-index_merge selects
247
251
  */
248
 
  uchar    *last_rowid;
 
252
  unsigned char    *last_rowid;
249
253
 
250
254
  /*
251
255
    Table record buffer used by this quick select.
252
256
  */
253
 
  uchar    *record;
 
257
  unsigned char    *record;
254
258
};
255
259
 
256
260
 
270
274
  QUICK_RANGE **last;
271
275
} QUICK_RANGE_SEQ_CTX;
272
276
 
273
 
range_seq_t quick_range_seq_init(void *init_param, uint n_ranges, uint flags);
274
 
uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
 
277
range_seq_t quick_range_seq_init(void *init_param, uint32_t n_ranges, uint32_t flags);
 
278
uint32_t quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
275
279
 
276
280
 
277
281
/*
296
300
  /* Members needed to use the MRR interface */
297
301
  QUICK_RANGE_SEQ_CTX qr_traversal_ctx;
298
302
public:
299
 
  uint mrr_flags; /* Flags to be used with MRR interface */
 
303
  uint32_t mrr_flags; /* Flags to be used with MRR interface */
300
304
protected:
301
 
  uint mrr_buf_size; /* copy from thd->variables.read_rnd_buff_size */  
 
305
  uint32_t mrr_buf_size; /* copy from thd->variables.read_rnd_buff_size */  
302
306
  HANDLER_BUFFER *mrr_buf_desc; /* the handler buffer */
303
307
 
304
308
  /* Info about index we're scanning */
313
317
public:
314
318
  MEM_ROOT alloc;
315
319
 
316
 
  QUICK_RANGE_SELECT(THD *thd, TABLE *table,uint index_arg,bool no_alloc,
 
320
  QUICK_RANGE_SELECT(THD *thd, Table *table,uint32_t index_arg,bool no_alloc,
317
321
                     MEM_ROOT *parent_alloc, bool *create_err);
318
322
  ~QUICK_RANGE_SELECT();
319
323
 
321
325
  int reset(void);
322
326
  int get_next();
323
327
  void range_end();
324
 
  int get_next_prefix(uint prefix_length, key_part_map keypart_map,
325
 
                      uchar *cur_prefix);
 
328
  int get_next_prefix(uint32_t prefix_length, key_part_map keypart_map,
 
329
                      unsigned char *cur_prefix);
326
330
  bool reverse_sorted() { return 0; }
327
331
  bool unique_key_range();
328
332
  int init_ror_merged_scan(bool reuse_handler);
335
339
  /* Used only by QUICK_SELECT_DESC */
336
340
  QUICK_RANGE_SELECT(const QUICK_RANGE_SELECT& org) : QUICK_SELECT_I()
337
341
  {
338
 
    bcopy(&org, this, sizeof(*this));
 
342
    memmove(this, &org, sizeof(*this));
339
343
    /* 
340
344
      Use default MRR implementation for reverse scans. No table engine
341
345
      currently can do an MRR scan with output in reverse index order.
346
350
  }
347
351
  friend class TRP_ROR_INTERSECT;
348
352
  friend
349
 
  QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table,
 
353
  QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, Table *table,
350
354
                                               struct st_table_ref *ref,
351
355
                                               ha_rows records);
352
356
  friend bool get_quick_keys(PARAM *param, QUICK_RANGE_SELECT *quick, 
353
357
                             KEY_PART *key, SEL_ARG *key_tree, 
354
 
                             uchar *min_key, uint min_key_flag,
355
 
                             uchar *max_key, uint max_key_flag);
356
 
  friend QUICK_RANGE_SELECT *get_quick_select(PARAM*,uint idx,
 
358
                             unsigned char *min_key, uint32_t min_key_flag,
 
359
                             unsigned char *max_key, uint32_t max_key_flag);
 
360
  friend QUICK_RANGE_SELECT *get_quick_select(PARAM*,uint32_t idx,
357
361
                                              SEL_ARG *key_tree,
358
 
                                              uint mrr_flags,
359
 
                                              uint mrr_buf_size,
 
362
                                              uint32_t mrr_flags,
 
363
                                              uint32_t mrr_buf_size,
360
364
                                              MEM_ROOT *alloc);
361
365
  friend class QUICK_SELECT_DESC;
362
366
  friend class QUICK_INDEX_MERGE_SELECT;
363
367
  friend class QUICK_ROR_INTERSECT_SELECT;
364
368
  friend class QUICK_GROUP_MIN_MAX_SELECT;
365
 
  friend uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
 
369
  friend uint32_t quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
366
370
  friend range_seq_t quick_range_seq_init(void *init_param,
367
 
                                          uint n_ranges, uint flags);
 
371
                                          uint32_t n_ranges, uint32_t flags);
368
372
  friend void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
369
373
                              bool distinct,const char *message);
370
374
};
432
436
class QUICK_INDEX_MERGE_SELECT : public QUICK_SELECT_I
433
437
{
434
438
public:
435
 
  QUICK_INDEX_MERGE_SELECT(THD *thd, TABLE *table);
 
439
  QUICK_INDEX_MERGE_SELECT(THD *thd, Table *table);
436
440
  ~QUICK_INDEX_MERGE_SELECT();
437
441
 
438
442
  int  init();
486
490
class QUICK_ROR_INTERSECT_SELECT : public QUICK_SELECT_I
487
491
{
488
492
public:
489
 
  QUICK_ROR_INTERSECT_SELECT(THD *thd, TABLE *table,
 
493
  QUICK_ROR_INTERSECT_SELECT(THD *thd, Table *table,
490
494
                             bool retrieve_full_rows,
491
495
                             MEM_ROOT *parent_alloc);
492
496
  ~QUICK_ROR_INTERSECT_SELECT();
539
543
class QUICK_ROR_UNION_SELECT : public QUICK_SELECT_I
540
544
{
541
545
public:
542
 
  QUICK_ROR_UNION_SELECT(THD *thd, TABLE *table);
 
546
  QUICK_ROR_UNION_SELECT(THD *thd, Table *table);
543
547
  ~QUICK_ROR_UNION_SELECT();
544
548
 
545
549
  int  init();
560
564
  MEM_ROOT alloc; /* Memory pool for this and merged quick selects data. */
561
565
 
562
566
  THD *thd;             /* current thread */
563
 
  uchar *cur_rowid;      /* buffer used in get_next() */
564
 
  uchar *prev_rowid;     /* rowid of last row returned by get_next() */
 
567
  unsigned char *cur_rowid;      /* buffer used in get_next() */
 
568
  unsigned char *prev_rowid;     /* rowid of last row returned by get_next() */
565
569
  bool have_prev_rowid; /* true if prev_rowid has valid data */
566
 
  uint rowid_length;    /* table rowid length */
 
570
  uint32_t rowid_length;    /* table rowid length */
567
571
private:
568
 
  static int queue_cmp(void *arg, uchar *val1, uchar *val2);
 
572
  static int queue_cmp(void *arg, unsigned char *val1, unsigned char *val2);
569
573
  bool scans_inited; 
570
574
};
571
575
 
609
613
  handler *file;         /* The handler used to get data. */
610
614
  JOIN *join;            /* Descriptor of the current query */
611
615
  KEY  *index_info;      /* The index chosen for data access */
612
 
  uchar *record;          /* Buffer where the next record is returned. */
613
 
  uchar *tmp_record;      /* Temporary storage for next_min(), next_max(). */
614
 
  uchar *group_prefix;    /* Key prefix consisting of the GROUP fields. */
615
 
  uint group_prefix_len; /* Length of the group prefix. */
616
 
  uint group_key_parts;  /* A number of keyparts in the group prefix */
617
 
  uchar *last_prefix;     /* Prefix of the last group for detecting EOF. */
 
616
  unsigned char *record;          /* Buffer where the next record is returned. */
 
617
  unsigned char *tmp_record;      /* Temporary storage for next_min(), next_max(). */
 
618
  unsigned char *group_prefix;    /* Key prefix consisting of the GROUP fields. */
 
619
  uint32_t group_prefix_len; /* Length of the group prefix. */
 
620
  uint32_t group_key_parts;  /* A number of keyparts in the group prefix */
 
621
  unsigned char *last_prefix;     /* Prefix of the last group for detecting EOF. */
618
622
  bool have_min;         /* Specify whether we are computing */
619
623
  bool have_max;         /*   a MIN, a MAX, or both.         */
620
624
  bool seen_first_key;   /* Denotes whether the first key was retrieved.*/
621
625
  KEY_PART_INFO *min_max_arg_part; /* The keypart of the only argument field */
622
626
                                   /* of all MIN/MAX functions.              */
623
 
  uint min_max_arg_len;  /* The length of the MIN/MAX argument field */
624
 
  uchar *key_infix;       /* Infix of constants from equality predicates. */
625
 
  uint key_infix_len;
 
627
  uint32_t min_max_arg_len;  /* The length of the MIN/MAX argument field */
 
628
  unsigned char *key_infix;       /* Infix of constants from equality predicates. */
 
629
  uint32_t key_infix_len;
626
630
  DYNAMIC_ARRAY min_max_ranges; /* Array of range ptrs for the MIN/MAX field. */
627
 
  uint real_prefix_len; /* Length of key prefix extended with key_infix. */
628
 
  uint real_key_parts;  /* A number of keyparts in the above value.      */
 
631
  uint32_t real_prefix_len; /* Length of key prefix extended with key_infix. */
 
632
  uint32_t real_key_parts;  /* A number of keyparts in the above value.      */
629
633
  List<Item_sum> *min_functions;
630
634
  List<Item_sum> *max_functions;
631
635
  List_iterator<Item_sum> *min_functions_it;
646
650
  void update_min_result();
647
651
  void update_max_result();
648
652
public:
649
 
  QUICK_GROUP_MIN_MAX_SELECT(TABLE *table, JOIN *join, bool have_min,
 
653
  QUICK_GROUP_MIN_MAX_SELECT(Table *table, JOIN *join, bool have_min,
650
654
                             bool have_max, KEY_PART_INFO *min_max_arg_part,
651
 
                             uint group_prefix_len, uint group_key_parts,
652
 
                             uint used_key_parts, KEY *index_info, uint
 
655
                             uint32_t group_prefix_len, uint32_t group_key_parts,
 
656
                             uint32_t used_key_parts, KEY *index_info, uint
653
657
                             use_index, double read_cost, ha_rows records, uint
654
 
                             key_infix_len, uchar *key_infix, MEM_ROOT
 
658
                             key_infix_len, unsigned char *key_infix, MEM_ROOT
655
659
                             *parent_alloc);
656
660
  ~QUICK_GROUP_MIN_MAX_SELECT();
657
661
  bool add_range(SEL_ARG *sel_range);
671
675
class QUICK_SELECT_DESC: public QUICK_RANGE_SELECT
672
676
{
673
677
public:
674
 
  QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q, uint used_key_parts, 
 
678
  QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q, uint32_t used_key_parts, 
675
679
                    bool *create_err);
676
680
  int get_next();
677
681
  bool reverse_sorted() { return 1; }
679
683
private:
680
684
  bool range_reads_after_key(QUICK_RANGE *range);
681
685
#ifdef NOT_USED
682
 
  bool test_if_null_range(QUICK_RANGE *range, uint used_key_parts);
 
686
  bool test_if_null_range(QUICK_RANGE *range, uint32_t used_key_parts);
683
687
#endif
684
688
  int reset(void) { rev_it.rewind(); return QUICK_RANGE_SELECT::reset(); }
685
689
  List<QUICK_RANGE> rev_ranges;
691
695
 public:
692
696
  QUICK_SELECT_I *quick;        // If quick-select used
693
697
  COND          *cond;          // where condition
694
 
  TABLE *head;
 
698
  Table *head;
695
699
  IO_CACHE file;                // Positions to used records
696
700
  ha_rows records;              // Records in use if read from file
697
701
  double read_time;             // Time to read rows
715
719
                        bool ordered_output);
716
720
};
717
721
 
718
 
QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table,
 
722
QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, Table *table,
719
723
                                             struct st_table_ref *ref,
720
724
                                             ha_rows records);
721
 
uint get_index_for_order(TABLE *table, ORDER *order, ha_rows limit);
 
725
uint32_t get_index_for_order(Table *table, order_st *order, ha_rows limit);
722
726
 
723
727
#endif