Skip to content

Commit 62e7ad2

Browse files
committed
cleanup: move initializations from query exec to prepare time
that is don't call alloc_lookup_buffer() and create_lookup_handler() for every row also, don't call ha_check_overlaps() for every partition, after it was already done on the ha_partition level
1 parent 259fb1c commit 62e7ad2

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

sql/handler.cc

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6737,26 +6737,20 @@ int handler::check_duplicate_long_entries_update(const uchar *new_rec)
67376737
int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
67386738
{
67396739
DBUG_ASSERT(new_data);
6740+
if (this != table->file)
6741+
return 0;
67406742
if (!table_share->period.unique_keys)
67416743
return 0;
67426744
if (table->versioned() && !table->vers_end_field()->is_max())
67436745
return 0;
67446746

6745-
bool is_update= old_data != NULL;
6746-
alloc_lookup_buffer();
6747-
auto *record_buffer= lookup_buffer + table_share->max_unique_length
6748-
+ table_share->null_fields;
6749-
auto *handler= this;
6750-
// handler->inited can be NONE on INSERT
6751-
if (handler->inited != NONE)
6752-
{
6753-
create_lookup_handler();
6754-
handler= lookup_handler;
6747+
const bool is_update= old_data != NULL;
6748+
uchar *record_buffer= lookup_buffer + table_share->max_unique_length
6749+
+ table_share->null_fields;
67556750

6756-
// Needs to compare record refs later is old_row_found()
6757-
if (is_update)
6758-
position(old_data);
6759-
}
6751+
// Needs to compare record refs later is old_row_found()
6752+
if (is_update)
6753+
position(old_data);
67606754

67616755
DBUG_ASSERT(!keyread_enabled());
67626756

@@ -6780,11 +6774,11 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
67806774
continue;
67816775
}
67826776

6783-
error= handler->ha_index_init(key_nr, 0);
6777+
error= lookup_handler->ha_index_init(key_nr, 0);
67846778
if (error)
67856779
return error;
67866780

6787-
error= handler->ha_start_keyread(key_nr);
6781+
error= lookup_handler->ha_start_keyread(key_nr);
67886782
DBUG_ASSERT(!error);
67896783

67906784
const uint period_field_length= key_info.key_part[key_parts - 1].length;
@@ -6801,7 +6795,7 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
68016795
period_field_length);
68026796

68036797
/* Find row with period_end > (period_start of new_data) */
6804-
error = handler->ha_index_read_map(record_buffer, lookup_buffer,
6798+
error = lookup_handler->ha_index_read_map(record_buffer, lookup_buffer,
68056799
key_part_map((1 << (key_parts - 1)) - 1),
68066800
HA_READ_AFTER_KEY);
68076801

@@ -6814,13 +6808,13 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
68146808
An assumption is made that during update we always have the last
68156809
fetched row in old_data. Therefore, comparing ref's is enough
68166810
*/
6817-
DBUG_ASSERT(handler != this);
6811+
DBUG_ASSERT(lookup_handler != this);
68186812
DBUG_ASSERT(inited != NONE);
6819-
DBUG_ASSERT(ref_length == handler->ref_length);
6813+
DBUG_ASSERT(ref_length == lookup_handler->ref_length);
68206814

6821-
handler->position(record_buffer);
6822-
if (memcmp(ref, handler->ref, ref_length) == 0)
6823-
error= handler->ha_index_next(record_buffer);
6815+
lookup_handler->position(record_buffer);
6816+
if (memcmp(ref, lookup_handler->ref, ref_length) == 0)
6817+
error= lookup_handler->ha_index_next(record_buffer);
68246818
}
68256819

68266820
if (!error && table->check_period_overlaps(key_info, new_data, record_buffer))
@@ -6832,10 +6826,10 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
68326826
if (error == HA_ERR_FOUND_DUPP_KEY)
68336827
lookup_errkey= key_nr;
68346828

6835-
int end_error= handler->ha_end_keyread();
6829+
int end_error= lookup_handler->ha_end_keyread();
68366830
DBUG_ASSERT(!end_error);
68376831

6838-
end_error= handler->ha_index_end();
6832+
end_error= lookup_handler->ha_index_end();
68396833
if (!error && end_error)
68406834
error= end_error;
68416835
}
@@ -6919,7 +6913,7 @@ bool handler::prepare_for_row_logging()
69196913
int handler::prepare_for_insert()
69206914
{
69216915
/* Preparation for unique of blob's */
6922-
if (table->s->long_unique_table)
6916+
if (table->s->long_unique_table || table->s->period.unique_keys)
69236917
{
69246918
/*
69256919
When doing a scan we can't use the same handler to check
@@ -6941,9 +6935,8 @@ int handler::ha_write_row(const uchar *buf)
69416935
DBUG_ENTER("handler::ha_write_row");
69426936
DEBUG_SYNC_C("ha_write_row_start");
69436937

6944-
error= ha_check_overlaps(NULL, buf);
6945-
if (unlikely(error))
6946-
goto end;
6938+
if ((error= ha_check_overlaps(NULL, buf)))
6939+
DBUG_RETURN(error);
69476940

69486941
MYSQL_INSERT_ROW_START(table_share->db.str, table_share->table_name.str);
69496942
mark_trx_read_write();
@@ -6976,7 +6969,6 @@ int handler::ha_write_row(const uchar *buf)
69766969
#endif /* WITH_WSREP */
69776970
}
69786971

6979-
end:
69806972
DEBUG_SYNC_C("ha_write_row_end");
69816973
DBUG_RETURN(error);
69826974
}

0 commit comments

Comments
 (0)