summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Malyavin <nikitamalyavin@gmail.com>2019-11-23 01:19:06 +1000
committerNikita Malyavin <nikitamalyavin@gmail.com>2020-01-21 20:35:05 +1000
commitc2a198e034fb53018b35f963a81215ec7eb31d43 (patch)
tree617c169eda95ef18a72d69caa7517c46f57ae76b
parentc528bbe4584a2d52626b0fbd5a8b3955c4049b39 (diff)
downloadmariadb-git-c2a198e034fb53018b35f963a81215ec7eb31d43.tar.gz
move overlaps check to a separate function
-rw-r--r--sql/handler.cc37
-rw-r--r--sql/table.cc9
-rw-r--r--sql/table.h9
3 files changed, 23 insertions, 32 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index d46a02f33a3..f90b7ccd828 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -6991,18 +6991,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;
}
@@ -7045,32 +7045,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;
diff --git a/sql/table.cc b/sql/table.cc
index 7808812b12e..76fee61d20b 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -8628,6 +8628,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()
{
diff --git a/sql/table.h b/sql/table.h
index 7043df7f76a..9a3ae7bd109 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -807,7 +807,7 @@ struct TABLE_SHARE
#endif
/**
- System versioning support.
+ System versioning and application-time periods support.
*/
struct period_info_t
{
@@ -1641,6 +1641,13 @@ public:
int period_make_insert(Item *src, Field *dst);
int insert_portion_of_time(THD *thd, const vers_select_conds_t &period_conds,
ha_rows *rows_inserted);
+ /*
+ @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);
bool vers_check_update(List<Item> &items);
int delete_row();