~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:
23
23
#ifndef DRIZZLED_OPT_RANGE_H
24
24
#define DRIZZLED_OPT_RANGE_H
25
25
 
26
 
#include <drizzled/field.h>
27
 
#include <mysys/queues.h>
28
 
#include <drizzled/item/sum.h>
29
 
 
30
 
class JOIN;
31
 
typedef class Item COND;
32
 
 
33
 
typedef struct st_handler_buffer HANDLER_BUFFER;
 
26
#ifdef USE_PRAGMA_INTERFACE
 
27
#pragma interface                       /* gcc class implementation */
 
28
#endif
34
29
 
35
30
typedef struct st_key_part {
36
31
  uint16_t           key,part;
178
173
    reset() should be called when it is certain that row retrieval will be
179
174
    necessary. This call may do heavyweight initialization like buffering first
180
175
    N records etc. If reset() call fails get_next() must not be called.
181
 
    Note that reset() may be called several times if
 
176
    Note that reset() may be called several times if 
182
177
     * the quick select is executed in a subselect
183
178
     * a JOIN buffer is used
184
 
 
 
179
    
185
180
    RETURN
186
181
      0      OK
187
182
      other  Error code
221
216
      0     Ok
222
217
      other Error
223
218
  */
224
 
  virtual int init_ror_merged_scan(bool)
 
219
  virtual int init_ror_merged_scan(bool reuse_handler __attribute__((unused)))
225
220
  { assert(0); return 1; }
226
221
 
227
222
  /*
243
238
    This function is implemented only by quick selects that merge other quick
244
239
    selects output and/or can produce output suitable for merging.
245
240
  */
246
 
  virtual void add_info_string(String *) {};
 
241
  virtual void add_info_string(String *str __attribute__((unused))) {};
247
242
  /*
248
243
    Return 1 if any index used by this quick select
249
244
    uses field which is marked in passed bitmap.
301
296
  /* Range pointers to be used when not using MRR interface */
302
297
  QUICK_RANGE **cur_range;  /* current element in ranges  */
303
298
  QUICK_RANGE *last_range;
304
 
 
 
299
  
305
300
  /* Members needed to use the MRR interface */
306
301
  QUICK_RANGE_SEQ_CTX qr_traversal_ctx;
307
302
public:
308
303
  uint32_t mrr_flags; /* Flags to be used with MRR interface */
309
304
protected:
310
 
  uint32_t mrr_buf_size; /* copy from session->variables.read_rnd_buff_size */
 
305
  uint32_t mrr_buf_size; /* copy from thd->variables.read_rnd_buff_size */  
311
306
  HANDLER_BUFFER *mrr_buf_desc; /* the handler buffer */
312
307
 
313
308
  /* Info about index we're scanning */
314
309
  KEY_PART *key_parts;
315
310
  KEY_PART_INFO *key_part_info;
316
 
 
 
311
  
317
312
  bool dont_free; /* Used by QUICK_SELECT_DESC */
318
313
 
319
314
  int cmp_next(QUICK_RANGE *range);
322
317
public:
323
318
  MEM_ROOT alloc;
324
319
 
325
 
  QUICK_RANGE_SELECT(Session *session, Table *table,uint32_t index_arg,bool no_alloc,
 
320
  QUICK_RANGE_SELECT(THD *thd, Table *table,uint32_t index_arg,bool no_alloc,
326
321
                     MEM_ROOT *parent_alloc, bool *create_err);
327
322
  ~QUICK_RANGE_SELECT();
328
323
 
335
330
  bool reverse_sorted() { return 0; }
336
331
  bool unique_key_range();
337
332
  int init_ror_merged_scan(bool reuse_handler);
338
 
  void save_last_pos();
 
333
  void save_last_pos()
 
334
  { file->position(record); }
339
335
  int get_type() { return QS_TYPE_RANGE; }
340
336
  void add_keys_and_lengths(String *key_names, String *used_lengths);
341
337
  void add_info_string(String *str);
344
340
  QUICK_RANGE_SELECT(const QUICK_RANGE_SELECT& org) : QUICK_SELECT_I()
345
341
  {
346
342
    memmove(this, &org, sizeof(*this));
347
 
    /*
 
343
    /* 
348
344
      Use default MRR implementation for reverse scans. No table engine
349
345
      currently can do an MRR scan with output in reverse index order.
350
346
    */
354
350
  }
355
351
  friend class TRP_ROR_INTERSECT;
356
352
  friend
357
 
  QUICK_RANGE_SELECT *get_quick_select_for_ref(Session *session, Table *table,
 
353
  QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, Table *table,
358
354
                                               struct st_table_ref *ref,
359
355
                                               ha_rows records);
360
 
  friend bool get_quick_keys(PARAM *param, QUICK_RANGE_SELECT *quick,
361
 
                             KEY_PART *key, SEL_ARG *key_tree,
 
356
  friend bool get_quick_keys(PARAM *param, QUICK_RANGE_SELECT *quick, 
 
357
                             KEY_PART *key, SEL_ARG *key_tree, 
362
358
                             unsigned char *min_key, uint32_t min_key_flag,
363
359
                             unsigned char *max_key, uint32_t max_key_flag);
364
360
  friend QUICK_RANGE_SELECT *get_quick_select(PARAM*,uint32_t idx,
440
436
class QUICK_INDEX_MERGE_SELECT : public QUICK_SELECT_I
441
437
{
442
438
public:
443
 
  QUICK_INDEX_MERGE_SELECT(Session *session, Table *table);
 
439
  QUICK_INDEX_MERGE_SELECT(THD *thd, Table *table);
444
440
  ~QUICK_INDEX_MERGE_SELECT();
445
441
 
446
442
  int  init();
465
461
  bool  doing_pk_scan;
466
462
 
467
463
  MEM_ROOT alloc;
468
 
  Session *session;
 
464
  THD *thd;
469
465
  int read_keys_and_merge();
470
466
 
471
467
  /* used to get rows collected in Unique */
494
490
class QUICK_ROR_INTERSECT_SELECT : public QUICK_SELECT_I
495
491
{
496
492
public:
497
 
  QUICK_ROR_INTERSECT_SELECT(Session *session, Table *table,
 
493
  QUICK_ROR_INTERSECT_SELECT(THD *thd, Table *table,
498
494
                             bool retrieve_full_rows,
499
495
                             MEM_ROOT *parent_alloc);
500
496
  ~QUICK_ROR_INTERSECT_SELECT();
524
520
  QUICK_RANGE_SELECT *cpk_quick;
525
521
 
526
522
  MEM_ROOT alloc; /* Memory pool for this and merged quick selects data. */
527
 
  Session *session;       /* current thread */
 
523
  THD *thd;       /* current thread */
528
524
  bool need_to_fetch_row; /* if true, do retrieve full table records. */
529
525
  /* in top-level quick select, true if merged scans where initialized */
530
 
  bool scans_inited;
 
526
  bool scans_inited; 
531
527
};
532
528
 
533
529
 
544
540
 
545
541
*/
546
542
 
547
 
extern "C" {
548
543
class QUICK_ROR_UNION_SELECT : public QUICK_SELECT_I
549
544
{
550
545
public:
551
 
  QUICK_ROR_UNION_SELECT(Session *session, Table *table);
 
546
  QUICK_ROR_UNION_SELECT(THD *thd, Table *table);
552
547
  ~QUICK_ROR_UNION_SELECT();
553
548
 
554
549
  int  init();
568
563
  QUEUE queue;    /* Priority queue for merge operation */
569
564
  MEM_ROOT alloc; /* Memory pool for this and merged quick selects data. */
570
565
 
571
 
  Session *session;             /* current thread */
 
566
  THD *thd;             /* current thread */
572
567
  unsigned char *cur_rowid;      /* buffer used in get_next() */
573
568
  unsigned char *prev_rowid;     /* rowid of last row returned by get_next() */
574
569
  bool have_prev_rowid; /* true if prev_rowid has valid data */
575
570
  uint32_t rowid_length;    /* table rowid length */
576
571
private:
577
572
  static int queue_cmp(void *arg, unsigned char *val1, unsigned char *val2);
578
 
  bool scans_inited;
 
573
  bool scans_inited; 
579
574
};
580
 
}
581
575
 
582
576
 
583
577
/*
681
675
class QUICK_SELECT_DESC: public QUICK_RANGE_SELECT
682
676
{
683
677
public:
684
 
  QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q, uint32_t used_key_parts,
 
678
  QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q, uint32_t used_key_parts, 
685
679
                    bool *create_err);
686
680
  int get_next();
687
681
  bool reverse_sorted() { return 1; }
688
682
  int get_type() { return QS_TYPE_RANGE_DESC; }
689
683
private:
690
684
  bool range_reads_after_key(QUICK_RANGE *range);
 
685
#ifdef NOT_USED
 
686
  bool test_if_null_range(QUICK_RANGE *range, uint32_t used_key_parts);
 
687
#endif
691
688
  int reset(void) { rev_it.rewind(); return QUICK_RANGE_SELECT::reset(); }
692
689
  List<QUICK_RANGE> rev_ranges;
693
690
  List_iterator<QUICK_RANGE> rev_it;
710
707
  SQL_SELECT();
711
708
  ~SQL_SELECT();
712
709
  void cleanup();
713
 
  bool check_quick(Session *session, bool force_quick_range, ha_rows limit);
714
 
  bool skip_record();
715
 
  int test_quick_select(Session *session, key_map keys, table_map prev_tables,
716
 
                        ha_rows limit, bool force_quick_range,
 
710
  bool check_quick(THD *thd, bool force_quick_range, ha_rows limit)
 
711
  {
 
712
    key_map tmp;
 
713
    tmp.set_all();
 
714
    return test_quick_select(thd, tmp, 0, limit, force_quick_range, false) < 0;
 
715
  }
 
716
  inline bool skip_record() { return cond ? cond->val_int() == 0 : 0; }
 
717
  int test_quick_select(THD *thd, key_map keys, table_map prev_tables,
 
718
                        ha_rows limit, bool force_quick_range, 
717
719
                        bool ordered_output);
718
720
};
719
721
 
720
 
QUICK_RANGE_SELECT *get_quick_select_for_ref(Session *session, Table *table,
 
722
QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, Table *table,
721
723
                                             struct st_table_ref *ref,
722
724
                                             ha_rows records);
723
725
uint32_t get_index_for_order(Table *table, order_st *order, ha_rows limit);