dolthub / doltgresql

DoltgreSQL - Version Controlled PostgreSQL
Apache License 2.0
1.12k stars 25 forks source link

implement single table inherits #929

Closed jycor closed 1 week ago

jycor commented 2 weeks ago

create table t1 inherits t2; in postgres is similar to create table t1 like t2 in mysql

However, postgres supports adding columns and inherting from multiple tables. There are also some foreign key-like dependencies.

github-actions[bot] commented 2 weeks ago
Main PR
Total 42090 42090
Successful 14003 14127
Failures 28087 27963
Partial Successes[^1] 4718 4706
Main PR
Successful 33.2692% 33.5638%
Failures 66.7308% 66.4362%

${\color{red}Regressions}$

alter_table

QUERY:          alter table atacc2 add constraint foo check (test2>0);
RECEIVED ERROR: column "test2" could not be found in any table in scope (errno 1105) (sqlstate HY000)
QUERY:          insert into atacc2 (test2) values (3);
RECEIVED ERROR: Unknown column 'test2' in 'atacc2' (errno 1054) (sqlstate HY000)
QUERY:          drop table child;
RECEIVED ERROR: table not found: child (errno 1146) (sqlstate HY000)
QUERY:          alter table dropColumnChild drop column c;
RECEIVED ERROR: table "dropcolumnchild" does not have column "c" (errno 1105) (sqlstate HY000)
QUERY:          alter table renameColumnChild rename column b to a;
RECEIVED ERROR: table "renamecolumnchild" does not have column "b" (errno 1105) (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)

constraints

QUERY:          INSERT INTO ATACC2 (TEST2) VALUES (3);
RECEIVED ERROR: Unknown column 'test2' in 'atacc2' (errno 1054) (sqlstate HY000)

create_misc

QUERY:          ALTER TABLE e_star* RENAME COLUMN e TO ee;
RECEIVED ERROR: table "e_star" does not have column "e" (errno 1105) (sqlstate HY000)
QUERY:          ALTER TABLE d_star* RENAME COLUMN d TO dd;
RECEIVED ERROR: table "d_star" does not have column "d" (errno 1105) (sqlstate HY000)
QUERY:          ALTER TABLE c_star* RENAME COLUMN c TO cc;
RECEIVED ERROR: table "c_star" does not have column "c" (errno 1105) (sqlstate HY000)
QUERY:          ALTER TABLE b_star* RENAME COLUMN b TO bb;
RECEIVED ERROR: table "b_star" does not have column "b" (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)
QUERY:          ALTER TABLE inhts RENAME d TO dd;
RECEIVED ERROR: table "inhts" does not have column "d" (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: create table parent (a int);
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);

compression

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

create_misc

QUERY: INSERT INTO b_star (class, a) VALUES ('b', 4);
QUERY: INSERT INTO b_star (class) VALUES ('b');
QUERY: INSERT INTO c_star (class, a) VALUES ('c', 6);
QUERY: INSERT INTO c_star (class) VALUES ('c');
QUERY: INSERT INTO d_star (class, a) VALUES ('d', 14);
QUERY: INSERT INTO d_star (class) VALUES ('d');
QUERY: INSERT INTO e_star (class, a)
   VALUES ('e', 18);

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: update pktable set base1=base1*4 where base1<3;
QUERY: delete from pktable where base1>3;
QUERY: create table pktable(ptest1 int, ptest2 int, primary key(base1, ptest1), foreign key(base2, ptest2) references
                                             pktable(base1, ptest1)) inherits (pktable_base);
QUERY: delete from pktable where base2=2;

generated

QUERY: INSERT INTO gtest_normal_child (a) VALUES (2);
QUERY: CREATE TABLE gtestx (x int, b int DEFAULT 10) INHERITS (gtest1);
QUERY: CREATE TABLE gtestc (f2 int GENERATED ALWAYS AS (f1+1) STORED) INHERITS(gtestp);
QUERY: INSERT INTO gtestc values(42);

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 TEMP TABLE z (b TEXT, PRIMARY KEY(aa, b)) inherits (a);
QUERY: create table some_tab_child () inherits (some_tab);
QUERY: insert into some_tab_child values(1,2);
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: 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);

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

rowsecurity

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

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

[^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 commented 1 week ago

improved version: https://github.com/dolthub/doltgresql/pull/935