Skip to content

Commit

Permalink
[feature] Issue#26 ADD NEW HANDLER METHODS FOR NOTIFYING STORAGE ENGI…
Browse files Browse the repository at this point in the history
…NE OF IMMINENT INDEX

Description:
------------
Ported from percona server:
http://bazaar.launchpad.net/~laurynas-biveinis/percona-server/tokudb-prepare-scans/revision/566
  • Loading branch information
AliSQL authored and AliSQL committed Oct 8, 2016
1 parent cf5e15e commit 96ee8f5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
37 changes: 37 additions & 0 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,43 @@ class handler :public Sql_alloc
uint key_len= calculate_key_len(table, active_index, key, keypart_map);
return index_read_last(buf, key, key_len);
}
public:
/**
TokuDB:
Notify storage engine about imminent index scan where a large number of
rows is expected to be returned. Does not replace nor call index_init.
*/
virtual int prepare_index_scan(void) { return 0; }

/**
Notify storage engine about imminent index range scan.
*/
virtual int prepare_range_scan(const key_range *start_key,
const key_range *end_key)
{
return 0;
}

/**
Notify storage engine about imminent index read with a bitmap of used key
parts.
*/
int prepare_index_key_scan_map(const uchar *key, key_part_map keypart_map)
{
uint key_len= calculate_key_len(table, active_index, key, keypart_map);
return prepare_index_key_scan(key, key_len);
}

protected:

/**
Notify storage engine about imminent index read with key length.
*/
virtual int prepare_index_key_scan(const uchar *key, uint key_len)
{
return 0;
}

public:
virtual int read_range_first(const key_range *start_key,
const key_range *end_key,
Expand Down
13 changes: 13 additions & 0 deletions sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10924,6 +10924,19 @@ int QUICK_SELECT_DESC::get_next()
}
}

/* TokuDB */
key_range prepare_range_start;
key_range prepare_range_end;

last_range->make_min_endpoint(&prepare_range_start);
last_range->make_max_endpoint(&prepare_range_end);
result= file->prepare_range_scan((last_range->flag & NO_MIN_RANGE)
? NULL : &prepare_range_start,
(last_range->flag & NO_MAX_RANGE)
? NULL : &prepare_range_end);
if (result)
DBUG_RETURN(result);

if (last_range->flag & NO_MAX_RANGE) // Read last record
{
int local_error;
Expand Down
16 changes: 14 additions & 2 deletions sql/records.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,14 @@ static int rr_quick(READ_RECORD *info)

static int rr_index_first(READ_RECORD *info)
{
int tmp= info->table->file->ha_index_first(info->record);
int tmp= info->table->file->prepare_index_scan();
info->read_record= rr_index;
if (tmp)
{
tmp= rr_handle_error(info, tmp);
return tmp;
}
tmp= info->table->file->ha_index_first(info->record);
if (tmp)
tmp= rr_handle_error(info, tmp);
return tmp;
Expand All @@ -416,8 +422,14 @@ static int rr_index_first(READ_RECORD *info)

static int rr_index_last(READ_RECORD *info)
{
int tmp= info->table->file->ha_index_last(info->record);
int tmp= info->table->file->prepare_index_scan();
info->read_record= rr_index_desc;
if (tmp)
{
tmp= rr_handle_error(info, tmp);
return tmp;
}
tmp= info->table->file->ha_index_last(info->record);
if (tmp)
tmp= rr_handle_error(info, tmp);
return tmp;
Expand Down
7 changes: 7 additions & 0 deletions sql/sql_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,9 @@ join_read_always_key(JOIN_TAB *tab)

if (cp_buffer_from_ref(tab->join->thd, table, ref))
return -1;
if ((error= table->file->prepare_index_key_scan_map(tab->ref.key_buff,
make_prev_keypart_map(tab->ref.key_parts))))
return report_handler_error(table, error);
if ((error= table->file->ha_index_read_map(table->record[0],
tab->ref.key_buff,
make_prev_keypart_map(tab->ref.key_parts),
Expand Down Expand Up @@ -2536,6 +2539,8 @@ join_read_first(JOIN_TAB *tab)
(void) report_handler_error(table, error);
return 1;
}
if ((error= tab->table->file->prepare_index_scan()))
return 1;
if ((error= tab->table->file->ha_index_first(tab->table->record[0])))
{
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
Expand Down Expand Up @@ -2574,6 +2579,8 @@ join_read_last(JOIN_TAB *tab)
(void) report_handler_error(table, error);
return 1;
}
if ((error= table->file->prepare_index_scan()))
return report_handler_error(table, error);
if ((error= tab->table->file->ha_index_last(tab->table->record[0])))
return report_handler_error(table, error);
return 0;
Expand Down

0 comments on commit 96ee8f5

Please sign in to comment.