Skip to content

Commit 3316a54

Browse files
committed
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()
1 parent 65da564 commit 3316a54

File tree

4 files changed

+163
-99
lines changed

4 files changed

+163
-99
lines changed

sql/records.cc

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,8 @@ static int rr_handle_error(READ_RECORD *info, int error)
400400
static int rr_quick(READ_RECORD *info)
401401
{
402402
int tmp;
403-
while ((tmp= info->select->quick->get_next()))
404-
{
403+
if ((tmp= info->select->quick->get_next()))
405404
tmp= rr_handle_error(info, tmp);
406-
break;
407-
}
408405
return tmp;
409406
}
410407

@@ -427,16 +424,14 @@ static int rr_index_first(READ_RECORD *info)
427424
int tmp;
428425
// tell handler that we are doing an index scan
429426
if ((tmp = info->table->file->prepare_index_scan()))
430-
{
431-
tmp= rr_handle_error(info, tmp);
432-
return tmp;
433-
}
427+
goto err;
434428

435-
tmp= info->table->file->ha_index_first(info->record());
436429
info->read_record_func= rr_index;
437-
if (tmp)
438-
tmp= rr_handle_error(info, tmp);
439-
return tmp;
430+
if (!(tmp= info->table->file->ha_index_first(info->record())))
431+
return tmp;
432+
433+
err:
434+
return rr_handle_error(info, tmp);
440435
}
441436

442437

@@ -455,9 +450,9 @@ static int rr_index_first(READ_RECORD *info)
455450

456451
static int rr_index_last(READ_RECORD *info)
457452
{
458-
int tmp= info->table->file->ha_index_last(info->record());
453+
int tmp;
459454
info->read_record_func= rr_index_desc;
460-
if (tmp)
455+
if ((tmp= info->table->file->ha_index_last(info->record())))
461456
tmp= rr_handle_error(info, tmp);
462457
return tmp;
463458
}

sql/sql_join_cache.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,12 +2146,12 @@ enum_nested_loop_state JOIN_CACHE::join_records(bool skip_last)
21462146

21472147
if (!join_tab->first_unmatched)
21482148
{
2149-
bool pfs_batch_update= join_tab->pfs_batch_update(join);
2150-
if (pfs_batch_update)
2149+
DBUG_ASSERT(join_tab->cached_pfs_batch_update == join_tab->pfs_batch_update());
2150+
if (join_tab->cached_pfs_batch_update)
21512151
join_tab->table->file->start_psi_batch_mode();
21522152
/* Find all records from join_tab that match records from join buffer */
21532153
rc= join_matching_records(skip_last);
2154-
if (pfs_batch_update)
2154+
if (join_tab->cached_pfs_batch_update)
21552155
join_tab->table->file->end_psi_batch_mode();
21562156
if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS)
21572157
goto finish;
@@ -2321,7 +2321,8 @@ enum_nested_loop_state JOIN_CACHE::join_matching_records(bool skip_last)
23212321
if ((rc= join_tab_execution_startup(join_tab)) < 0)
23222322
goto finish2;
23232323

2324-
join_tab->build_range_rowid_filter_if_needed();
2324+
if (join_tab->need_to_build_rowid_filter)
2325+
join_tab->build_range_rowid_filter();
23252326

23262327
/* Prepare to retrieve all records of the joined table */
23272328
if (unlikely((error= join_tab_scan->open())))

0 commit comments

Comments
 (0)