mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
index_merge implementation using Unique class, to be merged into 5.0
This commit is contained in:
130
sql/opt_range.h
130
sql/opt_range.h
@ -65,48 +65,142 @@ class QUICK_RANGE :public Sql_alloc {
|
||||
}
|
||||
};
|
||||
|
||||
//class INDEX_MERGE;
|
||||
|
||||
class QUICK_SELECT {
|
||||
/*
|
||||
Quick select interface.
|
||||
This class is parent for all QUICK_*_SELECT and FT_SELECT classes.
|
||||
*/
|
||||
|
||||
class QUICK_SELECT_I
|
||||
{
|
||||
public:
|
||||
ha_rows records; /* estimate of # of records to be retrieved */
|
||||
double read_time; /* time to perform this retrieval */
|
||||
TABLE *head;
|
||||
|
||||
/*
|
||||
the only index this quick select uses, or MAX_KEY for
|
||||
QUICK_INDEX_MERGE_SELECT
|
||||
*/
|
||||
uint index;
|
||||
uint max_used_key_length, used_key_parts;
|
||||
|
||||
QUICK_SELECT_I();
|
||||
virtual ~QUICK_SELECT_I(){};
|
||||
virtual int init() = 0;
|
||||
virtual int reset(void) = 0;
|
||||
virtual int get_next() = 0; /* get next record to retrieve */
|
||||
virtual bool reverse_sorted() = 0;
|
||||
virtual bool unique_key_range() { return false; }
|
||||
|
||||
enum {
|
||||
QS_TYPE_RANGE = 0,
|
||||
QS_TYPE_INDEX_MERGE = 1,
|
||||
QS_TYPE_RANGE_DESC = 2,
|
||||
QS_TYPE_FULLTEXT = 3
|
||||
};
|
||||
|
||||
/* Get type of this quick select - one of the QS_* values */
|
||||
virtual int get_type() = 0;
|
||||
};
|
||||
|
||||
struct st_qsel_param;
|
||||
class SEL_ARG;
|
||||
|
||||
class QUICK_RANGE_SELECT : public QUICK_SELECT_I
|
||||
{
|
||||
protected:
|
||||
bool next,dont_free;
|
||||
public:
|
||||
int error;
|
||||
uint index, max_used_key_length, used_key_parts;
|
||||
TABLE *head;
|
||||
handler *file;
|
||||
byte *record;
|
||||
protected:
|
||||
friend void print_quick_sel_range(QUICK_RANGE_SELECT *quick,
|
||||
key_map needed_reg);
|
||||
friend QUICK_RANGE_SELECT *get_quick_select_for_ref(TABLE *table,
|
||||
struct st_table_ref *ref);
|
||||
friend bool get_quick_keys(struct st_qsel_param *param,
|
||||
QUICK_RANGE_SELECT *quick,KEY_PART *key,
|
||||
SEL_ARG *key_tree,char *min_key,uint min_key_flag,
|
||||
char *max_key, uint max_key_flag);
|
||||
friend QUICK_RANGE_SELECT *get_quick_select(struct st_qsel_param*,uint idx,
|
||||
SEL_ARG *key_tree,
|
||||
MEM_ROOT *alloc);
|
||||
friend class QUICK_SELECT_DESC;
|
||||
|
||||
List<QUICK_RANGE> ranges;
|
||||
List_iterator<QUICK_RANGE> it;
|
||||
QUICK_RANGE *range;
|
||||
MEM_ROOT alloc;
|
||||
|
||||
KEY_PART *key_parts;
|
||||
ha_rows records;
|
||||
double read_time;
|
||||
|
||||
QUICK_SELECT(TABLE *table,uint index_arg,bool no_alloc=0);
|
||||
virtual ~QUICK_SELECT();
|
||||
void reset(void) { next=0; it.rewind(); }
|
||||
int init() { return error=file->index_init(index); }
|
||||
virtual int get_next();
|
||||
virtual bool reverse_sorted() { return 0; }
|
||||
int cmp_next(QUICK_RANGE *range);
|
||||
public:
|
||||
QUICK_RANGE_SELECT(TABLE *table,uint index_arg,bool no_alloc=0,
|
||||
MEM_ROOT *parent_alloc=NULL);
|
||||
~QUICK_RANGE_SELECT();
|
||||
|
||||
int reset(void) { next=0; it.rewind(); return 0; }
|
||||
int init();
|
||||
int get_next();
|
||||
bool reverse_sorted() { return 0; }
|
||||
bool unique_key_range();
|
||||
int get_type() { return QS_TYPE_RANGE; }
|
||||
};
|
||||
|
||||
/*
|
||||
Index merge quick select.
|
||||
It is implemented as a container for several QUICK_RANGE_SELECTs.
|
||||
*/
|
||||
|
||||
class QUICK_SELECT_DESC: public QUICK_SELECT
|
||||
class QUICK_INDEX_MERGE_SELECT : public QUICK_SELECT_I
|
||||
{
|
||||
public:
|
||||
QUICK_SELECT_DESC(QUICK_SELECT *q, uint used_key_parts);
|
||||
QUICK_INDEX_MERGE_SELECT(THD *thd, TABLE *table);
|
||||
~QUICK_INDEX_MERGE_SELECT();
|
||||
|
||||
int init();
|
||||
int reset(void);
|
||||
int get_next();
|
||||
bool reverse_sorted() { return false; }
|
||||
bool unique_key_range() { return false; }
|
||||
int get_type() { return QS_TYPE_INDEX_MERGE; }
|
||||
|
||||
bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range);
|
||||
|
||||
/* range quick selects this index_merge read consists of */
|
||||
List<QUICK_RANGE_SELECT> quick_selects;
|
||||
|
||||
/* quick select which is currently used for rows retrieval */
|
||||
List_iterator_fast<QUICK_RANGE_SELECT> cur_quick_it;
|
||||
QUICK_RANGE_SELECT* cur_quick_select;
|
||||
|
||||
/* last element in quick_selects list. */
|
||||
QUICK_RANGE_SELECT* last_quick_select;
|
||||
|
||||
Unique *unique;
|
||||
MEM_ROOT alloc;
|
||||
|
||||
THD *thd;
|
||||
int prepare_unique();
|
||||
bool reset_called;
|
||||
};
|
||||
|
||||
class QUICK_SELECT_DESC: public QUICK_RANGE_SELECT
|
||||
{
|
||||
public:
|
||||
QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q, uint used_key_parts);
|
||||
int get_next();
|
||||
bool reverse_sorted() { return 1; }
|
||||
int get_type() { return QS_TYPE_RANGE_DESC; }
|
||||
private:
|
||||
int cmp_prev(QUICK_RANGE *range);
|
||||
bool range_reads_after_key(QUICK_RANGE *range);
|
||||
#ifdef NOT_USED
|
||||
bool test_if_null_range(QUICK_RANGE *range, uint used_key_parts);
|
||||
#endif
|
||||
void reset(void) { next=0; rev_it.rewind(); }
|
||||
int reset(void) { next=0; rev_it.rewind(); return 0; }
|
||||
List<QUICK_RANGE> rev_ranges;
|
||||
List_iterator<QUICK_RANGE> rev_it;
|
||||
};
|
||||
@ -114,7 +208,7 @@ private:
|
||||
|
||||
class SQL_SELECT :public Sql_alloc {
|
||||
public:
|
||||
QUICK_SELECT *quick; // If quick-select used
|
||||
QUICK_SELECT_I *quick; // If quick-select used
|
||||
COND *cond; // where condition
|
||||
TABLE *head;
|
||||
IO_CACHE file; // Positions to used records
|
||||
@ -134,6 +228,6 @@ class SQL_SELECT :public Sql_alloc {
|
||||
bool force_quick_range=0);
|
||||
};
|
||||
|
||||
QUICK_SELECT *get_quick_select_for_ref(TABLE *table, struct st_table_ref *ref);
|
||||
QUICK_RANGE_SELECT *get_quick_select_for_ref(TABLE *table, struct st_table_ref *ref);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user