Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
10.4.14, 10.5
-
Windows
Description
I use a bi-temp table (application time period and system time versioning) with an autoincrement id. If I update a record with "FOR PORTION OF" the part of id in primary key changes automatically. I think, this isn't correct. The id expresses the associated business fact.
Example and reproduction:
Starting Position:
Create the table:
CREATE TABLE `t1` ( |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
`price_for` varchar(100) DEFAULT NULL, |
`price` integer DEFAULT NULL, |
`date_1` date NOT NULL, |
`date_2` date NOT NULL, |
`row_start` timestamp(6) GENERATED ALWAYS AS ROW START, |
`row_end` timestamp(6) GENERATED ALWAYS AS ROW END, |
PRIMARY KEY (`id`,`date_2`,`row_start`,`row_end`), |
PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`), |
PERIOD FOR `application_time` (`date_1`, `date_2`) |
) WITH SYSTEM VERSIONING |
Enter one record, result
Behaviour of using FOR PORTION OF:
Update query:
update t1 for portion of application_time |
from '2021-04-01' to '9999-12-31' |
set id=1, price = 6000 |
where id=1 |
Given result:
Line 1 is old versiones record as expected. Line 3 is new price record under id = 1 valid from 2021-04-01 as expected. But the old price which was valid between 2021-01-01 and 2021-04-01 has been stored automatically under id = 2 instead of id = 1 (it's still the price for procuct 1)
Think what would happen if this table had a related child table. The fk reference is broken.
Expected result:
Query to produce it manually:
update t2 |
set id = 1, date_2 = '2021-04-01' |
where id = 1; |
|
insert into t2 (id, date_1, date_2, price_for, price) |
values (1, '2021-04-01', '9999-12-31', 'Product 1', 6000); |
expected result:
Now, the same business fact has a correct application time line and the change is versioned correctly.
Attachments
Issue Links
- relates to
-
MDEV-33346 Improve application-time periods documentation
-
- Open
-
Activity
Field | Original Value | New Value |
---|---|---|
Fix Version/s | 10.4 [ 22408 ] | |
Fix Version/s | 10.5 [ 23123 ] |
Affects Version/s | 10.5 [ 23123 ] |
Assignee | Nikita Malyavin [ nikitamalyavin ] |
Description |
I use a bi-temp table (application time period and system time versioning) with an autoincrement id. If I update a record with "FOR PORTION OF" the part of id in primary key changes automatically. I think, this isn't correct. The id expresses the associated business fact.
*Example and reproduction:* Starting Position: Create the table: {code:SQL} CREATE TABLE `t1` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `price_for` varchar(100) DEFAULT NULL, `price` integer DEFAULT NULL, `date_1` date NOT NULL, `date_2` date NOT NULL, `row_start` timestamp(6) GENERATED ALWAYS AS ROW START, `row_end` timestamp(6) GENERATED ALWAYS AS ROW END, PRIMARY KEY (`id`,`date_2`,`row_start`,`row_end`), PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`), PERIOD FOR `application_time` (`date_1`, `date_2`) ) WITH SYSTEM VERSIONING {code} Enter one record, result !Starting_point.png! *Behaviour of using FOR PORTION OF:* Update query: {code:SQL} update t1 for portion of application_time from '2021-04-01' to '9999-12-31' set id=1, price = 6000 where id=1 {code} Given result: !given_result.png! Line 1 is old versiones record as expected. Line 3 is new price record under id = 1 valid from 2021-04-01 as expected. But the old price which was valid between 2021-01-01 and 2021-04-01 has been stored automatically under id = 2 instead of id = 1 (it's still the price for procuct 1) Think what would happen if this table had a related child table. The fk reference is broken. *Expected result:* Query to produce it manually: {code:SQL} update t2 set id = 1, date_2 = '2021-04-01' where id = 1; insert into t2 (id, date_1, date_2, price_for, price) values (1, '2021-04-01', '9999-12-31', 'Product 1', 6000); {code} expected result: !expected_result.png! Now, the same business fact has a correct application time line and the change is versioned correctly. |
I use a bi-temp table (application time period and system time versioning) with an autoincrement id. If I update a record with "FOR PORTION OF" the part of id in primary key changes automatically. I think, this isn't correct. The id expresses the associated business fact.
*Example and reproduction:* Starting Position: Create the table: {code:sql} CREATE TABLE `t1` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `price_for` varchar(100) DEFAULT NULL, `price` integer DEFAULT NULL, `date_1` date NOT NULL, `date_2` date NOT NULL, `row_start` timestamp(6) GENERATED ALWAYS AS ROW START, `row_end` timestamp(6) GENERATED ALWAYS AS ROW END, PRIMARY KEY (`id`,`date_2`,`row_start`,`row_end`), PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`), PERIOD FOR `application_time` (`date_1`, `date_2`) ) WITH SYSTEM VERSIONING {code} Enter one record, result !Starting_point.png! *Behaviour of using FOR PORTION OF:* Update query: {code:SQL} update t1 for portion of application_time from '2021-04-01' to '9999-12-31' set id=1, price = 6000 where id=1 {code} Given result: !given_result.png! Line 1 is old versiones record as expected. Line 3 is new price record under id = 1 valid from 2021-04-01 as expected. But the old price which was valid between 2021-01-01 and 2021-04-01 has been stored automatically under id = 2 instead of id = 1 (it's still the price for procuct 1) Think what would happen if this table had a related child table. The fk reference is broken. *Expected result:* Query to produce it manually: {code:SQL} update t2 set id = 1, date_2 = '2021-04-01' where id = 1; insert into t2 (id, date_1, date_2, price_for, price) values (1, '2021-04-01', '9999-12-31', 'Product 1', 6000); {code} expected result: !expected_result.png! Now, the same business fact has a correct application time line and the change is versioned correctly. |
Description |
I use a bi-temp table (application time period and system time versioning) with an autoincrement id. If I update a record with "FOR PORTION OF" the part of id in primary key changes automatically. I think, this isn't correct. The id expresses the associated business fact.
*Example and reproduction:* Starting Position: Create the table: {code:sql} CREATE TABLE `t1` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `price_for` varchar(100) DEFAULT NULL, `price` integer DEFAULT NULL, `date_1` date NOT NULL, `date_2` date NOT NULL, `row_start` timestamp(6) GENERATED ALWAYS AS ROW START, `row_end` timestamp(6) GENERATED ALWAYS AS ROW END, PRIMARY KEY (`id`,`date_2`,`row_start`,`row_end`), PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`), PERIOD FOR `application_time` (`date_1`, `date_2`) ) WITH SYSTEM VERSIONING {code} Enter one record, result !Starting_point.png! *Behaviour of using FOR PORTION OF:* Update query: {code:SQL} update t1 for portion of application_time from '2021-04-01' to '9999-12-31' set id=1, price = 6000 where id=1 {code} Given result: !given_result.png! Line 1 is old versiones record as expected. Line 3 is new price record under id = 1 valid from 2021-04-01 as expected. But the old price which was valid between 2021-01-01 and 2021-04-01 has been stored automatically under id = 2 instead of id = 1 (it's still the price for procuct 1) Think what would happen if this table had a related child table. The fk reference is broken. *Expected result:* Query to produce it manually: {code:SQL} update t2 set id = 1, date_2 = '2021-04-01' where id = 1; insert into t2 (id, date_1, date_2, price_for, price) values (1, '2021-04-01', '9999-12-31', 'Product 1', 6000); {code} expected result: !expected_result.png! Now, the same business fact has a correct application time line and the change is versioned correctly. |
I use a bi-temp table (application time period and system time versioning) with an autoincrement id. If I update a record with "FOR PORTION OF" the part of id in primary key changes automatically. I think, this isn't correct. The id expresses the associated business fact.
*Example and reproduction:* Starting Position: Create the table: {code:sql} CREATE TABLE `t1` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `price_for` varchar(100) DEFAULT NULL, `price` integer DEFAULT NULL, `date_1` date NOT NULL, `date_2` date NOT NULL, `row_start` timestamp(6) GENERATED ALWAYS AS ROW START, `row_end` timestamp(6) GENERATED ALWAYS AS ROW END, PRIMARY KEY (`id`,`date_2`,`row_start`,`row_end`), PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`), PERIOD FOR `application_time` (`date_1`, `date_2`) ) WITH SYSTEM VERSIONING {code} Enter one record, result !Starting_point.png! *Behaviour of using FOR PORTION OF:* Update query: {code:sql} update t1 for portion of application_time from '2021-04-01' to '9999-12-31' set id=1, price = 6000 where id=1 {code} Given result: !given_result.png! Line 1 is old versiones record as expected. Line 3 is new price record under id = 1 valid from 2021-04-01 as expected. But the old price which was valid between 2021-01-01 and 2021-04-01 has been stored automatically under id = 2 instead of id = 1 (it's still the price for procuct 1) Think what would happen if this table had a related child table. The fk reference is broken. *Expected result:* Query to produce it manually: {code:sql} update t2 set id = 1, date_2 = '2021-04-01' where id = 1; insert into t2 (id, date_1, date_2, price_for, price) values (1, '2021-04-01', '9999-12-31', 'Product 1', 6000); {code} expected result: !expected_result.png! Now, the same business fact has a correct application time line and the change is versioned correctly. |
Status | Open [ 1 ] | Confirmed [ 10101 ] |
Workflow | MariaDB v3 [ 120836 ] | MariaDB v4 [ 144351 ] |
Status | Confirmed [ 10101 ] | In Progress [ 3 ] |
Assignee | Nikita Malyavin [ nikitamalyavin ] | Sergei Golubchik [ serg ] |
Status | In Progress [ 3 ] | In Review [ 10002 ] |
Priority | Major [ 3 ] | Critical [ 2 ] |
Assignee | Sergei Golubchik [ serg ] | Nikita Malyavin [ nikitamalyavin ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Summary | Update for portion changes autoincrement key in bi-temp table | Update for portion changes autoincrement key in period table |
Assignee | Nikita Malyavin [ nikitamalyavin ] | Sergei Golubchik [ serg ] |
Status | Stalled [ 10000 ] | In Review [ 10002 ] |
Assignee | Sergei Golubchik [ serg ] | Nikita Malyavin [ nikitamalyavin ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Status | Stalled [ 10000 ] | In Progress [ 3 ] |
Link | This issue relates to MDEV-33346 [ MDEV-33346 ] |
Fix Version/s | 10.5.24 [ 29517 ] | |
Fix Version/s | 10.4 [ 22408 ] | |
Fix Version/s | 10.5 [ 23123 ] | |
Resolution | Fixed [ 1 ] | |
Status | In Progress [ 3 ] | Closed [ 6 ] |
Fix Version/s | 10.6.17 [ 29518 ] | |
Fix Version/s | 10.11.7 [ 29519 ] | |
Fix Version/s | 11.1.4 [ 29024 ] | |
Fix Version/s | 11.2.3 [ 29521 ] | |
Fix Version/s | 11.3.2 [ 29522 ] | |
Fix Version/s | 10.10.7 [ 29018 ] | |
Fix Version/s | 10.9.8 [ 29015 ] | |
Fix Version/s | 10.8.8 [ 28518 ] |
Fix Version/s | 10.5.25 [ 29626 ] | |
Fix Version/s | 10.6.18 [ 29627 ] | |
Fix Version/s | 10.11.8 [ 29630 ] | |
Fix Version/s | 11.0.6 [ 29628 ] | |
Fix Version/s | 11.1.5 [ 29629 ] | |
Fix Version/s | 11.2.4 [ 29631 ] | |
Fix Version/s | 10.8.8 [ 28518 ] | |
Fix Version/s | 10.9.8 [ 29015 ] | |
Fix Version/s | 10.10.7 [ 29018 ] | |
Fix Version/s | 11.1.4 [ 29024 ] | |
Fix Version/s | 10.5.24 [ 29517 ] | |
Fix Version/s | 10.6.17 [ 29518 ] | |
Fix Version/s | 10.11.7 [ 29519 ] | |
Fix Version/s | 11.2.3 [ 29521 ] |
I'd expect the correct key definition should be
but this doesn't help, new auto-inc value is still generated.