Skip to content

Commit 755f04c

Browse files
committed
Add table to regression tests for binary-compatibility checks in pg_upgrade
This commit adds to the main regression test suite a table with all the in-core data types (some exceptions apply). This table is not dropped, so as pg_upgrade would be able to check the binary compatibility of the types tracked in the table. If a new type is added in core, this part of the tests would need a refresh but the tests are designed to fail if that were to happen. As this is useful for upgrades and that these rely on the objects created in the regression test suite of the old version upgraded from, a backpatch down to 12 is done, which is the last point where a binary incompatible change has been done (7c15cef). This will hopefully be enough to find out if something gets broken during the development of a new version of Postgres, so as it is possible to take actions in pg_upgrade itself in this case (like 0ccfc28 for sql_identifier). An area that is not covered yet is related to external modules, which may create their own types. The testing infrastructure of pg_upgrade is not integrated yet with the external modules stored in core (src/test/modules/ or contrib/, all use the same database name for their tests so there would be an overlap). This could be improved in the future. Author: Justin Pryzby Reviewed-by: Jacob Champion, Peter Eisentraut, Tom Lane, Michael Paquier Discussion: https://postgr.es/m/20201206180248.GI24052@telsasoft.com Backpatch-through: 12
1 parent c8b5221 commit 755f04c

File tree

3 files changed

+193
-0
lines changed

3 files changed

+193
-0
lines changed

src/test/regress/expected/sanity_check.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ sql_parts|f
181181
sql_sizing|f
182182
stud_emp|f
183183
student|f
184+
tab_core_types|f
184185
tableam_parted_a_heap2|f
185186
tableam_parted_b_heap2|f
186187
tableam_parted_c_heap2|f

src/test/regress/expected/type_sanity.out

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,100 @@ WHERE pronargs != 2
631631
----------+------------+---------
632632
(0 rows)
633633

634+
-- Create a table that holds all the known in-core data types and leave it
635+
-- around so as pg_upgrade is able to test their binary compatibility.
636+
CREATE TABLE tab_core_types AS SELECT
637+
'(11,12)'::point,
638+
'(1,1),(2,2)'::line,
639+
'((11,11),(12,12))'::lseg,
640+
'((11,11),(13,13))'::box,
641+
'((11,12),(13,13),(14,14))'::path AS openedpath,
642+
'[(11,12),(13,13),(14,14)]'::path AS closedpath,
643+
'((11,12),(13,13),(14,14))'::polygon,
644+
'1,1,1'::circle,
645+
'today'::date,
646+
'now'::time,
647+
'now'::timestamp,
648+
'now'::timetz,
649+
'now'::timestamptz,
650+
'12 seconds'::interval,
651+
'{"reason":"because"}'::json,
652+
'{"when":"now"}'::jsonb,
653+
'$.a[*] ? (@ > 2)'::jsonpath,
654+
'127.0.0.1'::inet,
655+
'127.0.0.0/8'::cidr,
656+
'00:01:03:86:1c:ba'::macaddr8,
657+
'00:01:03:86:1c:ba'::macaddr,
658+
2::int2, 4::int4, 8::int8,
659+
4::float4, '8'::float8, pi()::numeric,
660+
'foo'::"char",
661+
'c'::bpchar,
662+
'abc'::varchar,
663+
'name'::name,
664+
'txt'::text,
665+
true::bool,
666+
E'\\xDEADBEEF'::bytea,
667+
B'10001'::bit,
668+
B'10001'::varbit AS varbit,
669+
'12.34'::money,
670+
'abc'::refcursor,
671+
'1 2'::int2vector,
672+
'1 2'::oidvector,
673+
format('%s=UC/%s', USER, USER)::aclitem,
674+
'a fat cat sat on a mat and ate a fat rat'::tsvector,
675+
'fat & rat'::tsquery,
676+
'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
677+
'11'::xid8,
678+
'pg_class'::regclass,
679+
'regtype'::regtype,
680+
'pg_monitor'::regrole,
681+
'pg_class'::regclass::oid,
682+
'(1,1)'::tid, '2'::xid, '3'::cid,
683+
'10:20:10,14,15'::txid_snapshot,
684+
'10:20:10,14,15'::pg_snapshot,
685+
'16/B374D848'::pg_lsn,
686+
1::information_schema.cardinal_number,
687+
'l'::information_schema.character_data,
688+
'n'::information_schema.sql_identifier,
689+
'now'::information_schema.time_stamp,
690+
'YES'::information_schema.yes_or_no,
691+
'venus'::planets,
692+
'i16'::insenum,
693+
'(1,2)'::int4range,
694+
'(3,4)'::int8range,
695+
'(1,2)'::float8range,
696+
'(3,4)'::numrange,
697+
'(a,b)'::textrange,
698+
'(12.34, 56.78)'::cashrange,
699+
'(2020-01-02, 2021-02-03)'::daterange,
700+
'(2020-01-02 03:04:05, 2021-02-03 06:07:08)'::tsrange,
701+
'(2020-01-02 03:04:05, 2021-02-03 06:07:08)'::tstzrange,
702+
arrayrange(ARRAY[1,2], ARRAY[2,1]);
703+
-- Sanity check on the previous table, checking that all core types are
704+
-- included in this table.
705+
SELECT oid, typname, typtype, typelem, typarray, typarray
706+
FROM pg_type t
707+
WHERE typtype NOT IN ('p', 'c') AND
708+
-- reg* types cannot be pg_upgraded, so discard them.
709+
oid != ALL(ARRAY['regproc', 'regprocedure', 'regoper',
710+
'regoperator', 'regconfig', 'regdictionary',
711+
'regnamespace', 'regcollation']::regtype[]) AND
712+
-- Discard types that do not accept input values as these cannot be
713+
-- tested easily.
714+
-- Note: XML might be disabled at compile-time.
715+
oid != ALL(ARRAY['gtsvector', 'pg_node_tree',
716+
'pg_ndistinct', 'pg_dependencies', 'pg_mcv_list',
717+
'xml']::regtype[]) AND
718+
-- Discard arrays.
719+
NOT EXISTS (SELECT 1 FROM pg_type u WHERE u.typarray = t.oid)
720+
-- Exclude everything from the table created above. This checks
721+
-- that no in-core types are missing in tab_core_types.
722+
AND NOT EXISTS (SELECT 1
723+
FROM pg_attribute a
724+
WHERE a.atttypid=t.oid AND
725+
a.attnum > 0 AND
726+
a.attrelid='tab_core_types'::regclass);
727+
oid | typname | typtype | typelem | typarray | typarray
728+
-----+---------+---------+---------+----------+----------
729+
(0 rows)
730+

src/test/regress/sql/type_sanity.sql

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,98 @@ FROM pg_range p1 JOIN pg_proc p ON p.oid = p1.rngsubdiff
467467
WHERE pronargs != 2
468468
OR proargtypes[0] != rngsubtype OR proargtypes[1] != rngsubtype
469469
OR prorettype != 'pg_catalog.float8'::regtype;
470+
471+
-- Create a table that holds all the known in-core data types and leave it
472+
-- around so as pg_upgrade is able to test their binary compatibility.
473+
CREATE TABLE tab_core_types AS SELECT
474+
'(11,12)'::point,
475+
'(1,1),(2,2)'::line,
476+
'((11,11),(12,12))'::lseg,
477+
'((11,11),(13,13))'::box,
478+
'((11,12),(13,13),(14,14))'::path AS openedpath,
479+
'[(11,12),(13,13),(14,14)]'::path AS closedpath,
480+
'((11,12),(13,13),(14,14))'::polygon,
481+
'1,1,1'::circle,
482+
'today'::date,
483+
'now'::time,
484+
'now'::timestamp,
485+
'now'::timetz,
486+
'now'::timestamptz,
487+
'12 seconds'::interval,
488+
'{"reason":"because"}'::json,
489+
'{"when":"now"}'::jsonb,
490+
'$.a[*] ? (@ > 2)'::jsonpath,
491+
'127.0.0.1'::inet,
492+
'127.0.0.0/8'::cidr,
493+
'00:01:03:86:1c:ba'::macaddr8,
494+
'00:01:03:86:1c:ba'::macaddr,
495+
2::int2, 4::int4, 8::int8,
496+
4::float4, '8'::float8, pi()::numeric,
497+
'foo'::"char",
498+
'c'::bpchar,
499+
'abc'::varchar,
500+
'name'::name,
501+
'txt'::text,
502+
true::bool,
503+
E'\\xDEADBEEF'::bytea,
504+
B'10001'::bit,
505+
B'10001'::varbit AS varbit,
506+
'12.34'::money,
507+
'abc'::refcursor,
508+
'1 2'::int2vector,
509+
'1 2'::oidvector,
510+
format('%s=UC/%s', USER, USER)::aclitem,
511+
'a fat cat sat on a mat and ate a fat rat'::tsvector,
512+
'fat & rat'::tsquery,
513+
'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
514+
'11'::xid8,
515+
'pg_class'::regclass,
516+
'regtype'::regtype,
517+
'pg_monitor'::regrole,
518+
'pg_class'::regclass::oid,
519+
'(1,1)'::tid, '2'::xid, '3'::cid,
520+
'10:20:10,14,15'::txid_snapshot,
521+
'10:20:10,14,15'::pg_snapshot,
522+
'16/B374D848'::pg_lsn,
523+
1::information_schema.cardinal_number,
524+
'l'::information_schema.character_data,
525+
'n'::information_schema.sql_identifier,
526+
'now'::information_schema.time_stamp,
527+
'YES'::information_schema.yes_or_no,
528+
'venus'::planets,
529+
'i16'::insenum,
530+
'(1,2)'::int4range,
531+
'(3,4)'::int8range,
532+
'(1,2)'::float8range,
533+
'(3,4)'::numrange,
534+
'(a,b)'::textrange,
535+
'(12.34, 56.78)'::cashrange,
536+
'(2020-01-02, 2021-02-03)'::daterange,
537+
'(2020-01-02 03:04:05, 2021-02-03 06:07:08)'::tsrange,
538+
'(2020-01-02 03:04:05, 2021-02-03 06:07:08)'::tstzrange,
539+
arrayrange(ARRAY[1,2], ARRAY[2,1]);
540+
541+
-- Sanity check on the previous table, checking that all core types are
542+
-- included in this table.
543+
SELECT oid, typname, typtype, typelem, typarray, typarray
544+
FROM pg_type t
545+
WHERE typtype NOT IN ('p', 'c') AND
546+
-- reg* types cannot be pg_upgraded, so discard them.
547+
oid != ALL(ARRAY['regproc', 'regprocedure', 'regoper',
548+
'regoperator', 'regconfig', 'regdictionary',
549+
'regnamespace', 'regcollation']::regtype[]) AND
550+
-- Discard types that do not accept input values as these cannot be
551+
-- tested easily.
552+
-- Note: XML might be disabled at compile-time.
553+
oid != ALL(ARRAY['gtsvector', 'pg_node_tree',
554+
'pg_ndistinct', 'pg_dependencies', 'pg_mcv_list',
555+
'xml']::regtype[]) AND
556+
-- Discard arrays.
557+
NOT EXISTS (SELECT 1 FROM pg_type u WHERE u.typarray = t.oid)
558+
-- Exclude everything from the table created above. This checks
559+
-- that no in-core types are missing in tab_core_types.
560+
AND NOT EXISTS (SELECT 1
561+
FROM pg_attribute a
562+
WHERE a.atttypid=t.oid AND
563+
a.attnum > 0 AND
564+
a.attrelid='tab_core_types'::regclass);

0 commit comments

Comments
 (0)