@@ -2293,8 +2293,13 @@ describeOneTableDetails(const char *schemaname,
22932293 appendPQExpBufferStr (& tmpbuf , _ (", replica identity" ));
22942294
22952295 printTableAddFooter (& cont , tmpbuf .data );
2296- add_tablespace_footer (& cont , tableinfo .relkind ,
2297- tableinfo .tablespace , true);
2296+
2297+ /*
2298+ * If it's a partitioned index, we'll print the tablespace below
2299+ */
2300+ if (tableinfo .relkind == RELKIND_INDEX )
2301+ add_tablespace_footer (& cont , tableinfo .relkind ,
2302+ tableinfo .tablespace , true);
22982303 }
22992304
23002305 PQclear (result );
@@ -2304,6 +2309,7 @@ describeOneTableDetails(const char *schemaname,
23042309 tableinfo .relkind == RELKIND_MATVIEW ||
23052310 tableinfo .relkind == RELKIND_FOREIGN_TABLE ||
23062311 tableinfo .relkind == RELKIND_PARTITIONED_TABLE ||
2312+ tableinfo .relkind == RELKIND_PARTITIONED_INDEX ||
23072313 tableinfo .relkind == RELKIND_TOASTVALUE )
23082314 {
23092315 /* Footer information about a table */
@@ -3070,11 +3076,17 @@ describeOneTableDetails(const char *schemaname,
30703076 tableinfo .relkind == RELKIND_MATVIEW ||
30713077 tableinfo .relkind == RELKIND_FOREIGN_TABLE ||
30723078 tableinfo .relkind == RELKIND_PARTITIONED_TABLE ||
3079+ tableinfo .relkind == RELKIND_PARTITIONED_INDEX ||
30733080 tableinfo .relkind == RELKIND_TOASTVALUE )
30743081 {
3082+ bool is_partitioned ;
30753083 PGresult * result ;
30763084 int tuples ;
30773085
3086+ /* simplify some repeated tests below */
3087+ is_partitioned = (tableinfo .relkind == RELKIND_PARTITIONED_TABLE ||
3088+ tableinfo .relkind == RELKIND_PARTITIONED_INDEX );
3089+
30783090 /* print foreign server name */
30793091 if (tableinfo .relkind == RELKIND_FOREIGN_TABLE )
30803092 {
@@ -3115,13 +3127,15 @@ describeOneTableDetails(const char *schemaname,
31153127 PQclear (result );
31163128 }
31173129
3118- /* print inherited tables (exclude, if parent is a partitioned table ) */
3130+ /* print tables inherited from (exclude partitioned parents ) */
31193131 printfPQExpBuffer (& buf ,
3120- "SELECT c.oid::pg_catalog.regclass"
3121- " FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i"
3122- " WHERE c.oid=i.inhparent AND i.inhrelid = '%s'"
3123- " AND c.relkind != " CppAsString2 (RELKIND_PARTITIONED_TABLE )
3124- " ORDER BY inhseqno;" , oid );
3132+ "SELECT c.oid::pg_catalog.regclass\n"
3133+ "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3134+ "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3135+ " AND c.relkind != " CppAsString2 (RELKIND_PARTITIONED_TABLE )
3136+ " AND c .relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3137+ " \nORDER BY inhseqno ;",
3138+ oid );
31253139
31263140 result = PSQLexec (buf .data );
31273141 if (!result )
@@ -3153,39 +3167,40 @@ describeOneTableDetails(const char *schemaname,
31533167 /* print child tables (with additional info if partitions) */
31543168 if (pset .sversion >= 100000 )
31553169 printfPQExpBuffer (& buf ,
3156- "SELECT c.oid::pg_catalog.regclass,"
3157- " pg_catalog.pg_get_expr(c.relpartbound, c.oid), "
3158- " c.relkind "
3159- " FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i "
3160- " WHERE c.oid=i.inhrelid AND i.inhparent = '%s' "
3161- " ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c. oid) = 'DEFAULT',"
3162- " c.oid::pg_catalog.regclass::pg_catalog.text;" , oid );
3170+ "SELECT c.oid::pg_catalog.regclass, c.relkind, "
3171+ " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n "
3172+ "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n "
3173+ "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n "
3174+ "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', "
3175+ " c. oid::pg_catalog.regclass::pg_catalog.text;" ,
3176+ oid );
31633177 else if (pset .sversion >= 80300 )
31643178 printfPQExpBuffer (& buf ,
3165- "SELECT c.oid::pg_catalog.regclass"
3166- " FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i"
3167- " WHERE c.oid=i.inhrelid AND i.inhparent = '%s'"
3168- " ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;" , oid );
3179+ "SELECT c.oid::pg_catalog.regclass, c.relkind, NULL\n"
3180+ "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3181+ "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3182+ "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;" ,
3183+ oid );
31693184 else
31703185 printfPQExpBuffer (& buf ,
3171- "SELECT c.oid::pg_catalog.regclass"
3172- " FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i"
3173- " WHERE c.oid=i.inhrelid AND i.inhparent = '%s'"
3174- " ORDER BY c.relname;" , oid );
3186+ "SELECT c.oid::pg_catalog.regclass, c.relkind, NULL\n"
3187+ "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3188+ "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3189+ "ORDER BY c.relname;" ,
3190+ oid );
31753191
31763192 result = PSQLexec (buf .data );
31773193 if (!result )
31783194 goto error_return ;
3179- else
3180- tuples = PQntuples (result );
3195+ tuples = PQntuples (result );
31813196
31823197 /*
31833198 * For a partitioned table with no partitions, always print the number
31843199 * of partitions as zero, even when verbose output is expected.
31853200 * Otherwise, we will not print "Partitions" section for a partitioned
31863201 * table without any partitions.
31873202 */
3188- if (tableinfo . relkind == RELKIND_PARTITIONED_TABLE && tuples == 0 )
3203+ if (is_partitioned && tuples == 0 )
31893204 {
31903205 printfPQExpBuffer (& buf , _ ("Number of partitions: %d" ), tuples );
31913206 printTableAddFooter (& cont , buf .data );
@@ -3195,49 +3210,34 @@ describeOneTableDetails(const char *schemaname,
31953210 /* print the number of child tables, if any */
31963211 if (tuples > 0 )
31973212 {
3198- if (tableinfo .relkind != RELKIND_PARTITIONED_TABLE )
3199- printfPQExpBuffer (& buf , _ ("Number of child tables: %d (Use \\d+ to list them.)" ), tuples );
3200- else
3213+ if (is_partitioned )
32013214 printfPQExpBuffer (& buf , _ ("Number of partitions: %d (Use \\d+ to list them.)" ), tuples );
3215+ else
3216+ printfPQExpBuffer (& buf , _ ("Number of child tables: %d (Use \\d+ to list them.)" ), tuples );
32023217 printTableAddFooter (& cont , buf .data );
32033218 }
32043219 }
32053220 else
32063221 {
32073222 /* display the list of child tables */
3208- const char * ct = (tableinfo .relkind != RELKIND_PARTITIONED_TABLE ) ?
3209- _ ("Child tables" ) : _ ("Partitions" );
3223+ const char * ct = is_partitioned ? _ ("Partitions" ) : _ ("Child tables" );
32103224 int ctw = pg_wcswidth (ct , strlen (ct ), pset .encoding );
32113225
32123226 for (i = 0 ; i < tuples ; i ++ )
32133227 {
3214- if (tableinfo .relkind != RELKIND_PARTITIONED_TABLE )
3215- {
3216- if (i == 0 )
3217- printfPQExpBuffer (& buf , "%s: %s" ,
3218- ct , PQgetvalue (result , i , 0 ));
3219- else
3220- printfPQExpBuffer (& buf , "%*s %s" ,
3221- ctw , "" , PQgetvalue (result , i , 0 ));
3222- }
3223- else
3224- {
3225- char * partitioned_note ;
3226-
3227- if (* PQgetvalue (result , i , 2 ) == RELKIND_PARTITIONED_TABLE )
3228- partitioned_note = ", PARTITIONED" ;
3229- else
3230- partitioned_note = "" ;
3228+ char child_relkind = * PQgetvalue (result , i , 1 );
32313229
3232- if (i == 0 )
3233- printfPQExpBuffer (& buf , "%s: %s %s%s" ,
3234- ct , PQgetvalue (result , i , 0 ), PQgetvalue (result , i , 1 ),
3235- partitioned_note );
3236- else
3237- printfPQExpBuffer (& buf , "%*s %s %s%s" ,
3238- ctw , "" , PQgetvalue (result , i , 0 ), PQgetvalue (result , i , 1 ),
3239- partitioned_note );
3240- }
3230+ if (i == 0 )
3231+ printfPQExpBuffer (& buf , "%s: %s" ,
3232+ ct , PQgetvalue (result , i , 0 ));
3233+ else
3234+ printfPQExpBuffer (& buf , "%*s %s" ,
3235+ ctw , "" , PQgetvalue (result , i , 0 ));
3236+ if (!PQgetisnull (result , i , 2 ))
3237+ appendPQExpBuffer (& buf , " %s" , PQgetvalue (result , i , 2 ));
3238+ if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3239+ child_relkind == RELKIND_PARTITIONED_INDEX )
3240+ appendPQExpBufferStr (& buf , ", PARTITIONED" );
32413241 if (i < tuples - 1 )
32423242 appendPQExpBufferChar (& buf , ',' );
32433243
0 commit comments