Commit 26f299ce authored by Nikita Malyavin's avatar Nikita Malyavin

remove lambda. fix comments & docs. fix DBUG_ASSERTs

parent 6e41e833
......@@ -6986,6 +6986,7 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
+ table_share->reclength);
auto *record_buffer= check_overlaps_buffer + table_share->max_unique_length;
auto *handler= this;
// handler->inited can be NONE on INSERT
if (handler->inited != NONE)
{
create_lookup_handler();
......@@ -7023,23 +7024,6 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
if (error)
return error;
auto old_row_found= [is_update, old_data, record_buffer, this, handler](){
if (!is_update)
return false;
/* In case of update it could appear that the nearest neighbour is
* a record we are updating. It means, that there are no overlaps
* from this side.
*
* An assumption is made that during update we always have the last
* fetched row in old_data. Therefore, comparing ref's is enough
* */
DBUG_ASSERT(handler != this && inited != NONE);
DBUG_ASSERT(ref_length == handler->ref_length);
handler->position(record_buffer);
return memcmp(ref, handler->ref, ref_length) == 0;
};
error= handler->ha_start_keyread(key_nr);
DBUG_ASSERT(!error);
......@@ -7049,8 +7033,8 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
key_copy(check_overlaps_buffer, new_data, &key_info, 0);
/* Copy period_end to period_start.
* the value in period_end field is not significant, but anyway let's leave
* it defined to avoid uninitialized memory access
the value in period_end field is not significant, but anyway let's leave
it defined to avoid uninitialized memory access
*/
memcpy(check_overlaps_buffer + key_base_length,
check_overlaps_buffer + key_base_length + period_field_length,
......@@ -7062,8 +7046,23 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
key_part_map((1 << key_parts) - 1),
HA_READ_BEFORE_KEY);
if (!error && old_row_found())
if (!error && is_update)
{
/* In case of update it could happen that the nearest neighbour is
a record we are updating. It means, that there are no overlaps
from this side.
An assumption is made that during update we always have the last
fetched row in old_data. Therefore, comparing ref's is enough
*/
DBUG_ASSERT(handler != this);
DBUG_ASSERT(inited != NONE);
DBUG_ASSERT(ref_length == handler->ref_length);
handler->position(record_buffer);
if (memcmp(ref, handler->ref, ref_length) == 0)
error= handler->ha_index_prev(record_buffer);
}
if (!error && table->check_period_overlaps(key_info, key_info,
new_data, record_buffer) == 0)
......@@ -7085,7 +7084,10 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
// Restore keyread of this handler, if it was enabled
if (old_this_keyread < MAX_KEY)
DBUG_ASSERT(this->ha_start_keyread(old_this_keyread) == 0);
{
error= this->ha_start_keyread(old_this_keyread);
DBUG_ASSERT(error == 0);
}
return error;
}
......
......@@ -899,6 +899,12 @@ bool key_buf_cmp(KEY *key_info, uint used_key_parts,
}
/**
Compare base parts (not including the period) of keys with period
@return -1, lhs less than rhs
0, lhs equals rhs
1, lhs more than rhs
*/
int key_period_compare_bases(const KEY &lhs_key, const KEY &rhs_key,
const uchar *lhs, const uchar *rhs)
{
......@@ -914,6 +920,12 @@ int key_period_compare_bases(const KEY &lhs_key, const KEY &rhs_key,
return cmp_res;
}
/**
Compare periods of two keys
@return -1, lhs preceeds rhs
0, lhs overlaps rhs
1, lhs succeeds rhs
*/
int key_period_compare_periods(const KEY &lhs_key, const KEY &rhs_key,
const uchar *lhs, const uchar *rhs)
{
......
......@@ -8617,6 +8617,12 @@ void TABLE::evaluate_update_default_function()
DBUG_VOID_RETURN;
}
/**
Compare two keys with periods
@return -1, lhs precedes rhs
0, lhs overlaps rhs
1, lhs succeeds rhs
*/
int TABLE::check_period_overlaps(const KEY &lhs_key, const KEY &rhs_key,
const uchar *lhs, const uchar *rhs)
{
......
......@@ -1635,12 +1635,6 @@ struct TABLE
int insert_portion_of_time(THD *thd, const vers_select_conds_t &period_conds,
ha_rows *rows_inserted);
bool vers_check_update(List<Item> &items);
/*
@return -1, lhs precedes rhs
0, lhs overlaps rhs
1, lhs succeeds rhs
*/
static int check_period_overlaps(const KEY &lhs_key, const KEY &rhs_key,
const uchar *lhs, const uchar *rhs);
int delete_row();
......
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