Commit bba4488a authored by Nikita Malyavin's avatar Nikita Malyavin

move overlaps check to a separate function

parent b3cdef5f
......@@ -6982,18 +6982,18 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
for (uint key_nr= 0; key_nr < table_share->keys; key_nr++)
{
const KEY *key_info= table->key_info + key_nr;
const uint key_parts= key_info->user_defined_key_parts;
if (!key_info->without_overlaps)
const KEY &key_info= table->key_info[key_nr];
const uint key_parts= key_info.user_defined_key_parts;
if (!key_info.without_overlaps)
continue;
key_copy(check_overlaps_buffer, new_data, key_info, 0);
key_copy(check_overlaps_buffer, new_data, &key_info, 0);
if (is_update)
{
bool key_used= false;
for (uint k= 0; k < key_parts && !key_used; k++)
key_used= bitmap_is_set(table->write_set,
key_info->key_part[k].fieldnr - 1);
key_info.key_part[k].fieldnr - 1);
if (!key_used)
continue;
}
......@@ -7036,32 +7036,7 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
continue;
}
uint period_key_part_nr= key_parts - 2;
int cmp_res= 0;
for (uint part_nr= 0; !cmp_res && part_nr < period_key_part_nr; part_nr++)
{
Field *f= key_info->key_part[part_nr].field;
cmp_res= f->cmp(f->ptr_in_record(new_data),
f->ptr_in_record(record_buffer));
}
if (cmp_res)
continue; /* key is different => no overlaps */
int period_cmp[2][2]= {/* l1 > l2, l1 > r2, r1 > l2, r1 > r2 */};
for (int i= 0; i < 2; i++)
{
for (int j= 0; j < 2; j++)
{
Field *lhs= key_info->key_part[period_key_part_nr + i].field;
Field *rhs= key_info->key_part[period_key_part_nr + j].field;
period_cmp[i][j]= lhs->cmp(lhs->ptr_in_record(new_data),
rhs->ptr_in_record(record_buffer));
}
}
if ((period_cmp[0][0] <= 0 && period_cmp[1][0] > 0)
|| (period_cmp[0][0] >= 0 && period_cmp[0][1] < 0))
if (table->check_period_overlaps(key_info, key_info, new_data, record_buffer) == 0)
{
handler->ha_index_end();
return HA_ERR_FOUND_DUPP_KEY;
......
......@@ -8618,6 +8618,15 @@ void TABLE::evaluate_update_default_function()
DBUG_VOID_RETURN;
}
int TABLE::check_period_overlaps(const KEY &lhs_key, const KEY &rhs_key,
const uchar *lhs, const uchar *rhs)
{
int cmp_res= key_period_compare_bases(lhs_key, rhs_key, lhs, rhs);
if (cmp_res)
return cmp_res;
return key_period_compare_periods(lhs_key, rhs_key, lhs, rhs);
}
void TABLE::vers_update_fields()
{
......
......@@ -803,7 +803,7 @@ struct TABLE_SHARE
#endif
/**
System versioning support.
System versioning and application-time periods support.
*/
struct period_info_t
{
......@@ -1637,6 +1637,13 @@ struct TABLE
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();
void vers_update_fields();
void vers_update_end();
......
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