Skip to content

Commit f627506

Browse files
committed
[#26576] YSQL: Enable table inheritance for all ported tests
Summary: Setting the defaults for `BasePgRegressTestPorted` to match more closely with Postgres behaviour will help simplify efforts to port more Postgres tests. 5aea237 / D42034 enabled inheritance on Yugabyte, but did not update all of the regression tests. This diff sets `ysql_enable_inheritance=true` for all tests that derive from `BasePgRegressTestPorted`. This cascades into some changes: * any Java test deriving from this class doesn't need to explicitly set the flag anymore. * regress tests that use table inheritance no longer have an error in their output. Many of these tests have a comment similar to "TODO: port more once inheritance is enabled". Generally, uncommenting the following lines results in the expected output. This change touches only lines related to `INHERITS`, and does not attempt to re-port other sections of the affected files. * `yb_enable_read_committed_isolation` is also now enabled by default in `BasePgRegressTestPorted` to enable some new test cases. This does not set the isolation level to read committed, but just **allows** it to be set. To help review, it's helpful to diff the `yb.port.*.sql` and `yb.port.*.out` files with their sources. ``` function portdiffsql() { diff src/postgres/src/test/regress/sql/$1.sql src/postgres/src/test/regress/sql/yb.port.$1.sql } function portdiffout() { diff src/postgres/src/test/regress/expected/$1.out src/postgres/src/test/regress/expected/yb.port.$1.out } portdiffsql foreign_data portdiffsql foreign_key portdiffsql generated portdiffsql insert_conflict portdiffsql privileges portdiffsql rowsecurity portdiffsql truncate portdiffout foreign_data portdiffout foreign_key portdiffout generated portdiffout insert_conflict portdiffout privileges portdiffout rowsecurity portdiffout truncate ``` Differences worth calling out: * There are a few cases where we need to delete + reinsert rows to get match the ctid update behaviour of Postgres * `yb.port.foreign_key` has extra changes because indexes on `INET` are not supported. * `yb.port.truncate` has some tests for `TRUNCATE ONLY` that depend on `TRUNCATE` being transactional. It's not transactional in YB, so to keep the coverage of `TRUNCATE ONLY`, manually reset the table after each `ROLLBACK`. (lines ~1640 in yb.port.truncate.sql`). The results of the `SELECT`s are identical to PG. Jira: DB-15944 Test Plan: ``` ./yb_build.sh --java-test TestPgRegressPgAuth ./yb_build.sh --java-test TestPgRegressPgDml ./yb_build.sh --java-test TestPgRegressPgForeignData ./yb_build.sh --java-test TestPgRegressPgGenerated ./yb_build.sh --java-test TestPgRegressPgMiscIndependent ./yb_build.sh --java-test TestPgRegressForeignKey ``` Jenkins Reviewers: fizaa, sanketh Reviewed By: sanketh Subscribers: smishra, yql Differential Revision: https://phorge.dev.yugabyte.com/D42816
1 parent 7602328 commit f627506

21 files changed

+1757
-194
lines changed

java/yb-pgsql/src/test/java/org/yb/pgsql/BasePgRegressTestPorted.java

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class BasePgRegressTestPorted extends BasePgRegressTest {
2626
protected Map<String, String> getTServerFlags() {
2727
Map<String, String> flagMap = super.getTServerFlags();
2828
flagMap.put("TEST_generate_ybrowid_sequentially", "true");
29+
flagMap.put("ysql_enable_inheritance", "true");
30+
flagMap.put("yb_enable_read_committed_isolation", "true");
2931
appendToYsqlPgConf(flagMap, "yb_use_hash_splitting_by_default=false");
3032
return flagMap;
3133
}

java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgRegressContribPostgresFdw.java

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.yb.YBTestRunner;
1919

2020
import java.io.File;
21+
import java.util.Map;
2122

2223
@RunWith(value=YBTestRunner.class)
2324
public class TestPgRegressContribPostgresFdw extends BasePgRegressTestPorted {
@@ -31,4 +32,14 @@ public void schedule() throws Exception {
3132
runPgRegressTest(new File(TestUtils.getBuildRootDir(), "postgres_build/contrib/postgres_fdw"),
3233
"yb_schedule");
3334
}
35+
36+
/* TODO: this is necessary because the ysql_enable_inheritance can leak into other tests and cause
37+
* failures. This test should use BasePgRegressTestPorted, and this flag can be removed.
38+
*/
39+
@Override
40+
protected Map<String, String> getTServerFlags() {
41+
Map<String, String> flagMap = super.getTServerFlags();
42+
flagMap.put("ysql_enable_inheritance", "false");
43+
return flagMap;
44+
}
3445
}

java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgRegressInherit.java

-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@
2121
@RunWith(value=YBTestRunner.class)
2222
public class TestPgRegressInherit extends BasePgRegressTestPorted {
2323

24-
@Override
25-
protected Map<String, String> getTServerFlags() {
26-
Map<String, String> flags = super.getTServerFlags();
27-
flags.put("ysql_enable_inheritance", "true");
28-
return flags;
29-
}
30-
3124
@Test
3225
public void testPgRegressInherit() throws Exception {
3326
runPgRegressTest("yb_pg_inherit_schedule");

java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgRegressLimit.java

-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ public int getTestMethodTimeoutSec() {
2727
return 1800;
2828
}
2929

30-
@Override
31-
protected Map<String, String> getTServerFlags() {
32-
Map<String, String> flags = super.getTServerFlags();
33-
flags.put("ysql_enable_inheritance", "true");
34-
return flags;
35-
}
36-
3730
@Test
3831
public void testPgRegressYbFetchLimits() throws Exception {
3932
runPgRegressTest("yb_limit_schedule");

java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgRegressPgConstraints.java

-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ public int getTestMethodTimeoutSec() {
2727
return 1800;
2828
}
2929

30-
@Override
31-
protected Map<String, String> getTServerFlags() {
32-
Map<String, String> flags = super.getTServerFlags();
33-
flags.put("ysql_enable_inheritance", "true");
34-
return flags;
35-
}
36-
3730
@Test
3831
public void schedule() throws Exception {
3932
runPgRegressTest("yb_pg_constraints_schedule");

java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgRegressPgMisc.java

-8
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ public int getTestMethodTimeoutSec() {
2929
return 1800;
3030
}
3131

32-
33-
@Override
34-
protected Map<String, String> getTServerFlags() {
35-
Map<String, String> flags = super.getTServerFlags();
36-
flags.put("ysql_enable_inheritance", "true");
37-
return flags;
38-
}
39-
4032
@Test
4133
public void testPgRegressPgMisc() throws Exception {
4234
runPgRegressTest("yb_pg_misc_serial_schedule");

src/postgres/src/test/regress/expected/yb.port.foreign_data.out

+231-35
Large diffs are not rendered by default.

src/postgres/src/test/regress/expected/yb.port.foreign_key.out

+42-19
Original file line numberDiff line numberDiff line change
@@ -866,57 +866,59 @@ CREATE TABLE PKTABLE (ptest1 int, ptest2 text, ptest3 int, ptest4 text, PRIMARY
866866
ptest3) REFERENCES pktable);
867867
ERROR: foreign key constraint "pktable_ptest4_ptest3_fkey" cannot be implemented
868868
DETAIL: Key columns "ptest4" and "ptest1" are of incompatible types: text and integer.
869-
-- TODO: YugaByte does not yet support table inheritance.
870-
-- Leaving the first failing statement uncommented so that this test
871-
-- will fail when the feature is implemented (the full test should
872-
-- be uncommented then).
873869
--
874870
-- Now some cases with inheritance
875871
-- Basic 2 table case: 1 column of matching types.
876872
create table pktable_base (base1 int not null);
877873
create table pktable (ptest1 int, primary key(base1), unique(base1, ptest1)) inherits (pktable_base);
878-
ERROR: INHERITS not supported yet
879-
LINE 1: ...1 int, primary key(base1), unique(base1, ptest1)) inherits (...
880-
^
881-
HINT: See https://github.com/yugabyte/yugabyte-db/issues/1129. React with thumbs up to raise its priority
882-
/*
883874
create table fktable (ftest1 int references pktable(base1));
884875
-- now some ins, upd, del
885876
insert into pktable(base1) values (1);
886877
insert into pktable(base1) values (2);
887878
-- let's insert a non-existent fktable value
888879
insert into fktable(ftest1) values (3);
880+
ERROR: insert or update on table "fktable" violates foreign key constraint "fktable_ftest1_fkey"
881+
DETAIL: Key (ftest1)=(3) is not present in table "pktable".
889882
-- let's make a valid row for that
890883
insert into pktable(base1) values (3);
891884
insert into fktable(ftest1) values (3);
892885
-- let's try removing a row that should fail from pktable
893886
delete from pktable where base1>2;
887+
ERROR: update or delete on table "pktable" violates foreign key constraint "fktable_ftest1_fkey" on table "fktable"
888+
DETAIL: Key (base1)=(3) is still referenced from table "fktable".
894889
-- okay, let's try updating all of the base1 values to *4
895890
-- which should fail.
896891
update pktable set base1=base1*4;
892+
ERROR: update or delete on table "pktable" violates foreign key constraint "fktable_ftest1_fkey" on table "fktable"
893+
DETAIL: Key (base1)=(3) is still referenced from table "fktable".
897894
-- okay, let's try an update that should work.
898895
update pktable set base1=base1*4 where base1<3;
899896
-- and a delete that should work
900897
delete from pktable where base1>3;
901898
-- cleanup
902899
drop table fktable;
903900
delete from pktable;
904-
905901
-- Now 2 columns 2 tables, matching types
906902
create table fktable (ftest1 int, ftest2 int, foreign key(ftest1, ftest2) references pktable(base1, ptest1));
907903
-- now some ins, upd, del
908904
insert into pktable(base1, ptest1) values (1, 1);
909905
insert into pktable(base1, ptest1) values (2, 2);
910906
-- let's insert a non-existent fktable value
911907
insert into fktable(ftest1, ftest2) values (3, 1);
908+
ERROR: insert or update on table "fktable" violates foreign key constraint "fktable_ftest1_ftest2_fkey"
909+
DETAIL: Key (ftest1, ftest2)=(3, 1) is not present in table "pktable".
912910
-- let's make a valid row for that
913911
insert into pktable(base1,ptest1) values (3, 1);
914912
insert into fktable(ftest1, ftest2) values (3, 1);
915913
-- let's try removing a row that should fail from pktable
916914
delete from pktable where base1>2;
915+
ERROR: update or delete on table "pktable" violates foreign key constraint "fktable_ftest1_ftest2_fkey" on table "fktable"
916+
DETAIL: Key (base1, ptest1)=(3, 1) is still referenced from table "fktable".
917917
-- okay, let's try updating all of the base1 values to *4
918918
-- which should fail.
919919
update pktable set base1=base1*4;
920+
ERROR: update or delete on table "pktable" violates foreign key constraint "fktable_ftest1_ftest2_fkey" on table "fktable"
921+
DETAIL: Key (base1, ptest1)=(3, 1) is still referenced from table "fktable".
920922
-- okay, let's try an update that should work.
921923
update pktable set base1=base1*4 where base1<3;
922924
-- and a delete that should work
@@ -925,7 +927,6 @@ delete from pktable where base1>3;
925927
drop table fktable;
926928
drop table pktable;
927929
drop table pktable_base;
928-
929930
-- Now we'll do one all in 1 table with 2 columns of matching types
930931
create table pktable_base(base1 int not null, base2 int);
931932
create table pktable(ptest1 int, ptest2 int, primary key(base1, ptest1), foreign key(base2, ptest2) references
@@ -936,41 +937,63 @@ insert into pktable (base1, ptest1, base2, ptest2) values (2, 2, 2, 1);
936937
insert into pktable (base1, ptest1, base2, ptest2) values (1, 3, 2, 2);
937938
-- fails (3,2) isn't in base1, ptest1
938939
insert into pktable (base1, ptest1, base2, ptest2) values (2, 3, 3, 2);
940+
ERROR: insert or update on table "pktable" violates foreign key constraint "pktable_base2_ptest2_fkey"
941+
DETAIL: Key (base2, ptest2)=(3, 2) is not present in table "pktable".
939942
-- fails (2,2) is being referenced
940943
delete from pktable where base1=2;
944+
ERROR: update or delete on table "pktable" violates foreign key constraint "pktable_base2_ptest2_fkey" on table "pktable"
945+
DETAIL: Key (base1, ptest1)=(2, 2) is still referenced from table "pktable".
941946
-- fails (1,1) is being referenced (twice)
942947
update pktable set base1=3 where base1=1;
948+
ERROR: update or delete on table "pktable" violates foreign key constraint "pktable_base2_ptest2_fkey" on table "pktable"
949+
DETAIL: Key (base1, ptest1)=(1, 1) is still referenced from table "pktable".
943950
-- this sequence of two deletes will work, since after the first there will be no (2,*) references
944951
delete from pktable where base2=2;
945952
delete from pktable where base1=2;
946953
drop table pktable;
947954
drop table pktable_base;
948-
949955
-- 2 columns (2 tables), mismatched types
950956
create table pktable_base(base1 int not null);
951-
create table pktable(ptest1 inet, primary key(base1, ptest1)) inherits (pktable_base);
957+
create table pktable(ptest1 text, primary key(base1, ptest1)) inherits (pktable_base); -- YB: #17017: replace INET with TEXT because indexes on INET are not supported
952958
-- just generally bad types (with and without column references on the referenced table)
953959
create table fktable(ftest1 cidr, ftest2 int[], foreign key (ftest1, ftest2) references pktable);
960+
ERROR: foreign key constraint "fktable_ftest1_ftest2_fkey" cannot be implemented
961+
DETAIL: Key columns "ftest1" and "base1" are of incompatible types: cidr and integer.
954962
create table fktable(ftest1 cidr, ftest2 int[], foreign key (ftest1, ftest2) references pktable(base1, ptest1));
963+
ERROR: foreign key constraint "fktable_ftest1_ftest2_fkey" cannot be implemented
964+
DETAIL: Key columns "ftest1" and "base1" are of incompatible types: cidr and integer.
955965
-- let's mix up which columns reference which
956966
create table fktable(ftest1 int, ftest2 inet, foreign key(ftest2, ftest1) references pktable);
967+
ERROR: foreign key constraint "fktable_ftest2_ftest1_fkey" cannot be implemented
968+
DETAIL: Key columns "ftest2" and "base1" are of incompatible types: inet and integer.
957969
create table fktable(ftest1 int, ftest2 inet, foreign key(ftest2, ftest1) references pktable(base1, ptest1));
970+
ERROR: foreign key constraint "fktable_ftest2_ftest1_fkey" cannot be implemented
971+
DETAIL: Key columns "ftest2" and "base1" are of incompatible types: inet and integer.
958972
create table fktable(ftest1 int, ftest2 inet, foreign key(ftest1, ftest2) references pktable(ptest1, base1));
973+
ERROR: foreign key constraint "fktable_ftest1_ftest2_fkey" cannot be implemented
974+
DETAIL: Key columns "ftest1" and "ptest1" are of incompatible types: integer and text.
959975
drop table pktable;
960976
drop table pktable_base;
961-
962977
-- 2 columns (1 table), mismatched types
963978
create table pktable_base(base1 int not null, base2 int);
964-
create table pktable(ptest1 inet, ptest2 inet[], primary key(base1, ptest1), foreign key(base2, ptest2) references
979+
create table pktable(ptest1 text, ptest2 text[], primary key(base1, ptest1), foreign key(base2, ptest2) references -- YB: #17017: replace INET with TEXT because indexes on INET are not supported
965980
pktable(base1, ptest1)) inherits (pktable_base);
966-
create table pktable(ptest1 inet, ptest2 inet, primary key(base1, ptest1), foreign key(base2, ptest2) references
981+
ERROR: foreign key constraint "pktable_base2_ptest2_fkey" cannot be implemented
982+
DETAIL: Key columns "ptest2" and "ptest1" are of incompatible types: text[] and text.
983+
create table pktable(ptest1 text, ptest2 text, primary key(base1, ptest1), foreign key(base2, ptest2) references -- YB: #17017: replace INET with TEXT because indexes on INET are not supported
967984
pktable(ptest1, base1)) inherits (pktable_base);
968-
create table pktable(ptest1 inet, ptest2 inet, primary key(base1, ptest1), foreign key(ptest2, base2) references
985+
ERROR: foreign key constraint "pktable_base2_ptest2_fkey" cannot be implemented
986+
DETAIL: Key columns "base2" and "ptest1" are of incompatible types: integer and text.
987+
create table pktable(ptest1 text, ptest2 text, primary key(base1, ptest1), foreign key(ptest2, base2) references -- YB: #17017: replace INET with TEXT because indexes on INET are not supported
969988
pktable(base1, ptest1)) inherits (pktable_base);
970-
create table pktable(ptest1 inet, ptest2 inet, primary key(base1, ptest1), foreign key(ptest2, base2) references
989+
ERROR: foreign key constraint "pktable_ptest2_base2_fkey" cannot be implemented
990+
DETAIL: Key columns "ptest2" and "base1" are of incompatible types: text and integer.
991+
create table pktable(ptest1 text, ptest2 text, primary key(base1, ptest1), foreign key(ptest2, base2) references -- YB: #17017: replace INET with TEXT because indexes on INET are not supported
971992
pktable(base1, ptest1)) inherits (pktable_base);
993+
ERROR: foreign key constraint "pktable_ptest2_base2_fkey" cannot be implemented
994+
DETAIL: Key columns "ptest2" and "base1" are of incompatible types: text and integer.
972995
drop table pktable;
973-
*/
996+
ERROR: table "pktable" does not exist
974997
drop table pktable_base;
975998
--
976999
-- Deferrable constraints

0 commit comments

Comments
 (0)