~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/opt_range.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 20:26:28 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321202628-nh6qsi825m4d4av6
Removing the queues.[h,cc] files from the mysys directory. The only place
where they are needed now is in the MyISAM storage engine. Thus, I moved the
files there and updated the files in the MyISAM storage engine
appropriately.

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