@@ -266,7 +266,6 @@ static void dumpForeignServer(Archive *fout, const ForeignServerInfo *srvinfo);
266266
267267/* GPDB follow upstream style */
268268static void dumpExtProtocol(Archive *fout, const ExtProtInfo *ptcinfo);
269- static void dumpTypeStorageOptions(Archive *fout, const TypeStorageOptions *tstorageoptions);
270269
271270static void dumpUserMappings(Archive *fout,
272271 const char *servername, const char *namespace,
@@ -368,6 +367,7 @@ static bool forcePartitionRootLoad(const TableInfo *tbinfo);
368367
369368
370369/* START MPP ADDITION */
370+ static void dumpTypeStorageOptions(Archive *fout, const TypeInfo *tyinfo);
371371static void setExtPartDependency(TableInfo *tblinfo, int numTables);
372372static char *format_table_function_columns(Archive *fout, const FuncInfo *finfo, int nallargs,
373373 char **allargtypes,
@@ -5948,6 +5948,7 @@ getTypes(Archive *fout, int *numTypes)
59485948 int i_typtype;
59495949 int i_typisdefined;
59505950 int i_isarray;
5951+ int i_typstorage;
59515952
59525953 /*
59535954 * we include even the built-in types because those may be used as array
@@ -5988,8 +5989,10 @@ getTypes(Archive *fout, int *numTypes)
59885989 "ELSE (SELECT relkind FROM pg_class WHERE oid = t.typrelid) END AS typrelkind, "
59895990 "t.typtype, t.typisdefined, "
59905991 "t.typname[0] = '_' AND t.typelem != 0 AND "
5991- "(SELECT typarray FROM pg_type te WHERE oid = t.typelem) = t.oid AS isarray "
5992+ "(SELECT typarray FROM pg_type te WHERE oid = t.typelem) = t.oid AS isarray, "
5993+ "coalesce(array_to_string(e.typoptions, ', '), '') AS typstorage "
59925994 "FROM pg_type t "
5995+ "LEFT JOIN pg_type_encoding e ON t.oid = e.typid "
59935996 "LEFT JOIN pg_init_privs pip ON "
59945997 "(t.oid = pip.objoid "
59955998 "AND pip.classoid = 'pg_type'::regclass "
@@ -6057,6 +6060,7 @@ getTypes(Archive *fout, int *numTypes)
60576060 i_typtype = PQfnumber(res, "typtype");
60586061 i_typisdefined = PQfnumber(res, "typisdefined");
60596062 i_isarray = PQfnumber(res, "isarray");
6063+ i_typstorage = PQfnumber(res, "typstorage");
60606064
60616065 for (i = 0; i < ntups; i++)
60626066 {
@@ -6089,6 +6093,8 @@ getTypes(Archive *fout, int *numTypes)
60896093 else
60906094 tyinfo[i].isArray = false;
60916095
6096+ tyinfo[i].typstorage = pg_strdup(PQgetvalue(res, i, i_typstorage));
6097+
60926098 if (tyinfo[i].typtype == 'm')
60936099 tyinfo[i].isMultirange = true;
60946100 else
@@ -6157,91 +6163,6 @@ getTypes(Archive *fout, int *numTypes)
61576163 return tyinfo;
61586164}
61596165
6160-
6161-
6162- /*
6163- * getTypeStorageOptions:
6164- * read all types with storage options in the system catalogs and return them in the
6165- * TypeStorageOptions* structure
6166- *
6167- * numTypes is set to the number of types with storage options read in
6168- *
6169- */
6170- TypeStorageOptions *
6171- getTypeStorageOptions(Archive *fout, int *numTypes)
6172- {
6173- PGresult *res;
6174- int ntups;
6175- int i;
6176- PQExpBuffer query = createPQExpBuffer();
6177- TypeStorageOptions *tstorageoptions;
6178- int i_tableoid;
6179- int i_oid;
6180- int i_typname;
6181- int i_typnamespace;
6182- int i_typoptions;
6183- int i_rolname;
6184-
6185- /*
6186- * The following statement used format_type to resolve an internal name to its equivalent sql name.
6187- * The format_type seems to do two things, it translates an internal type name (e.g. bpchar) into its
6188- * sql equivalent (e.g. character), and it puts trailing "[]" on a type if it is an array.
6189- * For any user defined type (ie. oid > 10000) or any type that might be an array (ie. starts with '_'),
6190- * then we will call quote_ident. If the type is a system defined type (i.e. oid <= 10000)
6191- * and can not possibly be an array (i.e. does not start with '_'), then call format_type to get the name. The
6192- * reason we do not call format_type for arrays is that it will return a '[]' on the end, which can not be used
6193- * when dumping the type.
6194- */
6195- appendPQExpBuffer(query, "SELECT "
6196- "CASE WHEN t.oid > 10000 OR substring(t.typname from 1 for 1) = '_' "
6197- "THEN quote_ident(t.typname) "
6198- "ELSE pg_catalog.format_type(t.oid, NULL) "
6199- "END as typname, "
6200- "t.tableoid as tableoid, "
6201- "t.oid AS oid, "
6202- "t.typnamespace AS typnamespace, "
6203- "(%s typowner) as rolname, "
6204- "array_to_string(a.typoptions, ', ') AS typoptions "
6205- "FROM pg_type t "
6206- "JOIN pg_catalog.pg_type_encoding a ON a.typid = t.oid "
6207- "WHERE t.typisdefined = 't'", username_subquery);
6208-
6209- res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6210-
6211- ntups = PQntuples(res);
6212-
6213- tstorageoptions = (TypeStorageOptions *) pg_malloc(ntups * sizeof(TypeStorageOptions));
6214-
6215- i_tableoid = PQfnumber(res, "tableoid");
6216- i_oid = PQfnumber(res, "oid");
6217- i_typname = PQfnumber(res, "typname");
6218- i_typnamespace = PQfnumber(res, "typnamespace");
6219- i_typoptions = PQfnumber(res, "typoptions");
6220- i_rolname = PQfnumber(res, "rolname");
6221-
6222- for (i = 0; i < ntups; i++)
6223- {
6224- tstorageoptions[i].dobj.objType = DO_TYPE_STORAGE_OPTIONS;
6225- tstorageoptions[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6226- tstorageoptions[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6227- AssignDumpId(&tstorageoptions[i].dobj);
6228- tstorageoptions[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname));
6229- tstorageoptions[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_typnamespace)));
6230- tstorageoptions[i].typoptions = pg_strdup(PQgetvalue(res, i, i_typoptions));
6231- tstorageoptions[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
6232- }
6233-
6234- *numTypes = ntups;
6235-
6236- PQclear(res);
6237-
6238- destroyPQExpBuffer(query);
6239-
6240- return tstorageoptions;
6241- }
6242-
6243-
6244-
62456166/*
62466167 * getOperators:
62476168 * read all operators in the system catalogs and return them in the
@@ -11488,9 +11409,6 @@ dumpDumpableObject(Archive *fout, const DumpableObject *dobj)
1148811409 case DO_TYPE:
1148911410 dumpType(fout, (const TypeInfo *) dobj);
1149011411 break;
11491- case DO_TYPE_STORAGE_OPTIONS:
11492- dumpTypeStorageOptions(fout, (const TypeStorageOptions *) dobj);
11493- break;
1149411412 case DO_SHELL_TYPE:
1149511413 dumpShellType(fout, (const ShellTypeInfo *) dobj);
1149611414 break;
@@ -11871,6 +11789,10 @@ dumpType(Archive *fout, const TypeInfo *tyinfo)
1187111789 else
1187211790 pg_log_warning("typtype of data type \"%s\" appears to be invalid",
1187311791 tyinfo->dobj.name);
11792+
11793+ if (tyinfo->typstorage && *tyinfo->typstorage != '\0')
11794+ dumpTypeStorageOptions(fout, tyinfo);
11795+
1187411796}
1187511797
1187611798/*
@@ -12486,36 +12408,28 @@ dumpBaseType(Archive *fout, const TypeInfo *tyinfo)
1248612408 * writes out to fout the ALTER TYPE queries to set default storage options for type
1248712409 */
1248812410static void
12489- dumpTypeStorageOptions(Archive *fout, const TypeStorageOptions *tstorageoptions )
12411+ dumpTypeStorageOptions(Archive *fout, const TypeInfo *tyinfo )
1249012412{
1249112413 PQExpBuffer q;
12492- PQExpBuffer delq;
12493-
1249412414 q = createPQExpBuffer();
12495- delq = createPQExpBuffer();
1249612415
12497- /*
12498- * Type name is already quoted by caller using quote_ident, hence used
12499- * directly here.
12500- */
1250112416 appendPQExpBuffer(q, "ALTER TYPE %s.",
12502- fmtId(tstorageoptions ->dobj.namespace->dobj.name));
12417+ fmtId(tyinfo ->dobj.namespace->dobj.name));
1250312418 appendPQExpBuffer(q, "%s SET DEFAULT ENCODING (%s);\n",
12504- tstorageoptions ->dobj.name,
12505- tstorageoptions->typoptions );
12419+ fmtId(tyinfo ->dobj.name) ,
12420+ tyinfo->typstorage );
1250612421
1250712422 ArchiveEntry(fout,
12508- tstorageoptions ->dobj.catId,
12509- tstorageoptions ->dobj.dumpId,
12510- ARCHIVE_OPTS(.tag = tstorageoptions ->dobj.name,
12511- .namespace = tstorageoptions ->dobj.namespace->dobj.name,
12512- .owner = tstorageoptions ->rolname,
12423+ tyinfo ->dobj.catId,
12424+ tyinfo ->dobj.dumpId,
12425+ ARCHIVE_OPTS(.tag = tyinfo ->dobj.name,
12426+ .namespace = tyinfo ->dobj.namespace->dobj.name,
12427+ .owner = tyinfo ->rolname,
1251312428 .description = "TYPE STORAGE OPTIONS",
1251412429 .section = SECTION_PRE_DATA,
1251512430 .createStmt = q->data));
1251612431
1251712432 destroyPQExpBuffer(q);
12518- destroyPQExpBuffer(delq);
1251912433}
1252012434
1252112435/*
@@ -21030,7 +20944,6 @@ addBoundaryDependencies(DumpableObject **dobjs, int numObjs,
2103020944 case DO_TRANSFORM:
2103120945 case DO_BLOB:
2103220946 case DO_EXTPROTOCOL:
21033- case DO_TYPE_STORAGE_OPTIONS:
2103420947 case DO_BINARY_UPGRADE:
2103520948 /* Pre-data objects: must come before the pre-data boundary */
2103620949 addObjectDependency(preDataBound, dobj->dumpId);
0 commit comments