Skip to content

Commit 96ee8f5

Browse files
AliSQLAliSQL
authored andcommitted
[feature] Issue#26 ADD NEW HANDLER METHODS FOR NOTIFYING STORAGE ENGINE OF IMMINENT INDEX
Description: ------------ Ported from percona server: http://bazaar.launchpad.net/~laurynas-biveinis/percona-server/tokudb-prepare-scans/revision/566
1 parent cf5e15e commit 96ee8f5

4 files changed

Lines changed: 71 additions & 2 deletions

File tree

sql/handler.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,43 @@ class handler :public Sql_alloc
23102310
uint key_len= calculate_key_len(table, active_index, key, keypart_map);
23112311
return index_read_last(buf, key, key_len);
23122312
}
2313+
public:
2314+
/**
2315+
TokuDB:
2316+
Notify storage engine about imminent index scan where a large number of
2317+
rows is expected to be returned. Does not replace nor call index_init.
2318+
*/
2319+
virtual int prepare_index_scan(void) { return 0; }
2320+
2321+
/**
2322+
Notify storage engine about imminent index range scan.
2323+
*/
2324+
virtual int prepare_range_scan(const key_range *start_key,
2325+
const key_range *end_key)
2326+
{
2327+
return 0;
2328+
}
2329+
2330+
/**
2331+
Notify storage engine about imminent index read with a bitmap of used key
2332+
parts.
2333+
*/
2334+
int prepare_index_key_scan_map(const uchar *key, key_part_map keypart_map)
2335+
{
2336+
uint key_len= calculate_key_len(table, active_index, key, keypart_map);
2337+
return prepare_index_key_scan(key, key_len);
2338+
}
2339+
2340+
protected:
2341+
2342+
/**
2343+
Notify storage engine about imminent index read with key length.
2344+
*/
2345+
virtual int prepare_index_key_scan(const uchar *key, uint key_len)
2346+
{
2347+
return 0;
2348+
}
2349+
23132350
public:
23142351
virtual int read_range_first(const key_range *start_key,
23152352
const key_range *end_key,

sql/opt_range.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10924,6 +10924,19 @@ int QUICK_SELECT_DESC::get_next()
1092410924
}
1092510925
}
1092610926

10927+
/* TokuDB */
10928+
key_range prepare_range_start;
10929+
key_range prepare_range_end;
10930+
10931+
last_range->make_min_endpoint(&prepare_range_start);
10932+
last_range->make_max_endpoint(&prepare_range_end);
10933+
result= file->prepare_range_scan((last_range->flag & NO_MIN_RANGE)
10934+
? NULL : &prepare_range_start,
10935+
(last_range->flag & NO_MAX_RANGE)
10936+
? NULL : &prepare_range_end);
10937+
if (result)
10938+
DBUG_RETURN(result);
10939+
1092710940
if (last_range->flag & NO_MAX_RANGE) // Read last record
1092810941
{
1092910942
int local_error;

sql/records.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,14 @@ static int rr_quick(READ_RECORD *info)
393393

394394
static int rr_index_first(READ_RECORD *info)
395395
{
396-
int tmp= info->table->file->ha_index_first(info->record);
396+
int tmp= info->table->file->prepare_index_scan();
397397
info->read_record= rr_index;
398+
if (tmp)
399+
{
400+
tmp= rr_handle_error(info, tmp);
401+
return tmp;
402+
}
403+
tmp= info->table->file->ha_index_first(info->record);
398404
if (tmp)
399405
tmp= rr_handle_error(info, tmp);
400406
return tmp;
@@ -416,8 +422,14 @@ static int rr_index_first(READ_RECORD *info)
416422

417423
static int rr_index_last(READ_RECORD *info)
418424
{
419-
int tmp= info->table->file->ha_index_last(info->record);
425+
int tmp= info->table->file->prepare_index_scan();
420426
info->read_record= rr_index_desc;
427+
if (tmp)
428+
{
429+
tmp= rr_handle_error(info, tmp);
430+
return tmp;
431+
}
432+
tmp= info->table->file->ha_index_last(info->record);
421433
if (tmp)
422434
tmp= rr_handle_error(info, tmp);
423435
return tmp;

sql/sql_executor.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,9 @@ join_read_always_key(JOIN_TAB *tab)
22102210

22112211
if (cp_buffer_from_ref(tab->join->thd, table, ref))
22122212
return -1;
2213+
if ((error= table->file->prepare_index_key_scan_map(tab->ref.key_buff,
2214+
make_prev_keypart_map(tab->ref.key_parts))))
2215+
return report_handler_error(table, error);
22132216
if ((error= table->file->ha_index_read_map(table->record[0],
22142217
tab->ref.key_buff,
22152218
make_prev_keypart_map(tab->ref.key_parts),
@@ -2536,6 +2539,8 @@ join_read_first(JOIN_TAB *tab)
25362539
(void) report_handler_error(table, error);
25372540
return 1;
25382541
}
2542+
if ((error= tab->table->file->prepare_index_scan()))
2543+
return 1;
25392544
if ((error= tab->table->file->ha_index_first(tab->table->record[0])))
25402545
{
25412546
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
@@ -2574,6 +2579,8 @@ join_read_last(JOIN_TAB *tab)
25742579
(void) report_handler_error(table, error);
25752580
return 1;
25762581
}
2582+
if ((error= table->file->prepare_index_scan()))
2583+
return report_handler_error(table, error);
25772584
if ((error= tab->table->file->ha_index_last(tab->table->record[0])))
25782585
return report_handler_error(table, error);
25792586
return 0;

0 commit comments

Comments
 (0)