Commit 87c2db37 authored by Nikita Malyavin's avatar Nikita Malyavin

get rid of a cycle

parent bba4488a
......@@ -7002,49 +7002,39 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
if (error)
return error;
for (int run= 0; run < 2; run++)
{
if (run == 0)
{
error = handler->ha_index_read_map(record_buffer,
check_overlaps_buffer,
key_part_map((1 << key_parts) - 1),
HA_READ_KEY_OR_PREV);
if (error == HA_ERR_KEY_NOT_FOUND)
continue;
}
else
{
error = handler->ha_index_next(record_buffer);
if (error == HA_ERR_END_OF_FILE)
continue;
}
if (error)
{
handler->ha_index_end();
return error;
}
auto old_row_found= [is_update, old_data, record_buffer, this](){
/* 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. */
if (is_update && memcmp(old_data + table->s->null_bytes,
return is_update && memcmp(old_data + table->s->null_bytes,
record_buffer + table->s->null_bytes,
table->s->reclength - table->s->null_bytes) == 0)
{
continue;
}
table->s->reclength - table->s->null_bytes) == 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;
}
}
error= handler->ha_index_end();
if (error)
return error;
error = handler->ha_index_read_map(record_buffer,
check_overlaps_buffer,
key_part_map((1 << key_parts) - 1),
HA_READ_KEY_OR_PREV);
if (!error && !old_row_found()
&& table->check_period_overlaps(key_info, key_info,
new_data, record_buffer) == 0)
error= HA_ERR_FOUND_DUPP_KEY;
if (!error || error == HA_ERR_KEY_NOT_FOUND)
error = handler->ha_index_next(record_buffer);
if (!error && !old_row_found()
&& table->check_period_overlaps(key_info, key_info,
new_data, record_buffer) == 0)
error= HA_ERR_FOUND_DUPP_KEY;
if (error == HA_ERR_END_OF_FILE)
error= 0;
int end_error= handler->ha_index_end();
if (error || end_error)
return error ? error : end_error;
}
return 0;
}
......
......@@ -896,3 +896,45 @@ bool key_buf_cmp(KEY *key_info, uint used_key_parts,
}
return FALSE;
}
int key_period_compare_bases(const KEY &lhs_key, const KEY &rhs_key,
const uchar *lhs, const uchar *rhs)
{
uint base_part_nr= lhs_key.user_defined_key_parts - 2;
int cmp_res= 0;
for (uint part_nr= 0; !cmp_res && part_nr < base_part_nr; part_nr++)
{
Field *f= lhs_key.key_part[part_nr].field;
cmp_res= f->cmp(f->ptr_in_record(lhs),
rhs_key.key_part[part_nr].field->ptr_in_record(rhs));
}
return cmp_res;
}
int key_period_compare_periods(const KEY &lhs_key, const KEY &rhs_key,
const uchar *lhs, const uchar *rhs)
{
uint base_part_nr= lhs_key.user_defined_key_parts - 2;
Field *lhs_fields[]= {lhs_key.key_part[base_part_nr].field,
lhs_key.key_part[base_part_nr + 1].field};
Field *rhs_fields[]= {rhs_key.key_part[base_part_nr].field,
rhs_key.key_part[base_part_nr + 1].field};
int 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++)
{
cmp[i][j]= lhs_fields[0]->cmp(lhs_fields[i]->ptr_in_record(lhs),
rhs_fields[j]->ptr_in_record(rhs));
}
}
bool overlaps = (cmp[0][0] <= 0 && cmp[1][0] > 0)
|| (cmp[0][0] >= 0 && cmp[0][1] < 0);
return overlaps ? 0 : cmp[0][0];
}
\ No newline at end of file
......@@ -40,5 +40,9 @@ bool key_buf_cmp(KEY *key_info, uint used_key_parts,
const uchar *key1, const uchar *key2);
extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
int key_tuple_cmp(KEY_PART_INFO *part, uchar *key1, uchar *key2, uint tuple_length);
int key_period_compare_bases(const KEY &lhs_key, const KEY &rhs_key,
const uchar *lhs, const uchar *rhs);
int key_period_compare_periods(const KEY &lhs_key, const KEY &rhs_key,
const uchar *lhs, const uchar *rhs);
#endif /* KEY_INCLUDED */
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