diff options
author | Nikita Malyavin <nikitamalyavin@gmail.com> | 2020-02-21 13:49:14 +1000 |
---|---|---|
committer | Nikita Malyavin <nikitamalyavin@gmail.com> | 2020-02-25 19:49:23 +1000 |
commit | 57e534b02ef072a7e64f6645dc18e3a49bab1c4e (patch) | |
tree | 9e58f3bb9e607e53a4c8df774f3c4b59df077355 | |
parent | 6d82b46a12de536c16992fa3fb1da534c1e43630 (diff) | |
download | mariadb-git-57e534b02ef072a7e64f6645dc18e3a49bab1c4e.tar.gz |
invert period columns order in key
-rw-r--r-- | mysql-test/suite/period/r/overlaps.result | 28 | ||||
-rw-r--r-- | sql/handler.cc | 16 | ||||
-rw-r--r-- | sql/key.cc | 4 | ||||
-rw-r--r-- | sql/sql_table.cc | 2 |
4 files changed, 25 insertions, 25 deletions
diff --git a/mysql-test/suite/period/r/overlaps.result b/mysql-test/suite/period/r/overlaps.result index d337295ac1f..cf980afd7f0 100644 --- a/mysql-test/suite/period/r/overlaps.result +++ b/mysql-test/suite/period/r/overlaps.result @@ -13,13 +13,13 @@ t CREATE TABLE `t` ( insert into t values (1, '2003-01-01', '2003-03-01'), (1, '2003-05-01', '2003-07-01'); insert into t values (1, '2003-02-01', '2003-04-01'); -ERROR 23000: Duplicate entry '1-2003-02-01-2003-04-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-04-01-2003-02-01' for key 'PRIMARY' insert into t values (1, '2003-04-01', '2003-06-01'); -ERROR 23000: Duplicate entry '1-2003-04-01-2003-06-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-06-01-2003-04-01' for key 'PRIMARY' insert into t values (1, '2003-05-15', '2003-06-15'); -ERROR 23000: Duplicate entry '1-2003-05-15-2003-06-15' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-06-15-2003-05-15' for key 'PRIMARY' insert into t values (1, '2003-04-01', '2003-08-01'); -ERROR 23000: Duplicate entry '1-2003-04-01-2003-08-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-08-01-2003-04-01' for key 'PRIMARY' insert into t values (1, '2003-03-01', '2003-05-01'); # expand/shrink period update t set s= '2002-12-01' where s = '2003-01-01'; @@ -39,22 +39,22 @@ id s e 1 2003-05-01 2003-07-01 # intersect left/right, strict inclusion/containment update t set e= '2003-04-01' where s = '2003-01-01'; -ERROR 23000: Duplicate entry '1-2003-01-01-2003-04-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-04-01-2003-01-01' for key 'PRIMARY' update t set s= '2003-04-01' where s = '2003-05-01'; -ERROR 23000: Duplicate entry '1-2003-04-01-2003-07-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-07-01-2003-04-01' for key 'PRIMARY' update t set s= '2003-03-10', e= '2003-03-20' where s = '2003-01-01'; -ERROR 23000: Duplicate entry '1-2003-03-10-2003-03-20' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-03-20-2003-03-10' for key 'PRIMARY' update t set s= '2003-04-01', e= '2003-08-01' where s = '2003-03-01'; -ERROR 23000: Duplicate entry '1-2003-04-01-2003-08-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-08-01-2003-04-01' for key 'PRIMARY' # inclusion/containment with partial match update t set s= '2003-03-01', e= '2003-04-01' where s = '2003-01-01'; -ERROR 23000: Duplicate entry '1-2003-03-01-2003-04-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-04-01-2003-03-01' for key 'PRIMARY' update t set s= '2003-04-01', e= '2003-05-01' where s = '2003-01-01'; -ERROR 23000: Duplicate entry '1-2003-04-01-2003-05-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-05-01-2003-04-01' for key 'PRIMARY' update t set s= '2003-03-01' where s = '2003-05-01'; -ERROR 23000: Duplicate entry '1-2003-03-01-2003-07-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-07-01-2003-03-01' for key 'PRIMARY' update t set e= '2003-05-01' where s = '2003-01-01'; -ERROR 23000: Duplicate entry '1-2003-01-01-2003-05-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-05-01-2003-01-01' for key 'PRIMARY' select * from t where year(s) = 2003; id s e 1 2003-01-01 2003-02-01 @@ -95,7 +95,7 @@ t CREATE TABLE `t` ( insert into t values (1, 1, '2003-03-01', '2003-05-01'); insert into t values (1, 2, '2003-05-01', '2003-07-01'); insert into t values (1, 3, '2003-04-01', '2003-05-01'); -ERROR 23000: Duplicate entry '1-2003-04-01-2003-05-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-05-01-2003-04-01' for key 'PRIMARY' create or replace table t(id int, u int, s date, e date, period for p(s,e), primary key(id, p without overlaps), @@ -120,7 +120,7 @@ insert into t values (1, '2003-01-01', '2003-03-01'), (1, '2003-05-01', '2003-07-01'), (1, '2003-02-01', '2003-04-01'); alter table t add primary key(id, p without overlaps); -ERROR 23000: Duplicate entry '1-2003-02-01-2003-04-01' for key 'PRIMARY' +ERROR 23000: Duplicate entry '1-2003-04-01-2003-02-01' for key 'PRIMARY' # Historical rows are not checked against constraints set @@system_versioning_alter_history= keep; alter table t add system versioning; diff --git a/sql/handler.cc b/sql/handler.cc index 6777e9732c2..f45baf32a79 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -7032,19 +7032,19 @@ 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 + /* Copy period_start to period_end. + the value in period_start 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, period_field_length); - /* Find row with period_start < (period_end of new_data) */ + /* Find row with period_end > (period_start of new_data) */ error = handler->ha_index_read_map(record_buffer, check_overlaps_buffer, - key_part_map((1 << key_parts) - 1), - HA_READ_BEFORE_KEY); + key_part_map((1 << (key_parts - 1)) - 1), + HA_READ_AFTER_KEY); if (!error && is_update) { @@ -7061,11 +7061,11 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data) handler->position(record_buffer); if (memcmp(ref, handler->ref, ref_length) == 0) - error= handler->ha_index_prev(record_buffer); + error= handler->ha_index_next(record_buffer); } if (!error && table->check_period_overlaps(key_info, key_info, - new_data, record_buffer) == 0) + new_data, record_buffer) == 0) error= HA_ERR_FOUND_DUPP_KEY; if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE) diff --git a/sql/key.cc b/sql/key.cc index 0f01774075b..49e97faea22 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -929,8 +929,8 @@ int key_period_compare_bases(const KEY &lhs_key, const KEY &rhs_key, int key_period_compare_periods(const KEY &lhs_key, const KEY &rhs_key, const uchar *lhs, const uchar *rhs) { - uint period_start= lhs_key.user_defined_key_parts - 2; - uint period_end= lhs_key.user_defined_key_parts - 1; + uint period_start= lhs_key.user_defined_key_parts - 1; + uint period_end= lhs_key.user_defined_key_parts - 2; const auto *f= lhs_key.key_part[period_start].field; const uchar *l[]= {lhs_key.key_part[period_start].field->ptr_in_record(lhs), diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 3e02780c9d0..74d28ede25f 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4623,8 +4623,8 @@ static bool append_system_key_parts(THD *thd, HA_CREATE_INFO *create_info, return true; } } - key->columns.push_back(new Key_part_spec(&period_start, 0)); key->columns.push_back(new Key_part_spec(&period_end, 0)); + key->columns.push_back(new Key_part_spec(&period_start, 0)); } } |