Skip to content

Commit

Permalink
0.1: SQL-level System Versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Fiala authored and midenok committed May 5, 2017
1 parent 14bdfa8 commit be6f2d3
Show file tree
Hide file tree
Showing 115 changed files with 4,055 additions and 1,101 deletions.
10 changes: 10 additions & 0 deletions include/mysql_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ enum enum_indicator_type
#define FIELD_FLAGS_COLUMN_FORMAT_MASK (3U << FIELD_FLAGS_COLUMN_FORMAT)
#define FIELD_IS_DROPPED (1U << 26) /* Intern: Field is being dropped */

#define GENERATED_ROW_START_FLAG (1 << 27) /* autogenerated column declared with
`generated always at row start`
(see II.a SQL Standard) */
#define GENERATED_ROW_END_FLAG (1 << 28) /* autogenerated column declared with
`generated always at row end`
(see II.a SQL Standard).*/
#define WITHOUT_SYSTEM_VERSIONING_FLAG (1 << 29) /* column that doesn't support
system versioning when table
itself supports it*/

#define REFRESH_GRANT (1ULL << 0) /* Refresh grant tables */
#define REFRESH_LOG (1ULL << 1) /* Start on new log file */
#define REFRESH_TABLES (1ULL << 2) /* close all tables */
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/extra/binlog_tests/blackhole.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ drop table if exists t1,t2;
--enable_warnings

CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Period_ smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
) ENGINE=blackhole;

INSERT INTO t1 VALUES (9410,9412);

select period from t1;
select period_ from t1;
select * from t1;
select t1.* from t1;

Expand Down
76 changes: 38 additions & 38 deletions mysql-test/include/common-tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ drop table if exists t1,t2,t3,t4;
--enable_warnings

CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Period_ smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
);

INSERT INTO t1 VALUES (9410,9412);

select period from t1;
select period_ from t1;
select * from t1;
select t1.* from t1;

Expand Down Expand Up @@ -1349,7 +1349,7 @@ select fld1,fld3 from t2 where fld1 like "25050_";
select distinct companynr from t2;
select distinct companynr from t2 order by companynr;
select distinct companynr from t2 order by companynr desc;
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%";
select distinct t2.fld3,period_ from t2,t1 where companynr=37 and fld3 like "O%";

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

create table t3 (
period int not null,
period_ int not null,
name char(32) not null,
companynr int not null,
price double(11,0),
price2 double(11,0),
key (period),
key (period_),
key (name)
);

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

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

explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
explain select * from t3 as t1,t3 where t1.period_=t3.period_ order by t3.period_;
explain select * from t3 as t1,t3 where t1.period_=t3.period_ order by t3.period_ limit 10;
explain select * from t3 as t1,t3 where t1.period_=t3.period_ order by t1.period_ limit 10;

#
# Search with a constant table.
#

select period from t1;
select period from t1 where period=1900;
select fld3,period from t1,t2 where fld1 = 011401 order by period;
select period_ from t1;
select period_ from t1 where period_=1900;
select fld3,period_ from t1,t2 where fld1 = 011401 order by period_;

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

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

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

#
# Search with a constant table and several rows from another table
#

select fld3,period from t2,t1 where companynr*10 = 37*10;
select fld3,period_ from t2,t1 where companynr*10 = 37*10;

#
# Search with a table reference and without a key.
# t3 will be the main table.
#

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;
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;

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

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;
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;

#
# We need another table for join stuff..
Expand Down Expand Up @@ -1588,18 +1588,18 @@ explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=
# each record
#

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;
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;

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;
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;

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;
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;

#
# Test of many parenthesis levels
#

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);
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)));
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);
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)));

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;

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

select sum(Period)/count(*) from t1;
select sum(Period_)/count(*) from t1;
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;
select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg;

Expand Down Expand Up @@ -1747,13 +1747,13 @@ select max(t2nr) from t3 where price=983543950;
# Test of alias
#

select t1.period from t3 = t1 limit 1;
select t1.period from t1 as t1 limit 1;
select t1.period as "Nuvarande period" from t1 as t1 limit 1;
select period as ok_period from t1 limit 1;
select period as ok_period from t1 group by ok_period limit 1;
select t1.period_ from t3 = t1 limit 1;
select t1.period_ from t1 as t1 limit 1;
select t1.period_ as "Nuvarande period_" from t1 as t1 limit 1;
select period_ as ok_period from t1 limit 1;
select period_ as ok_period from t1 group by ok_period limit 1;
select 1+1 as summa from t1 group by summa limit 1;
select period as "Nuvarande period" from t1 group by "Nuvarande period" limit 1;
select period_ as "Nuvarande period_" from t1 group by "Nuvarande period_" limit 1;

#
# Some simple show commands
Expand Down
59 changes: 59 additions & 0 deletions mysql-test/r/auto_increment.result
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,62 @@ pk
-5
1
drop table t1;
#
# System Versioning Support
#
#
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;
CREATE TABLE T1(id INT UNSIGNED AUTO_INCREMENT, x INT UNSIGNED, y INT UNSIGNED, PRIMARY KEY (id));
INSERT INTO t1(x, y) VALUES(1, 11);
INSERT INTO T1(x, y) VALUES(1, 11);
INSERT INTO t1(x, y) VALUES(2, 12);
INSERT INTO T1(x, y) VALUES(2, 12);
INSERT INTO t1(x, y) VALUES(3, 13);
INSERT INTO T1(x, y) VALUES(3, 13);
INSERT INTO t1(x, y) VALUES(4, 14);
INSERT INTO T1(x, y) VALUES(4, 14);
INSERT INTO t1(x, y) VALUES(5, 15);
INSERT INTO T1(x, y) VALUES(5, 15);
INSERT INTO t1(x, y) VALUES(6, 16);
INSERT INTO T1(x, y) VALUES(6, 16);
INSERT INTO t1(x, y) VALUES(7, 17);
INSERT INTO T1(x, y) VALUES(7, 17);
INSERT INTO t1(x, y) VALUES(8, 18);
INSERT INTO T1(x, y) VALUES(8, 18);
INSERT INTO t1(x, y) VALUES(9, 19);
INSERT INTO T1(x, y) VALUES(9, 19);
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);
t1.x = T1.x AND t1.y = T1.y x y x y
1 1 11 1 11
1 2 12 2 12
1 3 13 3 13
1 4 14 4 14
1 5 15 5 15
1 6 16 6 16
1 7 17 7 17
1 8 18 8 18
1 9 19 9 19
DELETE FROM t1 WHERE x=2;
DELETE FROM T1 WHERE x=2;
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);
t1.x = T1.x AND t1.y = T1.y x y x y
1 1 11 1 11
1 3 13 3 13
1 4 14 4 14
1 5 15 5 15
1 6 16 6 16
1 7 17 7 17
1 8 18 8 18
1 9 19 9 19
DELETE FROM t1 WHERE x>7;
DELETE FROM T1 WHERE x>7;
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);
t1.x = T1.x AND t1.y = T1.y x y x y
1 1 11 1 11
1 3 13 3 13
1 4 14 4 14
1 5 15 5 15
1 6 16 6 16
1 7 17 7 17
DROP TABLE t1;
DROP TABLE T1;
Loading

0 comments on commit be6f2d3

Please sign in to comment.