Skip to content

Commit be6f2d3

Browse files
Daniel Fialamidenok
authored andcommitted
0.1: SQL-level System Versioning
1 parent 14bdfa8 commit be6f2d3

File tree

115 files changed

+4055
-1101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+4055
-1101
lines changed

include/mysql_com.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ enum enum_indicator_type
184184
#define FIELD_FLAGS_COLUMN_FORMAT_MASK (3U << FIELD_FLAGS_COLUMN_FORMAT)
185185
#define FIELD_IS_DROPPED (1U << 26) /* Intern: Field is being dropped */
186186

187+
#define GENERATED_ROW_START_FLAG (1 << 27) /* autogenerated column declared with
188+
`generated always at row start`
189+
(see II.a SQL Standard) */
190+
#define GENERATED_ROW_END_FLAG (1 << 28) /* autogenerated column declared with
191+
`generated always at row end`
192+
(see II.a SQL Standard).*/
193+
#define WITHOUT_SYSTEM_VERSIONING_FLAG (1 << 29) /* column that doesn't support
194+
system versioning when table
195+
itself supports it*/
196+
187197
#define REFRESH_GRANT (1ULL << 0) /* Refresh grant tables */
188198
#define REFRESH_LOG (1ULL << 1) /* Start on new log file */
189199
#define REFRESH_TABLES (1ULL << 2) /* close all tables */

mysql-test/extra/binlog_tests/blackhole.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ drop table if exists t1,t2;
1717
--enable_warnings
1818

1919
CREATE TABLE t1 (
20-
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
20+
Period_ smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
2121
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
2222
) ENGINE=blackhole;
2323

2424
INSERT INTO t1 VALUES (9410,9412);
2525

26-
select period from t1;
26+
select period_ from t1;
2727
select * from t1;
2828
select t1.* from t1;
2929

mysql-test/include/common-tests.inc

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ drop table if exists t1,t2,t3,t4;
1414
--enable_warnings
1515

1616
CREATE TABLE t1 (
17-
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
17+
Period_ smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
1818
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
1919
);
2020

2121
INSERT INTO t1 VALUES (9410,9412);
2222

23-
select period from t1;
23+
select period_ from t1;
2424
select * from t1;
2525
select t1.* from t1;
2626

@@ -1349,7 +1349,7 @@ select fld1,fld3 from t2 where fld1 like "25050_";
13491349
select distinct companynr from t2;
13501350
select distinct companynr from t2 order by companynr;
13511351
select distinct companynr from t2 order by companynr desc;
1352-
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%";
1352+
select distinct t2.fld3,period_ from t2,t1 where companynr=37 and fld3 like "O%";
13531353

13541354
select distinct fld3 from t2 where companynr = 34 order by fld3;
13551355
select distinct fld3 from t2 limit 10;
@@ -1362,26 +1362,26 @@ select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10;
13621362
# make a big table.
13631363

13641364
create table t3 (
1365-
period int not null,
1365+
period_ int not null,
13661366
name char(32) not null,
13671367
companynr int not null,
13681368
price double(11,0),
13691369
price2 double(11,0),
1370-
key (period),
1370+
key (period_),
13711371
key (name)
13721372
);
13731373

13741374
--disable_query_log
1375-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1001,"Iranizes",37,5987435,234724);
1376-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1002,"violinist",37,28357832,8723648);
1377-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1003,"extramarital",37,39654943,235872);
1378-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1004,"spates",78,726498,72987523);
1379-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1005,"cloakroom",78,98439034,823742);
1380-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1006,"gazer",101,834598,27348324);
1381-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1007,"hand",154,983543950,29837423);
1382-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1008,"tucked",311,234298,3275892);
1383-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1009,"gems",447,2374834,9872392);
1384-
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1010,"clinker",512,786542,76234234);
1375+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1001,"Iranizes",37,5987435,234724);
1376+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1002,"violinist",37,28357832,8723648);
1377+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1003,"extramarital",37,39654943,235872);
1378+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1004,"spates",78,726498,72987523);
1379+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1005,"cloakroom",78,98439034,823742);
1380+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1006,"gazer",101,834598,27348324);
1381+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1007,"hand",154,983543950,29837423);
1382+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1008,"tucked",311,234298,3275892);
1383+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1009,"gems",447,2374834,9872392);
1384+
INSERT INTO t3 (period_,name,companynr,price,price2) VALUES (1010,"clinker",512,786542,76234234);
13851385
--enable_query_log
13861386

13871387
create temporary table tmp engine = myisam select * from t3;
@@ -1450,47 +1450,47 @@ explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2
14501450
# Some test with ORDER BY and limit
14511451
#
14521452

1453-
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
1454-
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
1455-
explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
1453+
explain select * from t3 as t1,t3 where t1.period_=t3.period_ order by t3.period_;
1454+
explain select * from t3 as t1,t3 where t1.period_=t3.period_ order by t3.period_ limit 10;
1455+
explain select * from t3 as t1,t3 where t1.period_=t3.period_ order by t1.period_ limit 10;
14561456

14571457
#
14581458
# Search with a constant table.
14591459
#
14601460

1461-
select period from t1;
1462-
select period from t1 where period=1900;
1463-
select fld3,period from t1,t2 where fld1 = 011401 order by period;
1461+
select period_ from t1;
1462+
select period_ from t1 where period_=1900;
1463+
select fld3,period_ from t1,t2 where fld1 = 011401 order by period_;
14641464

14651465
#
14661466
# Search with a constant table and several keyparts. (Rows are read only once
14671467
# in the beginning of the search)
14681468
#
14691469

1470-
select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001;
1470+
select fld3,period_ from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period_=1001;
14711471

1472-
explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period;
1472+
explain select fld3,period_ from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period_;
14731473

14741474
#
14751475
# Search with a constant table and several rows from another table
14761476
#
14771477

1478-
select fld3,period from t2,t1 where companynr*10 = 37*10;
1478+
select fld3,period_ from t2,t1 where companynr*10 = 37*10;
14791479

14801480
#
14811481
# Search with a table reference and without a key.
14821482
# t3 will be the main table.
14831483
#
14841484

1485-
select fld3,period,price,price2 from t2,t3 where t2.fld1=t3.t2nr and period >= 1001 and period <= 1002 and t2.companynr = 37 order by fld3,period, price;
1485+
select fld3,period_,price,price2 from t2,t3 where t2.fld1=t3.t2nr and period_ >= 1001 and period_ <= 1002 and t2.companynr = 37 order by fld3,period_, price;
14861486

14871487
#
14881488
# Search with an interval on a table with full key on reference table.
14891489
# Here t2 will be the main table and only records matching the
14901490
# t2nr will be checked.
14911491
#
14921492

1493-
select t2.fld1,fld3,period,price,price2 from t2,t3 where t2.fld1>= 18201 and t2.fld1 <= 18811 and t2.fld1=t3.t2nr and period = 1001 and t2.companynr = 37;
1493+
select t2.fld1,fld3,period_,price,price2 from t2,t3 where t2.fld1>= 18201 and t2.fld1 <= 18811 and t2.fld1=t3.t2nr and period_ = 1001 and t2.companynr = 37;
14941494

14951495
#
14961496
# We need another table for join stuff..
@@ -1588,18 +1588,18 @@ explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=
15881588
# each record
15891589
#
15901590

1591-
select t2.fld1,t2.companynr,fld3,period from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period = 1008;
1591+
select t2.fld1,t2.companynr,fld3,period_ from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period_ = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period_ = 1008;
15921592

1593-
select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t2.fld1 = 38208 or t2.fld1 = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009;
1593+
select t2.fld1,t2.companynr,fld3,period_ from t3,t2 where (t2.fld1 = 38208 or t2.fld1 = 38008) and t2.fld1=t3.t2nr and period_>=1008 and period_<=1009;
15941594

1595-
select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t3.t2nr = 38208 or t3.t2nr = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009;
1595+
select t2.fld1,t2.companynr,fld3,period_ from t3,t2 where (t3.t2nr = 38208 or t3.t2nr = 38008) and t2.fld1=t3.t2nr and period_>=1008 and period_<=1009;
15961596

15971597
#
15981598
# Test of many parenthesis levels
15991599
#
16001600

1601-
select period from t1 where (((period > 0) or period < 10000 or (period = 1900)) and (period=1900 and period <= 1901) or (period=1903 and (period=1903)) and period>=1902) or ((period=1904 or period=1905) or (period=1906 or period>1907)) or (period=1908 and period = 1909);
1602-
select period from t1 where ((period > 0 and period < 1) or (((period > 0 and period < 100) and (period > 10)) or (period > 10)) or (period > 0 and (period > 5 or period > 6)));
1601+
select period_ from t1 where (((period_ > 0) or period_ < 10000 or (period_ = 1900)) and (period_=1900 and period_ <= 1901) or (period_=1903 and (period_=1903)) and period_>=1902) or ((period_=1904 or period_=1905) or (period_=1906 or period_>1907)) or (period_=1908 and period_ = 1909);
1602+
select period_ from t1 where ((period_ > 0 and period_ < 1) or (((period_ > 0 and period_ < 100) and (period_ > 10)) or (period_ > 10)) or (period_ > 0 and (period_ > 5 or period_ > 6)));
16031603

16041604
select a.fld1 from t2 as a,t2 b where ((a.fld1 = 250501 and a.fld1=b.fld1) or a.fld1=250502 or a.fld1=250503 or (a.fld1=250505 and a.fld1<=b.fld1 and b.fld1>=a.fld1)) and a.fld1=b.fld1;
16051605

@@ -1657,7 +1657,7 @@ select t2.fld1,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 grou
16571657
# Calculation with group functions
16581658
#
16591659

1660-
select sum(Period)/count(*) from t1;
1660+
select sum(Period_)/count(*) from t1;
16611661
select companynr,count(price) as "count",sum(price) as "sum" ,abs(sum(price)/count(price)-avg(price)) as "diff",(0+count(price))*companynr as func from t3 group by companynr;
16621662
select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg;
16631663

@@ -1747,13 +1747,13 @@ select max(t2nr) from t3 where price=983543950;
17471747
# Test of alias
17481748
#
17491749

1750-
select t1.period from t3 = t1 limit 1;
1751-
select t1.period from t1 as t1 limit 1;
1752-
select t1.period as "Nuvarande period" from t1 as t1 limit 1;
1753-
select period as ok_period from t1 limit 1;
1754-
select period as ok_period from t1 group by ok_period limit 1;
1750+
select t1.period_ from t3 = t1 limit 1;
1751+
select t1.period_ from t1 as t1 limit 1;
1752+
select t1.period_ as "Nuvarande period_" from t1 as t1 limit 1;
1753+
select period_ as ok_period from t1 limit 1;
1754+
select period_ as ok_period from t1 group by ok_period limit 1;
17551755
select 1+1 as summa from t1 group by summa limit 1;
1756-
select period as "Nuvarande period" from t1 group by "Nuvarande period" limit 1;
1756+
select period_ as "Nuvarande period_" from t1 group by "Nuvarande period_" limit 1;
17571757

17581758
#
17591759
# Some simple show commands

mysql-test/r/auto_increment.result

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,62 @@ pk
537537
-5
538538
1
539539
drop table t1;
540+
#
541+
# System Versioning Support
542+
#
543+
#
544+
CREATE TABLE t1(id INT UNSIGNED AUTO_INCREMENT, x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY (id)) WITH SYSTEM VERSIONING;
545+
CREATE TABLE T1(id INT UNSIGNED AUTO_INCREMENT, x INT UNSIGNED, y INT UNSIGNED, PRIMARY KEY (id));
546+
INSERT INTO t1(x, y) VALUES(1, 11);
547+
INSERT INTO T1(x, y) VALUES(1, 11);
548+
INSERT INTO t1(x, y) VALUES(2, 12);
549+
INSERT INTO T1(x, y) VALUES(2, 12);
550+
INSERT INTO t1(x, y) VALUES(3, 13);
551+
INSERT INTO T1(x, y) VALUES(3, 13);
552+
INSERT INTO t1(x, y) VALUES(4, 14);
553+
INSERT INTO T1(x, y) VALUES(4, 14);
554+
INSERT INTO t1(x, y) VALUES(5, 15);
555+
INSERT INTO T1(x, y) VALUES(5, 15);
556+
INSERT INTO t1(x, y) VALUES(6, 16);
557+
INSERT INTO T1(x, y) VALUES(6, 16);
558+
INSERT INTO t1(x, y) VALUES(7, 17);
559+
INSERT INTO T1(x, y) VALUES(7, 17);
560+
INSERT INTO t1(x, y) VALUES(8, 18);
561+
INSERT INTO T1(x, y) VALUES(8, 18);
562+
INSERT INTO t1(x, y) VALUES(9, 19);
563+
INSERT INTO T1(x, y) VALUES(9, 19);
564+
SELECT t1.x = T1.x AND t1.y = T1.y, t1.x, t1.y, T1.x, T1.y FROM t1 INNER JOIN T1 ON(t1.id = T1.id);
565+
t1.x = T1.x AND t1.y = T1.y x y x y
566+
1 1 11 1 11
567+
1 2 12 2 12
568+
1 3 13 3 13
569+
1 4 14 4 14
570+
1 5 15 5 15
571+
1 6 16 6 16
572+
1 7 17 7 17
573+
1 8 18 8 18
574+
1 9 19 9 19
575+
DELETE FROM t1 WHERE x=2;
576+
DELETE FROM T1 WHERE x=2;
577+
SELECT t1.x = T1.x AND t1.y = T1.y, t1.x, t1.y, T1.x, T1.y FROM t1 INNER JOIN T1 ON(t1.id = T1.id);
578+
t1.x = T1.x AND t1.y = T1.y x y x y
579+
1 1 11 1 11
580+
1 3 13 3 13
581+
1 4 14 4 14
582+
1 5 15 5 15
583+
1 6 16 6 16
584+
1 7 17 7 17
585+
1 8 18 8 18
586+
1 9 19 9 19
587+
DELETE FROM t1 WHERE x>7;
588+
DELETE FROM T1 WHERE x>7;
589+
SELECT t1.x = T1.x AND t1.y = T1.y, t1.x, t1.y, T1.x, T1.y FROM t1 INNER JOIN T1 ON(t1.id = T1.id);
590+
t1.x = T1.x AND t1.y = T1.y x y x y
591+
1 1 11 1 11
592+
1 3 13 3 13
593+
1 4 14 4 14
594+
1 5 15 5 15
595+
1 6 16 6 16
596+
1 7 17 7 17
597+
DROP TABLE t1;
598+
DROP TABLE T1;

0 commit comments

Comments
 (0)