Merge lp:~laurynas-biveinis/percona-server/tokudb-prepare-scans into lp:percona-server/5.6

Proposed by Laurynas Biveinis
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 573
Proposed branch: lp:~laurynas-biveinis/percona-server/tokudb-prepare-scans
Merge into: lp:percona-server/5.6
Diff against target: 137 lines (+69/-2)
4 files modified
sql/handler.h (+38/-0)
sql/opt_range.cc (+12/-0)
sql/records.cc (+12/-2)
sql/sql_executor.cc (+7/-0)
To merge this branch: bzr merge lp:~laurynas-biveinis/percona-server/tokudb-prepare-scans
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+212349@code.launchpad.net

Description of the change

Handler extensions to notify SE of incoming index/range scan. Although ideally any required preparation actions should be added to existing methods (ha_index_init, read_range_first), or perhaps by exploiting ICP better, that's not trivial (e.g. cannot add TokuDB prelocking to ha_index_init if it is expensive, because ha_index_init is called to read few rows too). Investigating such changes is on Tokutek's TODO.

Add new handler methods for notifying storage engine of imminent index
scans, both for reading whole table and ranges. Implements
https://blueprints.launchpad.net/percona-server/+spec/prepare-index-range-scan.

The new handler methods added, no-ops in default implementations:
- prepare_index_scan for imminent index (range-less) scan, called in
rr_index_first, rr_index_last in records.cc, and
join_read_first/join_read_last.
- prepare_range_scan for imminent index range scan, called in
QUICK_SELECT_DESC::get_next.
- prepare_index_key_scan_map and prepare_index_key_scan for imminent
index (range-less) scan with used key part information, called in
join_read_always_key in sql_executor.cc.

http://jenkins.percona.com/job/percona-server-5.6-param/562/

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'sql/handler.h'
--- sql/handler.h 2014-02-27 12:29:47 +0000
+++ sql/handler.h 2014-03-24 06:21:13 +0000
@@ -2311,6 +2311,44 @@
2311 return index_read_last(buf, key, key_len);2311 return index_read_last(buf, key, key_len);
2312 }2312 }
2313public:2313public:
2314
2315 /**
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
2340protected:
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
2350public:
2351
2314 virtual int read_range_first(const key_range *start_key,2352 virtual int read_range_first(const key_range *start_key,
2315 const key_range *end_key,2353 const key_range *end_key,
2316 bool eq_range, bool sorted);2354 bool eq_range, bool sorted);
23172355
=== modified file 'sql/opt_range.cc'
--- sql/opt_range.cc 2014-03-03 17:51:33 +0000
+++ sql/opt_range.cc 2014-03-24 06:21:13 +0000
@@ -10867,6 +10867,18 @@
10867 }10867 }
10868 }10868 }
1086910869
10870 key_range prepare_range_start;
10871 key_range prepare_range_end;
10872
10873 last_range->make_min_endpoint(&prepare_range_start);
10874 last_range->make_max_endpoint(&prepare_range_end);
10875 result = file->prepare_range_scan((last_range->flag & NO_MIN_RANGE)
10876 ? NULL : &prepare_range_start,
10877 (last_range->flag & NO_MAX_RANGE)
10878 ? NULL : &prepare_range_end);
10879 if (result)
10880 DBUG_RETURN(result);
10881
10870 if (last_range->flag & NO_MAX_RANGE) // Read last record10882 if (last_range->flag & NO_MAX_RANGE) // Read last record
10871 {10883 {
10872 int local_error;10884 int local_error;
1087310885
=== modified file 'sql/records.cc'
--- sql/records.cc 2013-08-14 03:57:21 +0000
+++ sql/records.cc 2014-03-24 06:21:13 +0000
@@ -391,8 +391,13 @@
391391
392static int rr_index_first(READ_RECORD *info)392static int rr_index_first(READ_RECORD *info)
393{393{
394 int tmp= info->table->file->ha_index_first(info->record);394 int tmp= info->table->file->prepare_index_scan();
395 info->read_record= rr_index;395 info->read_record= rr_index;
396 if (tmp) {
397 tmp= rr_handle_error(info, tmp);
398 return tmp;
399 }
400 tmp= info->table->file->ha_index_first(info->record);
396 if (tmp)401 if (tmp)
397 tmp= rr_handle_error(info, tmp);402 tmp= rr_handle_error(info, tmp);
398 return tmp;403 return tmp;
@@ -414,8 +419,13 @@
414419
415static int rr_index_last(READ_RECORD *info)420static int rr_index_last(READ_RECORD *info)
416{421{
417 int tmp= info->table->file->ha_index_last(info->record);422 int tmp= info->table->file->prepare_index_scan();
418 info->read_record= rr_index_desc;423 info->read_record= rr_index_desc;
424 if (tmp) {
425 tmp= rr_handle_error(info, tmp);
426 return tmp;
427 }
428 tmp= info->table->file->ha_index_last(info->record);
419 if (tmp)429 if (tmp)
420 tmp= rr_handle_error(info, tmp);430 tmp= rr_handle_error(info, tmp);
421 return tmp;431 return tmp;
422432
=== modified file 'sql/sql_executor.cc'
--- sql/sql_executor.cc 2014-02-17 11:12:40 +0000
+++ sql/sql_executor.cc 2014-03-24 06:21:13 +0000
@@ -2203,6 +2203,9 @@
22032203
2204 if (cp_buffer_from_ref(tab->join->thd, table, ref))2204 if (cp_buffer_from_ref(tab->join->thd, table, ref))
2205 return -1;2205 return -1;
2206 if ((error= table->file->prepare_index_key_scan_map(tab->ref.key_buff,
2207 make_prev_keypart_map(tab->ref.key_parts))))
2208 return report_handler_error(table, error);
2206 if ((error= table->file->ha_index_read_map(table->record[0],2209 if ((error= table->file->ha_index_read_map(table->record[0],
2207 tab->ref.key_buff,2210 tab->ref.key_buff,
2208 make_prev_keypart_map(tab->ref.key_parts),2211 make_prev_keypart_map(tab->ref.key_parts),
@@ -2529,6 +2532,8 @@
2529 (void) report_handler_error(table, error);2532 (void) report_handler_error(table, error);
2530 return 1;2533 return 1;
2531 }2534 }
2535 if ((error= tab->table->file->prepare_index_scan()))
2536 return 1;
2532 if ((error= tab->table->file->ha_index_first(tab->table->record[0])))2537 if ((error= tab->table->file->ha_index_first(tab->table->record[0])))
2533 {2538 {
2534 if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)2539 if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
@@ -2567,6 +2572,8 @@
2567 (void) report_handler_error(table, error);2572 (void) report_handler_error(table, error);
2568 return 1;2573 return 1;
2569 }2574 }
2575 if ((error= table->file->prepare_index_scan()))
2576 return report_handler_error(table, error);
2570 if ((error= tab->table->file->ha_index_last(tab->table->record[0])))2577 if ((error= tab->table->file->ha_index_last(tab->table->record[0])))
2571 return report_handler_error(table, error);2578 return report_handler_error(table, error);
2572 return 0;2579 return 0;

Subscribers

People subscribed via source and target branches