Commit 3316a54d authored by Monty's avatar Monty

Code cleanups and add some caching of functions to speed up things

Detailed description:
- Added more function comments and fixed types in some old comments
- Removed an outdated comment
- Cleaned up some functions in records.cc
  - Replaced "while" with "if"
  - Reused error code
  - Made functions similar
- Added caching of pfs_batch_update()
- Simplified some rowid_filter code
  - Only call build_range_rowid_filter() if rowid filter will be used
  - Replaced tab->is_rowid_filter_built with need_to_build_rowid_filter.
    We only have to test need_to_build_rowid_filter to know if we have
    to build the filter. Old code needed two tests
  - Added function 'clear_range_rowid_filter' to disable rowid filter.
    Made things simpler as we can now clear all rowid filter variables
    in one place.
- Removed some 'if' in sub_select()
parent 65da5645
...@@ -400,11 +400,8 @@ static int rr_handle_error(READ_RECORD *info, int error) ...@@ -400,11 +400,8 @@ static int rr_handle_error(READ_RECORD *info, int error)
static int rr_quick(READ_RECORD *info) static int rr_quick(READ_RECORD *info)
{ {
int tmp; int tmp;
while ((tmp= info->select->quick->get_next())) if ((tmp= info->select->quick->get_next()))
{
tmp= rr_handle_error(info, tmp); tmp= rr_handle_error(info, tmp);
break;
}
return tmp; return tmp;
} }
...@@ -427,16 +424,14 @@ static int rr_index_first(READ_RECORD *info) ...@@ -427,16 +424,14 @@ static int rr_index_first(READ_RECORD *info)
int tmp; int tmp;
// tell handler that we are doing an index scan // tell handler that we are doing an index scan
if ((tmp = info->table->file->prepare_index_scan())) if ((tmp = info->table->file->prepare_index_scan()))
{ goto err;
tmp= rr_handle_error(info, tmp);
return tmp;
}
tmp= info->table->file->ha_index_first(info->record());
info->read_record_func= rr_index; info->read_record_func= rr_index;
if (tmp) if (!(tmp= info->table->file->ha_index_first(info->record())))
tmp= rr_handle_error(info, tmp); return tmp;
return tmp;
err:
return rr_handle_error(info, tmp);
} }
...@@ -455,9 +450,9 @@ static int rr_index_first(READ_RECORD *info) ...@@ -455,9 +450,9 @@ static int rr_index_first(READ_RECORD *info)
static int rr_index_last(READ_RECORD *info) static int rr_index_last(READ_RECORD *info)
{ {
int tmp= info->table->file->ha_index_last(info->record()); int tmp;
info->read_record_func= rr_index_desc; info->read_record_func= rr_index_desc;
if (tmp) if ((tmp= info->table->file->ha_index_last(info->record())))
tmp= rr_handle_error(info, tmp); tmp= rr_handle_error(info, tmp);
return tmp; return tmp;
} }
......
...@@ -2146,12 +2146,12 @@ enum_nested_loop_state JOIN_CACHE::join_records(bool skip_last) ...@@ -2146,12 +2146,12 @@ enum_nested_loop_state JOIN_CACHE::join_records(bool skip_last)
if (!join_tab->first_unmatched) if (!join_tab->first_unmatched)
{ {
bool pfs_batch_update= join_tab->pfs_batch_update(join); DBUG_ASSERT(join_tab->cached_pfs_batch_update == join_tab->pfs_batch_update());
if (pfs_batch_update) if (join_tab->cached_pfs_batch_update)
join_tab->table->file->start_psi_batch_mode(); join_tab->table->file->start_psi_batch_mode();
/* Find all records from join_tab that match records from join buffer */ /* Find all records from join_tab that match records from join buffer */
rc= join_matching_records(skip_last); rc= join_matching_records(skip_last);
if (pfs_batch_update) if (join_tab->cached_pfs_batch_update)
join_tab->table->file->end_psi_batch_mode(); join_tab->table->file->end_psi_batch_mode();
if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS) if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS)
goto finish; goto finish;
...@@ -2321,7 +2321,8 @@ enum_nested_loop_state JOIN_CACHE::join_matching_records(bool skip_last) ...@@ -2321,7 +2321,8 @@ enum_nested_loop_state JOIN_CACHE::join_matching_records(bool skip_last)
if ((rc= join_tab_execution_startup(join_tab)) < 0) if ((rc= join_tab_execution_startup(join_tab)) < 0)
goto finish2; goto finish2;
join_tab->build_range_rowid_filter_if_needed(); if (join_tab->need_to_build_rowid_filter)
join_tab->build_range_rowid_filter();
/* Prepare to retrieve all records of the joined table */ /* Prepare to retrieve all records of the joined table */
if (unlikely((error= join_tab_scan->open()))) if (unlikely((error= join_tab_scan->open())))
......
This diff is collapsed.
...@@ -423,6 +423,8 @@ typedef struct st_join_table { ...@@ -423,6 +423,8 @@ typedef struct st_join_table {
bool cached_eq_ref_table,eq_ref_table; bool cached_eq_ref_table,eq_ref_table;
bool shortcut_for_distinct; bool shortcut_for_distinct;
bool sorted; bool sorted;
bool cached_pfs_batch_update;
/* /*
If it's not 0 the number stored this field indicates that the index If it's not 0 the number stored this field indicates that the index
scan has been chosen to access the table data and we expect to scan scan has been chosen to access the table data and we expect to scan
...@@ -571,10 +573,11 @@ typedef struct st_join_table { ...@@ -571,10 +573,11 @@ typedef struct st_join_table {
Range_rowid_filter_cost_info *range_rowid_filter_info; Range_rowid_filter_cost_info *range_rowid_filter_info;
/* Rowid filter to be used when joining this join table */ /* Rowid filter to be used when joining this join table */
Rowid_filter *rowid_filter; Rowid_filter *rowid_filter;
/* Becomes true just after the used range filter has been built / filled */ /* True if the plan requires a rowid filter and it's not built yet */
bool is_rowid_filter_built; bool need_to_build_rowid_filter;
void build_range_rowid_filter_if_needed(); void build_range_rowid_filter();
void clear_range_rowid_filter();
void cleanup(); void cleanup();
inline bool is_using_loose_index_scan() inline bool is_using_loose_index_scan()
...@@ -685,7 +688,7 @@ typedef struct st_join_table { ...@@ -685,7 +688,7 @@ typedef struct st_join_table {
double get_examined_rows(); double get_examined_rows();
bool preread_init(); bool preread_init();
bool pfs_batch_update(JOIN *join); bool pfs_batch_update();
bool is_sjm_nest() { return MY_TEST(bush_children); } bool is_sjm_nest() { return MY_TEST(bush_children); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment