Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement multiple table inherits #935

Merged
merged 19 commits into from
Nov 12, 2024
Merged

implement multiple table inherits #935

merged 19 commits into from
Nov 12, 2024

Conversation

jycor
Copy link
Contributor

@jycor jycor commented Nov 8, 2024

This PR supports most of the functionality around PostgreSQL INHERITs.
We just translate create table t1 (...) inherits (t2, t3, ...); to create table t1 like (t2, t3, ...);
Note: MySQL does not support multiple LIKE statements

gms logic: dolthub/go-mysql-server#2738
syntax: dolthub/vitess#375

@jycor jycor requested a review from tbantle22 as a code owner November 8, 2024 09:47
@jycor jycor changed the base branch from james/like to main November 8, 2024 09:48
@jycor jycor removed the request for review from tbantle22 November 8, 2024 09:48
Copy link
Contributor

github-actions bot commented Nov 8, 2024

Main PR
Total 42090 42090
Successful 14213 14396
Failures 27877 27694
Partial Successes1 4717 4703
Main PR
Successful 33.7681% 34.2029%
Failures 66.2319% 65.7971%

${\color{red}Regressions}$

alter_table

QUERY:          drop table child;
RECEIVED ERROR: table not found: child (errno 1146) (sqlstate HY000)
QUERY:          create table depth1(c text) inherits (depth0);
RECEIVED ERROR: table not found: depth0 (errno 1146) (sqlstate HY000)
QUERY:          CREATE TABLE inh_test (LIKE part_2);
RECEIVED ERROR: table with name inh_test already exists (errno 1105) (sqlstate HY000)

inherit

QUERY:          CREATE TABLE otherchild (tomorrow date default now())
  INHERITS (firstparent, thirdparent);
RECEIVED ERROR: table not found: firstparent (errno 1146) (sqlstate HY000)
QUERY:          create table c1(f3 int) inherits(p1,p2);
RECEIVED ERROR: table with name c1 already exists (errno 1105) (sqlstate HY000)
QUERY:          create table c2(f3 int) inherits(p1,p2);
RECEIVED ERROR: table with name c2 already exists (errno 1105) (sqlstate HY000)

misc

QUERY:          CREATE TEMP TABLE stud_emp_copy (LIKE stud_emp);
RECEIVED ERROR: table not found: stud_emp (errno 1146) (sqlstate HY000)

test_setup

QUERY:          CREATE TABLE emp (
	salary 		int4,
	manager 	name
) INHERITS (person);
RECEIVED ERROR: table not found: person (errno 1146) (sqlstate HY000)
QUERY:          CREATE TABLE student (
	gpa 		float8
) INHERITS (person);
RECEIVED ERROR: table not found: person (errno 1146) (sqlstate HY000)
QUERY:          CREATE TABLE stud_emp (
	percent 	int4
) INHERITS (emp, student);
RECEIVED ERROR: table not found: emp (errno 1146) (sqlstate HY000)
QUERY:          CREATE TABLE shighway (
	surface		text
) INHERITS (road);
RECEIVED ERROR: table not found: road (errno 1146) (sqlstate HY000)

${\color{lightgreen}Progressions}$

aggregates

QUERY: create table minmaxtest1() inherits (minmaxtest);
QUERY: create table minmaxtest2() inherits (minmaxtest);
QUERY: create table minmaxtest3() inherits (minmaxtest);
QUERY: create index minmaxtest1i on minmaxtest1(f1);
QUERY: create index minmaxtest2i on minmaxtest2(f1 desc);
QUERY: insert into minmaxtest1 values(13), (14);
QUERY: insert into minmaxtest2 values(15), (16);
QUERY: insert into minmaxtest3 values(17), (18);
QUERY: create temp table t1c () inherits (t1);

alter_table

QUERY: CREATE TABLE attmp6 () INHERITS (attmp3);
QUERY: CREATE TABLE attmp7 () INHERITS (attmp3);
QUERY: INSERT INTO attmp6 VALUES (6, 30), (7, 16);
QUERY: DELETE FROM attmp6 WHERE b > 20;
QUERY: INSERT INTO attmp7 VALUES (8, 18);
QUERY: create table child_noinh_convalid () inherits (parent_noinh_convalid);
QUERY: insert into child_noinh_convalid values (1);
QUERY: drop table parent_noinh_convalid, child_noinh_convalid;
QUERY: DROP TABLE attmp7;
QUERY: DROP TABLE attmp6;
QUERY: insert into atacc3 (test2) values (3);
QUERY: insert into atacc3 (test2) values (3);
QUERY: alter table atacc3 rename test2 to testx;
QUERY: create table parent (a int);
QUERY: insert into child values (12, 13, 'testing');
QUERY: select * from child;
QUERY: create table child (a float4) inherits (parent);
QUERY: create table gc1() inherits (c1);
QUERY: CREATE TABLE test_inh_check_child() INHERITS(test_inh_check);
QUERY: ALTER TABLE test_inh_check_child ADD CONSTRAINT blocal CHECK (b < 1000);
QUERY: ALTER TABLE test_inh_check_child ADD CONSTRAINT bmerged CHECK (b > 1);
QUERY: CREATE TABLE tt6 () INHERITS (tt0);
QUERY: CREATE TABLE test_drop_constr_child () INHERITS (test_drop_constr_parent);
QUERY: ALTER TABLE part_6 DROP c;
QUERY: ALTER TABLE part_7_a_null DROP c, DROP d, DROP e;

compression

QUERY: CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata);

create_misc

QUERY: INSERT INTO b_star (class, a, b) VALUES ('b', 3, 'mumble'::text);
QUERY: INSERT INTO b_star (class, a) VALUES ('b', 4);
QUERY: INSERT INTO b_star (class, b) VALUES ('b', 'bumble'::text);
QUERY: INSERT INTO b_star (class) VALUES ('b');
QUERY: INSERT INTO c_star (class, a, c) VALUES ('c', 5, 'hi mom'::name);
QUERY: INSERT INTO c_star (class, a) VALUES ('c', 6);
QUERY: INSERT INTO c_star (class, c) VALUES ('c', 'hi paul'::name);
QUERY: INSERT INTO c_star (class) VALUES ('c');
QUERY: INSERT INTO d_star (class, a, b, c, d)
   VALUES ('d', 7, 'grumble'::text, 'hi sunita'::name, '0.0'::float8);
QUERY: INSERT INTO d_star (class, a, b, c)
   VALUES ('d', 8, 'stumble'::text, 'hi koko'::name);
QUERY: INSERT INTO d_star (class, a, b, d)
   VALUES ('d', 9, 'rumble'::text, '1.1'::float8);
QUERY: INSERT INTO d_star (class, a, c, d)
   VALUES ('d', 10, 'hi kristin'::name, '10.01'::float8);
QUERY: INSERT INTO d_star (class, b, c, d)
   VALUES ('d', 'crumble'::text, 'hi boris'::name, '100.001'::float8);
QUERY: INSERT INTO d_star (class, a, b)
   VALUES ('d', 11, 'fumble'::text);
QUERY: INSERT INTO d_star (class, a, c)
   VALUES ('d', 12, 'hi avi'::name);
QUERY: INSERT INTO d_star (class, a, d)
   VALUES ('d', 13, '1000.0001'::float8);
QUERY: INSERT INTO d_star (class, b, c)
   VALUES ('d', 'tumble'::text, 'hi andrew'::name);
QUERY: INSERT INTO d_star (class, b, d)
   VALUES ('d', 'humble'::text, '10000.00001'::float8);
QUERY: INSERT INTO d_star (class, c, d)
   VALUES ('d', 'hi ginger'::name, '100000.000001'::float8);
QUERY: INSERT INTO d_star (class, a) VALUES ('d', 14);
QUERY: INSERT INTO d_star (class, b) VALUES ('d', 'jumble'::text);
QUERY: INSERT INTO d_star (class, c) VALUES ('d', 'hi jolly'::name);
QUERY: INSERT INTO d_star (class, d) VALUES ('d', '1000000.0000001'::float8);
QUERY: INSERT INTO d_star (class) VALUES ('d');
QUERY: INSERT INTO e_star (class, a, c, e)
   VALUES ('e', 15, 'hi carol'::name, '-1'::int2);
QUERY: INSERT INTO e_star (class, a, c)
   VALUES ('e', 16, 'hi bob'::name);
QUERY: INSERT INTO e_star (class, a, e)
   VALUES ('e', 17, '-2'::int2);
QUERY: INSERT INTO e_star (class, c, e)
   VALUES ('e', 'hi michelle'::name, '-3'::int2);
QUERY: INSERT INTO e_star (class, a)
   VALUES ('e', 18);
QUERY: INSERT INTO e_star (class, c)
   VALUES ('e', 'hi elisa'::name);
QUERY: INSERT INTO e_star (class, e)
   VALUES ('e', '-4'::int2);
QUERY: SELECT *
   FROM b_star* x
   WHERE x.b = text 'bumble' or x.a < 3;
QUERY: SELECT class, b, c
   FROM d_star* x
   WHERE x.a < 100;

create_table

QUERY: CREATE TABLE partitioned (
	a int
) INHERITS (some_table) PARTITION BY LIST (a);

errors

QUERY: alter table emp rename column salary to ctid;

foreign_key

QUERY: create table pktable (ptest1 int, primary key(base1), unique(base1, ptest1)) inherits (pktable_base);
QUERY: insert into pktable(base1) values (1);
QUERY: insert into pktable(base1) values (2);
QUERY: insert into pktable(base1) values (3);
QUERY: update pktable set base1=base1*4 where base1<3;
QUERY: delete from pktable where base1>3;
QUERY: delete from pktable;
QUERY: insert into pktable(base1, ptest1) values (1, 1);
QUERY: insert into pktable(base1, ptest1) values (2, 2);
QUERY: insert into pktable(base1,ptest1) values (3, 1);
QUERY: update pktable set base1=base1*4 where base1<3;
QUERY: delete from pktable where base1>3;

generated

QUERY: CREATE TABLE gtest1_1 () INHERITS (gtest1);
QUERY: SELECT * FROM gtest1_1;
QUERY: CREATE TABLE gtest30_1 () INHERITS (gtest30);

identity

QUERY: CREATE TABLE itest7e () INHERITS (itest7d);

inherit

QUERY: INSERT INTO b(aa) VALUES('bbb');
QUERY: INSERT INTO b(aa) VALUES('bbbb');
QUERY: INSERT INTO b(aa) VALUES('bbbbb');
QUERY: INSERT INTO b(aa) VALUES('bbbbbb');
QUERY: INSERT INTO b(aa) VALUES('bbbbbbb');
QUERY: INSERT INTO b(aa) VALUES('bbbbbbbb');
QUERY: INSERT INTO c(aa) VALUES('ccc');
QUERY: INSERT INTO c(aa) VALUES('cccc');
QUERY: INSERT INTO c(aa) VALUES('ccccc');
QUERY: INSERT INTO c(aa) VALUES('cccccc');
QUERY: INSERT INTO c(aa) VALUES('ccccccc');
QUERY: INSERT INTO c(aa) VALUES('cccccccc');
QUERY: INSERT INTO d(aa) VALUES('ddd');
QUERY: INSERT INTO d(aa) VALUES('dddd');
QUERY: INSERT INTO d(aa) VALUES('ddddd');
QUERY: INSERT INTO d(aa) VALUES('dddddd');
QUERY: INSERT INTO d(aa) VALUES('ddddddd');
QUERY: INSERT INTO d(aa) VALUES('dddddddd');
QUERY: UPDATE b SET aa='zzz' WHERE aa='aaa';
QUERY: UPDATE b SET aa='new';
QUERY: create table some_tab_child () inherits (some_tab);
QUERY: insert into some_tab_child values(1,2);
QUERY: insert into foo2 values(2,2,2);
QUERY: insert into foo2 values(3,3,3);
QUERY: insert into bar2 values(1,1,1);
QUERY: insert into bar2 values(2,2,2);
QUERY: insert into bar2 values(3,3,3);
QUERY: insert into bar2 values(4,4,4);
QUERY: insert into d values('test','one','two','three');
QUERY: create table c1 () inherits (p1);
QUERY: create table derived () inherits (base);
QUERY: create table more_derived (like derived, b int) inherits (derived);
QUERY: insert into derived (i) values (0);
QUERY: drop table more_derived;
QUERY: drop table derived;
QUERY: insert into c1 values(1,1,2);
QUERY: CREATE TABLE test_constraints_inh () INHERITS (test_constraints);
QUERY: DROP TABLE test_constraints_inh;
QUERY: CREATE TABLE test_foreign_constraints_inh () INHERITS (test_foreign_constraints);
QUERY: DROP TABLE test_foreign_constraints_inh;
QUERY: create table p1_c1() inherits(p1);
QUERY: alter table p1_c1 add constraint inh_check_constraint1 check (f1 > 0);
QUERY: alter table p1_c1 add constraint inh_check_constraint2 check (f1 < 10);
QUERY: create table invalid_check_con_child() inherits(invalid_check_con);
QUERY: alter table invalid_check_con_child add constraint inh_check_constraint check(f1 > 0);
QUERY: insert into matest1 (name) values ('Test 1');
QUERY: insert into matest1 (name) values ('Test 2');
QUERY: insert into matest2 (name) values ('Test 3');
QUERY: insert into matest2 (name) values ('Test 4');
QUERY: insert into matest3 (name) values ('Test 5');
QUERY: insert into matest3 (name) values ('Test 6');
QUERY: create table cnullchild (check (f1 = 1 or f1 = null)) inherits(cnullparent);
QUERY: insert into cnullchild values(1);
QUERY: insert into cnullchild values(2);
QUERY: insert into cnullchild values(null);
QUERY: create temp table inh_temp_child () inherits (inh_perm_parent);
QUERY: create temp table inh_temp_child_2 () inherits (inh_temp_parent);
QUERY: insert into inh_temp_child values (3);
QUERY: insert into inh_temp_child_2 values (4);

insert_conflict

QUERY: create unique index capitals_names_unique on capitals (name);
QUERY: insert into capitals values ('Sacramento', 3.694E+5, 30, 'CA');
QUERY: insert into capitals values ('Madison', 1.913E+5, 845, 'WI');
QUERY: select * from capitals;

join

QUERY: create temp table t2a () inherits (t2);
QUERY: insert into t2a values (200, 2001);

lock

QUERY: CREATE TABLE lock_tbl3 () INHERITS (lock_tbl2);
QUERY: DROP TABLE lock_tbl3;

portals

QUERY: CREATE TEMP TABLE ucchild () inherits (uctest);
QUERY: INSERT INTO ucchild values(100, 'hundred');
QUERY: CREATE TABLE current_check_1 () INHERITS (current_check);
QUERY: CREATE TABLE current_check_2 () INHERITS (current_check);

returning

QUERY: INSERT INTO foochild VALUES(123,'child',999,-123);

rowsecurity

QUERY: COPY t2 FROM stdin;
QUERY: CREATE TABLE copy_rel_to_child () INHERITS (copy_rel_to);
QUERY: INSERT INTO copy_rel_to_child VALUES (1, 'one'), (2, 'two');

rowtypes

QUERY: create temp table tt2 () inherits(tt1);
QUERY: create temp table tt3 () inherits(tt2);

rules

QUERY: create table rules_fooview_child () inherits (rules_fooview);
QUERY: insert into test_1 (name) values ('Test 1');
QUERY: insert into test_1 (name) values ('Test 2');
QUERY: insert into test_2 (name) values ('Test 3');
QUERY: insert into test_2 (name) values ('Test 4');
QUERY: insert into test_3 (name) values ('Test 5');
QUERY: insert into test_3 (name) values ('Test 6');
QUERY: create temp table t1_1 (check (a >= 0 and a < 10)) inherits (t1);
QUERY: create temp table t1_2 (check (a >= 10 and a < 20)) inherits (t1);

stats_ext

QUERY: CREATE TABLE ab1c () INHERITS (ab1);
QUERY: CREATE TABLE stxdinh1() INHERITS(stxdinh);
QUERY: CREATE TABLE stxdinh2() INHERITS(stxdinh);
QUERY: DROP TABLE stxdinh, stxdinh1, stxdinh2;

triggers

QUERY: create table stmt_trig_on_empty_upd1 () inherits (stmt_trig_on_empty_upd);
QUERY: create table child1 () inherits (parent);
QUERY: drop table parent, child1;
QUERY: create table parent (a int) partition by list (a);
QUERY: create table child1 () inherits (parent);
QUERY: delete from child1;
QUERY: drop table child1, child2, child3, parent;
QUERY: create table parent (a text, b int);
QUERY: create table child () inherits (parent);
QUERY: drop table child, parent;
QUERY: create table child () inherits (parent);

truncate

QUERY: INSERT INTO trunc_fa VALUES (3, 'three');
QUERY: INSERT INTO trunc_fb VALUES (4, 444);
QUERY: INSERT INTO trunc_faa VALUES (5, 'five', 'FIVE');
QUERY: SELECT * FROM trunc_faa;
QUERY: SELECT * FROM trunc_faa;
QUERY: SELECT * FROM trunc_faa;

union

QUERY: create table events_child () inherits (events);
QUERY: drop table events_child, events, other_events;

updatable_views

QUERY: CREATE TABLE base_tbl_child (CHECK (a > 0)) INHERITS (base_tbl_parent);
QUERY: CREATE TABLE other_tbl_child () INHERITS (other_tbl_parent);
QUERY: INSERT INTO other_tbl_child VALUES (8),(100);
QUERY: CREATE INDEX t11_a_idx ON t11(a);
QUERY: CREATE INDEX t12_a_idx ON t12(a);
QUERY: CREATE TABLE t111 () INHERITS (t11, t12);
QUERY: CREATE INDEX t111_a_idx ON t111(a);
QUERY: ANALYZE t111;

with

QUERY: CREATE TEMP TABLE child1 ( ) INHERITS ( parent );
QUERY: CREATE TEMP TABLE child2 ( ) INHERITS ( parent );
QUERY: INSERT INTO child1 VALUES ( 11, 'c11' ),( 12, 'c12' );
QUERY: INSERT INTO child2 VALUES ( 23, 'c21' ),( 24, 'c22' );

Footnotes

  1. These are tests that we're marking as Successful, however they do not match the expected output in some way. This is due to small differences, such as different wording on the error messages, or the column names being incorrect while the data itself is correct.

@jycor jycor changed the title bump and implement implement multiple table inherits Nov 8, 2024
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior in the test is wrong, see comments

testing/go/create_table_test.go Show resolved Hide resolved
testing/go/create_table_test.go Show resolved Hide resolved
testing/go/create_table_test.go Outdated Show resolved Hide resolved
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

testing/go/create_table_test.go Show resolved Hide resolved
testing/go/create_table_test.go Show resolved Hide resolved
testing/go/create_table_test.go Outdated Show resolved Hide resolved
testing/go/create_table_test.go Outdated Show resolved Hide resolved
@jycor jycor enabled auto-merge (squash) November 12, 2024 20:17
@jycor jycor merged commit f078658 into main Nov 12, 2024
13 checks passed
@jycor jycor deleted the james/multi-inherit branch November 12, 2024 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants