diff --git a/src/postgres/src/backend/catalog/heap.c b/src/postgres/src/backend/catalog/heap.c index d625817d669e..7f66ab9f941d 100644 --- a/src/postgres/src/backend/catalog/heap.c +++ b/src/postgres/src/backend/catalog/heap.c @@ -1269,7 +1269,7 @@ heap_create_with_catalog(const char *relname, if (!OidIsValid(relid)) { /* Use binary-upgrade override for pg_class.oid/relfilenode? */ - if (IsBinaryUpgrade && !yb_binary_restore && + if ((IsBinaryUpgrade || yb_binary_restore) && (relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE || relkind == RELKIND_VIEW || relkind == RELKIND_MATVIEW || relkind == RELKIND_COMPOSITE_TYPE || relkind == RELKIND_FOREIGN_TABLE || @@ -1284,7 +1284,7 @@ heap_create_with_catalog(const char *relname, binary_upgrade_next_heap_pg_class_oid = InvalidOid; } /* There might be no TOAST table, so we have to test for it. */ - else if (IsBinaryUpgrade && !yb_binary_restore && + else if ((IsBinaryUpgrade || yb_binary_restore) && OidIsValid(binary_upgrade_next_toast_pg_class_oid) && relkind == RELKIND_TOASTVALUE) { diff --git a/src/postgres/src/backend/catalog/index.c b/src/postgres/src/backend/catalog/index.c index 15aa02267fda..361a6bfe773d 100644 --- a/src/postgres/src/backend/catalog/index.c +++ b/src/postgres/src/backend/catalog/index.c @@ -962,7 +962,7 @@ index_create(Relation heapRelation, if (!OidIsValid(indexRelationId)) { /* Use binary-upgrade override for pg_class.oid/relfilenode? */ - if (IsBinaryUpgrade && !yb_binary_restore) + if (IsBinaryUpgrade || yb_binary_restore) { if (!OidIsValid(binary_upgrade_next_index_pg_class_oid)) ereport(ERROR, diff --git a/src/postgres/src/bin/pg_dump/pg_dump.c b/src/postgres/src/bin/pg_dump/pg_dump.c index 20d6d3da1c4d..b860d7028e22 100644 --- a/src/postgres/src/bin/pg_dump/pg_dump.c +++ b/src/postgres/src/bin/pg_dump/pg_dump.c @@ -11381,8 +11381,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) binary_upgrade_set_type_oids_by_type_oid(fout, q, tyinfo->dobj.catId.oid, false); - if (dopt->binary_upgrade) - binary_upgrade_set_pg_class_oids(fout, q, tyinfo->typrelid, false); + binary_upgrade_set_pg_class_oids(fout, q, tyinfo->typrelid, false); } qtypname = pg_strdup(fmtId(tyinfo->dobj.name)); @@ -15946,7 +15945,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) appendPQExpBuffer(delq, "DROP VIEW %s;\n", qualrelname); - if (dopt->binary_upgrade) + if (dopt->binary_upgrade || dopt->include_yb_metadata) binary_upgrade_set_pg_class_oids(fout, q, tbinfo->dobj.catId.oid, false); @@ -16023,10 +16022,21 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) appendPQExpBuffer(delq, "DROP %s %s;\n", reltypename, qualrelname); - if (dopt->binary_upgrade) + if (dopt->binary_upgrade || dopt->include_yb_metadata) { binary_upgrade_set_pg_class_oids(fout, q, tbinfo->dobj.catId.oid, false); + /* + * We may create a primary key index as part of the CREATE TABLE + * statement we generate here; accordingly, set things up so we + * will set its OID correctly in binary update mode. + */ + if (tbinfo->primaryKeyIndex) + { + IndxInfo *index = tbinfo->primaryKeyIndex; + binary_upgrade_set_pg_class_oids(fout, q, + index->dobj.catId.oid, true); + } } /* Get the table properties from YB, if relevant. */ @@ -16223,7 +16233,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) bool parent_has_primary_key = false; if (tbinfo->ispartition) { - TableInfo *parentRel = tbinfo->parents[0]; + TableInfo *parentRel = parents[0]; parent_has_primary_key = parentRel->primaryKeyIndex; } @@ -16905,7 +16915,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) int nstatcols; int nstatvals; - if (dopt->binary_upgrade) + if (dopt->binary_upgrade || dopt->include_yb_metadata) binary_upgrade_set_pg_class_oids(fout, q, indxinfo->dobj.catId.oid, true); @@ -17131,7 +17141,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) exit_horribly(NULL, "missing index for constraint \"%s\"\n", coninfo->dobj.name); - if (dopt->binary_upgrade) + if (dopt->binary_upgrade || dopt->include_yb_metadata) binary_upgrade_set_pg_class_oids(fout, q, indxinfo->dobj.catId.oid, true); @@ -17633,9 +17643,8 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) if (dopt->binary_upgrade || dopt->include_yb_metadata) { - if (dopt->binary_upgrade) - binary_upgrade_set_pg_class_oids(fout, query, - tbinfo->dobj.catId.oid, false); + binary_upgrade_set_pg_class_oids(fout, query, + tbinfo->dobj.catId.oid, false); binary_upgrade_set_type_oids_by_rel_oid(fout, query, tbinfo->dobj.catId.oid); } diff --git a/src/postgres/src/test/regress/data/yb_ysql_dump.data.sql b/src/postgres/src/test/regress/data/yb_ysql_dump.data.sql index aad8efa36a32..33cf77066869 100644 --- a/src/postgres/src/test/regress/data/yb_ysql_dump.data.sql +++ b/src/postgres/src/test/regress/data/yb_ysql_dump.data.sql @@ -117,6 +117,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16551'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16550'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16549'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16553'::pg_catalog.oid); + CREATE TABLE hint_plan.hints ( id integer NOT NULL, norm_query_string text NOT NULL, @@ -139,6 +147,10 @@ ALTER EXTENSION pg_hint_plan ADD TABLE hint_plan.hints; -- +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16547'::pg_catalog.oid); + + -- For binary upgrade, must preserve pg_type oid SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16548'::pg_catalog.oid); @@ -177,6 +189,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16471'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16470'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16469'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16472'::pg_catalog.oid); + CREATE TABLE public.chat_user ( "chatID" text NOT NULL, CONSTRAINT chat_user_pkey PRIMARY KEY(("chatID") HASH) @@ -200,6 +220,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16578'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16577'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16576'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16579'::pg_catalog.oid); + CREATE TABLE public.hash_tbl_pk_with_include_clause ( k2 text NOT NULL, v double precision, @@ -225,6 +253,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16589'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16588'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16587'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16590'::pg_catalog.oid); + CREATE TABLE public.hash_tbl_pk_with_multiple_included_columns ( col1 integer NOT NULL, col2 integer NOT NULL, @@ -251,6 +287,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16558'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16557'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16556'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16559'::pg_catalog.oid); + CREATE TABLE public.p1 ( k integer NOT NULL, v text, @@ -275,6 +319,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16565'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16564'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16563'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16566'::pg_catalog.oid); + CREATE TABLE public.p2 ( k integer NOT NULL, v text, @@ -299,6 +351,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16538'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16537'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16536'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16539'::pg_catalog.oid); + CREATE TABLE public.pre_split_range ( id integer NOT NULL, customer_id integer NOT NULL, @@ -336,6 +396,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16572'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16571'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16570'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16573'::pg_catalog.oid); + CREATE TABLE public.range_tbl_pk_with_include_clause ( k2 text NOT NULL, v double precision, @@ -361,6 +429,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16584'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16583'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16582'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16585'::pg_catalog.oid); + CREATE TABLE public.range_tbl_pk_with_multiple_included_columns ( col1 integer NOT NULL, col2 integer NOT NULL, @@ -386,6 +462,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16463'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16462'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16461'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16464'::pg_catalog.oid); + CREATE TABLE public.rls_private ( k integer NOT NULL, v text, @@ -412,6 +496,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16458'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16457'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16456'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16459'::pg_catalog.oid); + CREATE TABLE public.rls_public ( k integer NOT NULL, v text, @@ -436,6 +528,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16388'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16387'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16386'::pg_catalog.oid); + CREATE TABLE public.tbl1 ( a integer NOT NULL, b integer @@ -459,6 +555,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16438'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16437'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16436'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16439'::pg_catalog.oid); + CREATE TABLE public.tbl10 ( a integer NOT NULL, b integer NOT NULL, @@ -485,6 +589,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16443'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16442'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16441'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16444'::pg_catalog.oid); + CREATE TABLE public.tbl11 ( a integer NOT NULL, b integer NOT NULL, @@ -509,6 +621,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16448'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16447'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16446'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16449'::pg_catalog.oid); + CREATE TABLE public.tbl12 ( a integer NOT NULL, b integer, @@ -534,6 +654,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16453'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16452'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16451'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16454'::pg_catalog.oid); + CREATE TABLE public.tbl13 ( a integer, b integer NOT NULL, @@ -553,6 +681,10 @@ SPLIT INTO 3 TABLETS; -- +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16384'::pg_catalog.oid); + + -- For binary upgrade, must preserve pg_type oid SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16385'::pg_catalog.oid); @@ -588,6 +720,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16394'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16393'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16392'::pg_catalog.oid); + CREATE TABLE public.tbl2 ( a integer NOT NULL ) @@ -603,6 +739,10 @@ SPLIT INTO 3 TABLETS; -- +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16390'::pg_catalog.oid); + + -- For binary upgrade, must preserve pg_type oid SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16391'::pg_catalog.oid); @@ -638,6 +778,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16398'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16397'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16396'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16399'::pg_catalog.oid); + CREATE TABLE public.tbl3 ( a integer NOT NULL, b integer, @@ -661,6 +809,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16403'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16402'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16401'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16404'::pg_catalog.oid); + CREATE TABLE public.tbl4 ( a integer NOT NULL, b integer NOT NULL, @@ -685,6 +841,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16408'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16407'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16406'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16409'::pg_catalog.oid); + CREATE TABLE public.tbl5 ( a integer NOT NULL, b integer, @@ -710,6 +874,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16413'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16412'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16411'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16414'::pg_catalog.oid); + CREATE TABLE public.tbl6 ( a integer NOT NULL, CONSTRAINT tbl6_pkey PRIMARY KEY((a) HASH) @@ -733,6 +905,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16418'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16417'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16416'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16419'::pg_catalog.oid); + CREATE TABLE public.tbl7 ( a integer, b integer NOT NULL, @@ -759,6 +939,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16423'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16422'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16421'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16424'::pg_catalog.oid); + CREATE TABLE public.tbl8 ( a integer NOT NULL, b integer, @@ -785,6 +973,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16433'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16432'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16431'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16434'::pg_catalog.oid); + CREATE TABLE public.tbl9 ( a integer NOT NULL, b integer NOT NULL, @@ -810,6 +1006,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16503'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16502'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16501'::pg_catalog.oid); + CREATE TABLE public.tgroup_after_options ( a integer ) @@ -833,6 +1033,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16509'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16508'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16507'::pg_catalog.oid); + CREATE TABLE public.tgroup_empty_options ( a integer ) @@ -855,6 +1059,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16506'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16505'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16504'::pg_catalog.oid); + CREATE TABLE public.tgroup_in_between_options ( a integer ) @@ -878,6 +1086,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16485'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16484'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16483'::pg_catalog.oid); + CREATE TABLE public.tgroup_no_options_and_tgroup ( a integer ) @@ -901,6 +1113,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16488'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16487'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16486'::pg_catalog.oid); + CREATE TABLE public.tgroup_one_option ( a integer ) @@ -924,6 +1140,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16491'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16490'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16489'::pg_catalog.oid); + CREATE TABLE public.tgroup_one_option_and_tgroup ( a integer ) @@ -947,6 +1167,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16494'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16493'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16492'::pg_catalog.oid); + CREATE TABLE public.tgroup_options ( a integer ) @@ -970,6 +1194,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16497'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16496'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16495'::pg_catalog.oid); + CREATE TABLE public.tgroup_options_and_tgroup ( a integer ) @@ -993,6 +1221,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16500'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16499'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16498'::pg_catalog.oid); + CREATE TABLE public.tgroup_options_tgroup_and_custom_colocation_id ( a integer ) @@ -1016,6 +1248,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16512'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16511'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16510'::pg_catalog.oid); + CREATE TABLE public.tgroup_with_spc ( a integer ) @@ -1039,6 +1275,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16515'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16514'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16513'::pg_catalog.oid); + CREATE TABLE public.th1 ( a integer, b text, @@ -1063,6 +1303,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16518'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16517'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16516'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16519'::pg_catalog.oid); + CREATE TABLE public.th2 ( a integer NOT NULL, b text NOT NULL, @@ -1088,6 +1336,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16523'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16522'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16521'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16524'::pg_catalog.oid); + CREATE TABLE public.th3 ( a integer NOT NULL, b text NOT NULL, @@ -1113,6 +1369,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16528'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16527'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16526'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16529'::pg_catalog.oid); + CREATE TABLE public.tr1 ( a integer NOT NULL, b text, @@ -1138,6 +1402,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16533'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16532'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16531'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16534'::pg_catalog.oid); + CREATE TABLE public.tr2 ( a integer NOT NULL, b text NOT NULL, @@ -1163,6 +1435,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16476'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16475'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16474'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16477'::pg_catalog.oid); + CREATE TABLE public.uaccount ( pguser name NOT NULL, seclv integer, @@ -1542,6 +1822,10 @@ SELECT pg_catalog.setval('public.tbl2_a_seq', 1, false); -- Name: p1 c1; Type: CONSTRAINT; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16561'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY c1 ON public.p1 USING lsm (v ASC) SPLIT AT VALUES (('foo'), ('qux')); ALTER TABLE ONLY public.p1 @@ -1552,6 +1836,10 @@ ALTER TABLE ONLY public.p1 -- Name: p2 c2; Type: CONSTRAINT; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16568'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY c2 ON public.p2 USING lsm (v HASH) SPLIT INTO 10 TABLETS; ALTER TABLE ONLY public.p2 @@ -1562,6 +1850,10 @@ ALTER TABLE ONLY public.p2 -- Name: hints_norm_and_app; Type: INDEX; Schema: hint_plan; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16555'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY hints_norm_and_app ON hint_plan.hints USING lsm (norm_query_string HASH, application_name ASC) SPLIT INTO 3 TABLETS; @@ -1569,6 +1861,10 @@ CREATE UNIQUE INDEX NONCONCURRENTLY hints_norm_and_app ON hint_plan.hints USING -- Name: non_unique_idx_with_include_clause; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16581'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY non_unique_idx_with_include_clause ON public.hash_tbl_pk_with_include_clause USING lsm (k1 HASH, k2 ASC) INCLUDE (v) SPLIT INTO 3 TABLETS; @@ -1576,6 +1872,10 @@ CREATE UNIQUE INDEX NONCONCURRENTLY non_unique_idx_with_include_clause ON public -- Name: tbl8_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16426'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY tbl8_idx ON public.tbl8 USING lsm ((b, c) HASH) SPLIT INTO 3 TABLETS; @@ -1583,6 +1883,10 @@ CREATE INDEX NONCONCURRENTLY tbl8_idx ON public.tbl8 USING lsm ((b, c) HASH) SPL -- Name: tbl8_idx2; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16427'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY tbl8_idx2 ON public.tbl8 USING lsm (a HASH, b ASC) SPLIT INTO 3 TABLETS; @@ -1590,6 +1894,10 @@ CREATE INDEX NONCONCURRENTLY tbl8_idx2 ON public.tbl8 USING lsm (a HASH, b ASC) -- Name: tbl8_idx3; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16428'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY tbl8_idx3 ON public.tbl8 USING lsm (b ASC); @@ -1597,6 +1905,10 @@ CREATE INDEX NONCONCURRENTLY tbl8_idx3 ON public.tbl8 USING lsm (b ASC); -- Name: tbl8_idx4; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16429'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY tbl8_idx4 ON public.tbl8 USING lsm (b DESC); @@ -1604,6 +1916,10 @@ CREATE INDEX NONCONCURRENTLY tbl8_idx4 ON public.tbl8 USING lsm (b DESC); -- Name: tbl8_idx5; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16430'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY tbl8_idx5 ON public.tbl8 USING lsm (c HASH) SPLIT INTO 3 TABLETS; @@ -1611,6 +1927,10 @@ CREATE INDEX NONCONCURRENTLY tbl8_idx5 ON public.tbl8 USING lsm (c HASH) SPLIT I -- Name: th2_c_b_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16541'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY th2_c_b_idx ON public.th2 USING lsm (c HASH, b DESC) SPLIT INTO 4 TABLETS; @@ -1618,6 +1938,10 @@ CREATE INDEX NONCONCURRENTLY th2_c_b_idx ON public.th2 USING lsm (c HASH, b DESC -- Name: th3_c_b_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16542'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY th3_c_b_idx ON public.th3 USING lsm ((c, b) HASH) SPLIT INTO 3 TABLETS; @@ -1625,6 +1949,10 @@ CREATE INDEX NONCONCURRENTLY th3_c_b_idx ON public.th3 USING lsm ((c, b) HASH) S -- Name: tr2_c_b_a_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16544'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY tr2_c_b_a_idx ON public.tr2 USING lsm (c ASC, b DESC, a ASC) SPLIT AT VALUES ((-5.12000000000000011, 'z', 1), (-0.75, 'l', MINVALUE), (2.5, 'a', 100)); @@ -1632,6 +1960,10 @@ CREATE INDEX NONCONCURRENTLY tr2_c_b_a_idx ON public.tr2 USING lsm (c ASC, b DES -- Name: tr2_c_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16543'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY tr2_c_idx ON public.tr2 USING lsm (c DESC) SPLIT AT VALUES ((100.5), (1.5)); @@ -1639,6 +1971,10 @@ CREATE INDEX NONCONCURRENTLY tr2_c_idx ON public.tr2 USING lsm (c DESC) SPLIT AT -- Name: unique_idx_with_include_clause; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16575'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY unique_idx_with_include_clause ON public.range_tbl_pk_with_include_clause USING lsm (k1 HASH, k2 ASC) INCLUDE (v) SPLIT INTO 3 TABLETS; diff --git a/src/postgres/src/test/regress/data/yb_ysql_dump_colocated_database.data.sql b/src/postgres/src/test/regress/data/yb_ysql_dump_colocated_database.data.sql index c30ff67b7d5b..0d6e048eb1d9 100644 --- a/src/postgres/src/test/regress/data/yb_ysql_dump_colocated_database.data.sql +++ b/src/postgres/src/test/regress/data/yb_ysql_dump_colocated_database.data.sql @@ -48,6 +48,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16412'::pg_catalog.oid); SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16411'::pg_catalog.oid); +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16410'::pg_catalog.oid); + + -- For YB colocation backup, must preserve implicit tablegroup pg_yb_tablegroup oid SELECT pg_catalog.binary_upgrade_set_next_tablegroup_oid('16387'::pg_catalog.oid); CREATE TABLE public.htest ( @@ -77,6 +81,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16415'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16414'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16413'::pg_catalog.oid); + CREATE TABLE public.htest_1 PARTITION OF public.htest FOR VALUES WITH (modulus 2, remainder 0) WITH (colocation_id='234567'); @@ -98,6 +106,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16386'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16385'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16384'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16388'::pg_catalog.oid); + CREATE TABLE public.tbl ( k integer NOT NULL, v integer, @@ -122,6 +138,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16392'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16391'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16390'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16393'::pg_catalog.oid); + CREATE TABLE public.tbl2 ( k integer NOT NULL, v integer, @@ -147,6 +171,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16401'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16400'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16399'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16402'::pg_catalog.oid); + CREATE TABLE public.tbl3 ( k integer NOT NULL, v integer, @@ -172,6 +204,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16407'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16406'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16405'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16408'::pg_catalog.oid); + CREATE TABLE public.tbl4 ( k integer NOT NULL, v integer, @@ -230,6 +270,10 @@ COPY public.tbl4 (k, v, v2) FROM stdin; -- Name: partial_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16398'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY partial_idx ON public.tbl2 USING lsm (k ASC, v DESC) WITH (colocation_id=40001) WHERE ((k > 10) AND (k < 20) AND (v > 200)); @@ -237,6 +281,10 @@ CREATE INDEX NONCONCURRENTLY partial_idx ON public.tbl2 USING lsm (k ASC, v DESC -- Name: partial_unique_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16397'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY partial_unique_idx ON public.tbl USING lsm (v DESC) WITH (colocation_id=40000) WHERE ((v >= 100) AND (v <= 200)); @@ -244,6 +292,10 @@ CREATE UNIQUE INDEX NONCONCURRENTLY partial_unique_idx ON public.tbl USING lsm ( -- Name: tbl2_v2_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16396'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY tbl2_v2_idx ON public.tbl2 USING lsm (v2 ASC) WITH (colocation_id=20004); @@ -251,6 +303,10 @@ CREATE INDEX NONCONCURRENTLY tbl2_v2_idx ON public.tbl2 USING lsm (v2 ASC) WITH -- Name: tbl3_v_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16404'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY tbl3_v_idx ON public.tbl3 USING lsm (v HASH) SPLIT INTO 3 TABLETS; @@ -258,6 +314,10 @@ CREATE UNIQUE INDEX NONCONCURRENTLY tbl3_v_idx ON public.tbl3 USING lsm (v HASH) -- Name: tbl_v_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16395'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY tbl_v_idx ON public.tbl USING lsm (v DESC) WITH (colocation_id=20003); diff --git a/src/postgres/src/test/regress/data/yb_ysql_dump_legacy_colocated_database.data.sql b/src/postgres/src/test/regress/data/yb_ysql_dump_legacy_colocated_database.data.sql index 4d4f9228263d..8560ced2c450 100644 --- a/src/postgres/src/test/regress/data/yb_ysql_dump_legacy_colocated_database.data.sql +++ b/src/postgres/src/test/regress/data/yb_ysql_dump_legacy_colocated_database.data.sql @@ -47,6 +47,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16411'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16410'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16409'::pg_catalog.oid); + CREATE TABLE public.htest ( k1 integer, k2 text, @@ -74,6 +78,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16414'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16413'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16412'::pg_catalog.oid); + CREATE TABLE public.htest_1 PARTITION OF public.htest FOR VALUES WITH (modulus 2, remainder 0) WITH (colocation_id='234567'); @@ -95,6 +103,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16386'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16385'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16384'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16387'::pg_catalog.oid); + CREATE TABLE public.tbl ( k integer NOT NULL, v integer, @@ -119,6 +135,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16391'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16390'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16389'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16392'::pg_catalog.oid); + CREATE TABLE public.tbl2 ( k integer NOT NULL, v integer, @@ -144,6 +168,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16400'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16399'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16398'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16401'::pg_catalog.oid); + CREATE TABLE public.tbl3 ( k integer NOT NULL, v integer, @@ -169,6 +201,14 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16406'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16405'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16404'::pg_catalog.oid); + + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16407'::pg_catalog.oid); + CREATE TABLE public.tbl4 ( k integer NOT NULL, v integer, @@ -227,6 +267,10 @@ COPY public.tbl4 (k, v, v2) FROM stdin; -- Name: partial_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16397'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY partial_idx ON public.tbl2 USING lsm (k ASC, v DESC) WITH (colocation_id=40001) WHERE ((k > 10) AND (k < 20) AND (v > 200)); @@ -234,6 +278,10 @@ CREATE INDEX NONCONCURRENTLY partial_idx ON public.tbl2 USING lsm (k ASC, v DESC -- Name: partial_unique_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16396'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY partial_unique_idx ON public.tbl USING lsm (v DESC) WITH (colocation_id=40000) WHERE ((v >= 100) AND (v <= 200)); @@ -241,6 +289,10 @@ CREATE UNIQUE INDEX NONCONCURRENTLY partial_unique_idx ON public.tbl USING lsm ( -- Name: tbl2_v2_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16395'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY tbl2_v2_idx ON public.tbl2 USING lsm (v2 ASC) WITH (colocation_id=20004); @@ -248,6 +300,10 @@ CREATE INDEX NONCONCURRENTLY tbl2_v2_idx ON public.tbl2 USING lsm (v2 ASC) WITH -- Name: tbl3_v_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16403'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY tbl3_v_idx ON public.tbl3 USING lsm (v HASH) SPLIT INTO 3 TABLETS; @@ -255,6 +311,10 @@ CREATE UNIQUE INDEX NONCONCURRENTLY tbl3_v_idx ON public.tbl3 USING lsm (v HASH) -- Name: tbl_v_idx; Type: INDEX; Schema: public; Owner: yugabyte_test -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16394'::pg_catalog.oid); + CREATE UNIQUE INDEX NONCONCURRENTLY tbl_v_idx ON public.tbl USING lsm (v DESC) WITH (colocation_id=20003); diff --git a/src/postgres/src/test/regress/data/yb_ysql_dumpall.data.sql b/src/postgres/src/test/regress/data/yb_ysql_dumpall.data.sql index 6426cf48435e..579271776022 100644 --- a/src/postgres/src/test/regress/data/yb_ysql_dumpall.data.sql +++ b/src/postgres/src/test/regress/data/yb_ysql_dumpall.data.sql @@ -453,6 +453,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16386'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16385'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16384'::pg_catalog.oid); + CREATE TABLE public.table1 ( id integer ) @@ -479,6 +483,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16390'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16389'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16388'::pg_catalog.oid); + CREATE TABLE public.table2 ( name character varying ) @@ -505,6 +513,10 @@ SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('16396'::pg_catalog.oid); -- For binary upgrade, must preserve pg_type array oid SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('16395'::pg_catalog.oid); + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('16394'::pg_catalog.oid); + CREATE TABLE public.tbl_with_grp_with_spc ( a integer ) @@ -548,6 +560,10 @@ COPY public.tbl_with_grp_with_spc (a) FROM stdin; -- Name: idx1; Type: INDEX; Schema: public; Owner: yugabyte_test; Tablespace: tsp2 -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16387'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY idx1 ON public.table1 USING lsm (id HASH) SPLIT INTO 3 TABLETS; @@ -559,6 +575,10 @@ CREATE INDEX NONCONCURRENTLY idx1 ON public.table1 USING lsm (id HASH) SPLIT INT -- Name: idx2; Type: INDEX; Schema: public; Owner: yugabyte_test; Tablespace: tsp1 -- + +-- For binary upgrade, must preserve pg_class oids +SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('16391'::pg_catalog.oid); + CREATE INDEX NONCONCURRENTLY idx2 ON public.table2 USING lsm (name HASH) SPLIT INTO 3 TABLETS; diff --git a/src/yb/tools/yb-backup/yb-backup-cross-feature-test.cc b/src/yb/tools/yb-backup/yb-backup-cross-feature-test.cc index f7a22234d004..a5780cc16674 100644 --- a/src/yb/tools/yb-backup/yb-backup-cross-feature-test.cc +++ b/src/yb/tools/yb-backup/yb-backup-cross-feature-test.cc @@ -2292,5 +2292,166 @@ TEST_F(YBBackupTest, YB_DISABLE_TEST_IN_SANITIZERS(TestBackupWithFailedLegacyRew (5 rows) )#")); } + +TEST_F_EX( + YBBackupTest, YB_DISABLE_TEST_IN_SANITIZERS(TestPreservingPgEnumOids), + YBBackupTestOneTablet) { + + // Backup only works when there is at least one table so create one. + ASSERT_NO_FATALS(CreateTable( + Format("CREATE TABLE gratuitous_table (a INT, b INT)", "gratuitous_table"))); + + // Create some enums intermixed with filler ones then drop the fillers. + // The filler enums will ensure the non-filler enums don't just use the default OIDs. + ASSERT_NO_FATALS(CreateType("CREATE TYPE filler_1 AS ENUM ('A','B','C')")); + ASSERT_NO_FATALS(CreateType("CREATE TYPE e_contact_method AS ENUM ('Email','Sms','Phone','A')")); + ASSERT_NO_FATALS(CreateType("CREATE TYPE filler_2 AS ENUM ('A','B','C')")); + ASSERT_NO_FATALS(CreateType("CREATE TYPE empty_enum AS ENUM ()")); + ASSERT_NO_FATALS(CreateType("CREATE TYPE twofold AS ENUM ('A', 'B')")); + ASSERT_NO_FATALS(RunPsqlCommand("DROP TYPE filler_1", "DROP TYPE")); + ASSERT_NO_FATALS(RunPsqlCommand("DROP TYPE filler_2", "DROP TYPE")); + + // Backup then restore to a new database. + const string backup_dir = GetTempDir("backup"); + ASSERT_OK(RunBackupCommand( + {"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"})); + ASSERT_OK(RunBackupCommand( + {"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte_new", "restore"})); + + auto query = "SELECT oid, enumlabel FROM pg_enum ORDER BY oid ASC"; + Result result{""}; + ASSERT_NO_FATALS(result = RunPsqlCommand(query)); + ASSERT_OK(result); + LOG(INFO) << "***** pg_enum OIDs on namespace being backed up are: " << *result; + + SetDbName("yugabyte_new"); + ASSERT_NO_FATALS(RunPsqlCommand(query, *result)); +} + +TEST_F_EX( + YBBackupTest, YB_DISABLE_TEST_IN_SANITIZERS(TestPreservingPgTypeAndClassOids), + YBBackupTestOneTablet) { + // Attempt to create one instance of each thing that consumes a pg_type or pg_class OID. Also + // create some fillers that will we will drop at the end to make sure we don't just use the same + // default OIDs by accident. + + ASSERT_NO_FATALS(CreateTable("CREATE TABLE filler_table (a INT, b INT)")); + ASSERT_NO_FATALS(CreateTable("CREATE TABLE filler_table_2 (a INT, b INT)")); + + // Creating basic tables. + ASSERT_NO_FATALS(CreateTable("CREATE TABLE simple_table (a INT, b INT)")); + // Backup ignores temporary tables so no need to test. + + // Creating tables with indexes and constraints. + ASSERT_NO_FATALS( + CreateTable("CREATE TABLE table_with_primary_key (a INT PRIMARY KEY, b INT, c INT)")); + ASSERT_NO_FATALS(CreateTable("CREATE TABLE indexed_table (a INT, b INT)")); + ASSERT_NO_FATALS(CreateIndex("CREATE INDEX simple_index ON indexed_table (a DESC)")); + // This is a special case due to D6956, where we create the table and the primary key index + // simultaneously. + ASSERT_NO_FATALS(CreateTable( + "CREATE TABLE table_with_index_and_constraint (k INT PRIMARY KEY, v TEXT, UNIQUE (v))")); + ASSERT_NO_FATALS(CreateTable("CREATE TABLE constrained_table (a INT, b INT)")); + ASSERT_NO_FATALS(RunPsqlCommand( + "ALTER TABLE constrained_table ADD CONSTRAINT equality_constraint CHECK (a = b)", + "ALTER TABLE")); + ASSERT_NO_FATALS(RunPsqlCommand( + "ALTER TABLE constrained_table ADD CONSTRAINT positive_constraint CHECK (a > 0)", + "ALTER TABLE")); + // Another special case due to D6956; note that a separate index/OID is created for + // htest_1 automatically. + ASSERT_NO_FATALS(CreateTable( + "CREATE TABLE htest(k1 INT, k2 TEXT, k3 INT, v1 INT, v2 TEXT, PRIMARY KEY(k1, k2)) PARTITION " + "BY HASH (k1)")); + ASSERT_NO_FATALS(CreateTable( + "CREATE TABLE htest_1 PARTITION OF htest(k1, k2, k3, v1, v2) FOR VALUES WITH (MODULUS 2, " + "REMAINDER 0)")); + + // Attempt to create a table with an accompanying TOAST table; this does not actually work with + // YugabyteDB, which does not use TOAST tables. + ASSERT_NO_FATALS( + CreateTable("CREATE TABLE table_using_toast (id SERIAL PRIMARY KEY, data TEXT)")); + ASSERT_NO_FATALS( + InsertOneRow("INSERT INTO table_using_toast (data) VALUES (repeat('A', 5000))")); + + // Creating sequences, both standalone and as part of a table. + ASSERT_NO_FATALS(CreateSequence("CREATE SEQUENCE standalone_sequence")); + ASSERT_NO_FATALS(CreateTable("CREATE TABLE table_with_serial_column (key SERIAL, value TEXT)")); + ASSERT_NO_FATALS( + CreateTable("CREATE TABLE table_with_2_serial_columns (key SERIAL, id SERIAL, value TEXT)")); + ASSERT_NO_FATALS( + CreateTable("CREATE TABLE table_with_default_sequence (" + "id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (INCREMENT 7 START " + "77777),value INTEGER)")); + ASSERT_NO_FATALS(CreateSequence("CREATE SEQUENCE sequence_created_first")); + ASSERT_NO_FATALS( + CreateTable("CREATE TABLE table_using_existing_sequence (id INTEGER DEFAULT " + "nextval('sequence_created_first'),value INTEGER)")); + ASSERT_NO_FATALS(CreateTable( + "CREATE TABLE table_with_primary_serial_key (a SERIAL PRIMARY KEY, b INT, c INT)")); + + // Creating table-like things. + ASSERT_NO_FATALS(RunPsqlCommand( + "CREATE VIEW view AS SELECT a, b FROM simple_table WHERE a = b", "CREATE VIEW")); + ASSERT_NO_FATALS(RunPsqlCommand( + "CREATE MATERIALIZED VIEW materialized_view AS SELECT a, b FROM simple_table", "SELECT 0")); + // Not possible to create a materialized view with a primary key directly so no D6956 special case + // exists for materialized views. + // The following currently produces warnings because FOREIGN DATA WRAPPER is a YSQL beta feature. + // This doesn't matter for this test, however. + ASSERT_NO_FATALS( + RunPsqlCommand("CREATE FOREIGN DATA WRAPPER dummy_wrapper", "CREATE FOREIGN DATA WRAPPER")); + ASSERT_NO_FATALS(RunPsqlCommand( + "CREATE SERVER dummy_server FOREIGN DATA WRAPPER dummy_wrapper", "CREATE SERVER")); + ASSERT_NO_FATALS(RunPsqlCommand( + "CREATE FOREIGN TABLE test_foreign_table () SERVER dummy_server", "CREATE FOREIGN TABLE")); + + // Create one of each type of Postgres type not already covered. + ASSERT_NO_FATALS(CreateType("CREATE TYPE composite_type AS (x INT, y INT)")); + ASSERT_NO_FATALS(CreateType("CREATE TYPE twofold AS ENUM ('A', 'B')")); + ASSERT_NO_FATALS(CreateType("CREATE TYPE date_range AS RANGE (subtype = DATE)")); + ASSERT_NO_FATALS(CreateType("CREATE TYPE shell_type")); + ASSERT_NO_FATALS(RunPsqlCommand( + "CREATE DOMAIN email_address AS VARCHAR CHECK (VALUE ~ " + "'^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$')", + "CREATE DOMAIN")); + // This extension creates a new base type, vector. + ASSERT_NO_FATALS(RunPsqlCommand("CREATE EXTENSION vector", "CREATE EXTENSION")); + + // Done creating stuff, time to drop the filler objects. + ASSERT_NO_FATALS(RunPsqlCommand("DROP TABLE filler_table", "DROP TABLE")); + ASSERT_NO_FATALS(RunPsqlCommand("DROP TABLE filler_table_2", "DROP TABLE")); + + // Backup then restore to a new database. + const string backup_dir = GetTempDir("backup"); + ASSERT_OK(RunBackupCommand( + {"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"})); + ASSERT_OK(RunBackupCommand( + {"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte_new", "restore"})); + + // Assert the pg type OIDs are the same in both databases. + { + auto query = "SELECT oid, typname FROM pg_type ORDER BY oid ASC"; + Result query_result{""}; + SetDbName("yugabyte"); + ASSERT_NO_FATALS(query_result = RunPsqlCommand(query)); + ASSERT_OK(query_result); + LOG(INFO) << "***** pg_type OIDs on namespace being backed up are: " << *query_result; + SetDbName("yugabyte_new"); + ASSERT_NO_FATALS(RunPsqlCommand(query, *query_result)); + } + + // Assert the pg class OIDs are the same in both databases. + { + auto query = "SELECT oid, relname FROM pg_class ORDER BY oid ASC"; + Result query_result{""}; + SetDbName("yugabyte"); + ASSERT_NO_FATALS(query_result = RunPsqlCommand(query)); + ASSERT_OK(query_result); + LOG(INFO) << "***** pg_class OIDs on namespace being backed up are: " << *query_result; + SetDbName("yugabyte_new"); + ASSERT_NO_FATALS(RunPsqlCommand(query, *query_result)); + } +} } // namespace tools } // namespace yb diff --git a/src/yb/yql/pgwrapper/pg_wrapper_test_base.h b/src/yb/yql/pgwrapper/pg_wrapper_test_base.h index 0d627be01659..41976191ce29 100644 --- a/src/yb/yql/pgwrapper/pg_wrapper_test_base.h +++ b/src/yb/yql/pgwrapper/pg_wrapper_test_base.h @@ -71,6 +71,10 @@ class PgCommandTestBase : public PgWrapperTestBase { RunPsqlCommand(statement, "CREATE TYPE"); } + void CreateSequence(const std::string &statement) { + RunPsqlCommand(statement, "CREATE SEQUENCE"); + } + void CreateIndex(const std::string &statement) { RunPsqlCommand(statement, "CREATE INDEX"); }