BUG #19390: Defects in the test case partition_merge - Mailing list pgsql-bugs
| From | PG Bug reporting form |
|---|---|
| Subject | BUG #19390: Defects in the test case partition_merge |
| Date | |
| Msg-id | 19390-2edac7dbcd914aea@postgresql.org Whole thread Raw |
| List | pgsql-bugs |
The following bug has been logged on the website: Bug reference: 19390 Logged by: fairyfar Email address: fairyfar@msn.com PostgreSQL version: Unsupported/Unknown Operating system: Linux Description: # PostgreSQL version git branch: master git commit id: 851f6649cc18c4b482fa2b6afddb65b35d035370 # Problem In my test environment, the next OID of PostgreSQL is greater than 2^31. The partition_merge failure in regression testing: ```bash [yz@bogon regress]$ ./pg_regress --schedule=parallel_schedule ... # parallel group (18 tests): compression_lz4 numa hash_part explain reloptions predicate partition_info compression memoize eager_aggregate tuplesort partition_aggregate partition_merge partition_split partition_prune indexing partition_join stats not ok 215 + partition_merge 16421 ms ... [yz@bogon regress]$ cat regression.diffs diff -U3 /home/yz/postgresql/postgres_src/src/test/regress/expected/partition_merge.out /home/yz/postgresql/postgres_src/src/test/regress/results/partition_merge.out --- /home/yz/postgresql/postgres_src/src/test/regress/expected/partition_merge.out 2026-01-27 14:36:29.093904247 +0800 +++ /home/yz/postgresql/postgres_src/src/test/regress/results/partition_merge.out 2026-01-28 14:51:09.227253112 +0800 @@ -1068,26 +1068,27 @@ ALTER TABLE t ADD CHECK (g > 0); ALTER TABLE t ADD CHECK (i > 0); INSERT INTO t VALUES (5), (15); +ERROR: new row for relation "tp_1" violates check constraint "t_g_check" +DETAIL: Failing row contains (5, virtual). ALTER TABLE t MERGE PARTITIONS (tp_1, tp_2) INTO tp_12; INSERT INTO t VALUES (16); +ERROR: new row for relation "tp_12" violates check constraint "t_g_check" +DETAIL: Failing row contains (16, virtual). -- ERROR: new row for relation "tp_12" violates check constraint "t_i_check" INSERT INTO t VALUES (0); -ERROR: new row for relation "tp_12" violates check constraint "t_i_check" +ERROR: new row for relation "tp_12" violates check constraint "t_g_check" DETAIL: Failing row contains (0, virtual). -- Should be 3 rows: (5), (15), (16): SELECT i FROM t ORDER BY i; - i ----- - 5 - 15 - 16 -(3 rows) + i +--- +(0 rows) -- Should be 1 because for the same tableoid (15 + tableoid) = (5 + tableoid) + 10: SELECT count(*) FROM t WHERE i = 15 AND g IN (SELECT g + 10 FROM t WHERE i = 5); count ------- - 1 + 0 (1 row) DROP TABLE t; ``` # Root Cause OID is unsigned int. So, when OID is greater than 2^n, converting it to int will result in a negative value. # Solution ```bash [yz@bogon postgres_src]$ git diff diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out index 925fe4f570a..75d1e42511e 100644 --- a/src/test/regress/expected/partition_merge.out +++ b/src/test/regress/expected/partition_merge.out @@ -1033,7 +1033,7 @@ DETAIL: Key (i)=(2) is not present in table "t". DROP TABLE t_fk; DROP TABLE t; -- Test for recomputation of stored generated columns. -CREATE TABLE t (i int, tab_id int generated always as (tableoid) stored) PARTITION BY RANGE (i); +CREATE TABLE t (i bigint, tab_id bigint generated always as (tableoid) stored) PARTITION BY RANGE (i); CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1); CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2); ALTER TABLE t ADD CONSTRAINT cc CHECK(tableoid <> 123456789); @@ -1060,9 +1060,9 @@ SELECT count(*) FROM t WHERE i = 0 AND tab_id IN (SELECT tab_id FROM t WHERE i = DROP TABLE t; -- Test for generated columns (different order of columns in partitioned table -- and partitions). -CREATE TABLE t (i int, g int GENERATED ALWAYS AS (i + tableoid::int)) PARTITION BY RANGE (i); -CREATE TABLE tp_1 (g int GENERATED ALWAYS AS (i + tableoid::int), i int); -CREATE TABLE tp_2 (g int GENERATED ALWAYS AS (i + tableoid::int), i int); +CREATE TABLE t (i bigint, g bigint GENERATED ALWAYS AS (i + tableoid::bigint)) PARTITION BY RANGE (i); +CREATE TABLE tp_1 (g bigint GENERATED ALWAYS AS (i + tableoid::bigint), i bigint); +CREATE TABLE tp_2 (g bigint GENERATED ALWAYS AS (i + tableoid::bigint), i bigint); ALTER TABLE t ATTACH PARTITION tp_1 FOR VALUES FROM (-1) TO (10); ALTER TABLE t ATTACH PARTITION tp_2 FOR VALUES FROM (10) TO (20); ALTER TABLE t ADD CHECK (g > 0); diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql index a211fee2ad1..721a313fbd4 100644 --- a/src/test/regress/sql/partition_merge.sql +++ b/src/test/regress/sql/partition_merge.sql @@ -739,7 +739,7 @@ DROP TABLE t; -- Test for recomputation of stored generated columns. -CREATE TABLE t (i int, tab_id int generated always as (tableoid) stored) PARTITION BY RANGE (i); +CREATE TABLE t (i bigint, tab_id bigint generated always as (tableoid) stored) PARTITION BY RANGE (i); CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1); CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2); ALTER TABLE t ADD CONSTRAINT cc CHECK(tableoid <> 123456789); @@ -762,9 +762,9 @@ DROP TABLE t; -- Test for generated columns (different order of columns in partitioned table -- and partitions). -CREATE TABLE t (i int, g int GENERATED ALWAYS AS (i + tableoid::int)) PARTITION BY RANGE (i); -CREATE TABLE tp_1 (g int GENERATED ALWAYS AS (i + tableoid::int), i int); -CREATE TABLE tp_2 (g int GENERATED ALWAYS AS (i + tableoid::int), i int); +CREATE TABLE t (i bigint, g bigint GENERATED ALWAYS AS (i + tableoid::bigint)) PARTITION BY RANGE (i); +CREATE TABLE tp_1 (g bigint GENERATED ALWAYS AS (i + tableoid::bigint), i bigint); +CREATE TABLE tp_2 (g bigint GENERATED ALWAYS AS (i + tableoid::bigint), i bigint); ALTER TABLE t ATTACH PARTITION tp_1 FOR VALUES FROM (-1) TO (10); ALTER TABLE t ATTACH PARTITION tp_2 FOR VALUES FROM (10) TO (20); ALTER TABLE t ADD CHECK (g > 0); ```
pgsql-bugs by date: