@@ -2293,8 +2293,13 @@ describeOneTableDetails(const char *schemaname,
2293
2293
appendPQExpBufferStr (& tmpbuf , _ (", replica identity" ));
2294
2294
2295
2295
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);
2298
2303
}
2299
2304
2300
2305
PQclear (result );
@@ -2304,6 +2309,7 @@ describeOneTableDetails(const char *schemaname,
2304
2309
tableinfo .relkind == RELKIND_MATVIEW ||
2305
2310
tableinfo .relkind == RELKIND_FOREIGN_TABLE ||
2306
2311
tableinfo .relkind == RELKIND_PARTITIONED_TABLE ||
2312
+ tableinfo .relkind == RELKIND_PARTITIONED_INDEX ||
2307
2313
tableinfo .relkind == RELKIND_TOASTVALUE )
2308
2314
{
2309
2315
/* Footer information about a table */
@@ -3070,11 +3076,17 @@ describeOneTableDetails(const char *schemaname,
3070
3076
tableinfo .relkind == RELKIND_MATVIEW ||
3071
3077
tableinfo .relkind == RELKIND_FOREIGN_TABLE ||
3072
3078
tableinfo .relkind == RELKIND_PARTITIONED_TABLE ||
3079
+ tableinfo .relkind == RELKIND_PARTITIONED_INDEX ||
3073
3080
tableinfo .relkind == RELKIND_TOASTVALUE )
3074
3081
{
3082
+ bool is_partitioned ;
3075
3083
PGresult * result ;
3076
3084
int tuples ;
3077
3085
3086
+ /* simplify some repeated tests below */
3087
+ is_partitioned = (tableinfo .relkind == RELKIND_PARTITIONED_TABLE ||
3088
+ tableinfo .relkind == RELKIND_PARTITIONED_INDEX );
3089
+
3078
3090
/* print foreign server name */
3079
3091
if (tableinfo .relkind == RELKIND_FOREIGN_TABLE )
3080
3092
{
@@ -3115,13 +3127,15 @@ describeOneTableDetails(const char *schemaname,
3115
3127
PQclear (result );
3116
3128
}
3117
3129
3118
- /* print inherited tables (exclude, if parent is a partitioned table ) */
3130
+ /* print tables inherited from (exclude partitioned parents ) */
3119
3131
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 );
3125
3139
3126
3140
result = PSQLexec (buf .data );
3127
3141
if (!result )
@@ -3153,39 +3167,40 @@ describeOneTableDetails(const char *schemaname,
3153
3167
/* print child tables (with additional info if partitions) */
3154
3168
if (pset .sversion >= 100000 )
3155
3169
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 );
3163
3177
else if (pset .sversion >= 80300 )
3164
3178
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 );
3169
3184
else
3170
3185
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 );
3175
3191
3176
3192
result = PSQLexec (buf .data );
3177
3193
if (!result )
3178
3194
goto error_return ;
3179
- else
3180
- tuples = PQntuples (result );
3195
+ tuples = PQntuples (result );
3181
3196
3182
3197
/*
3183
3198
* For a partitioned table with no partitions, always print the number
3184
3199
* of partitions as zero, even when verbose output is expected.
3185
3200
* Otherwise, we will not print "Partitions" section for a partitioned
3186
3201
* table without any partitions.
3187
3202
*/
3188
- if (tableinfo . relkind == RELKIND_PARTITIONED_TABLE && tuples == 0 )
3203
+ if (is_partitioned && tuples == 0 )
3189
3204
{
3190
3205
printfPQExpBuffer (& buf , _ ("Number of partitions: %d" ), tuples );
3191
3206
printTableAddFooter (& cont , buf .data );
@@ -3195,49 +3210,34 @@ describeOneTableDetails(const char *schemaname,
3195
3210
/* print the number of child tables, if any */
3196
3211
if (tuples > 0 )
3197
3212
{
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 )
3201
3214
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 );
3202
3217
printTableAddFooter (& cont , buf .data );
3203
3218
}
3204
3219
}
3205
3220
else
3206
3221
{
3207
3222
/* 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" );
3210
3224
int ctw = pg_wcswidth (ct , strlen (ct ), pset .encoding );
3211
3225
3212
3226
for (i = 0 ; i < tuples ; i ++ )
3213
3227
{
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 );
3231
3229
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" );
3241
3241
if (i < tuples - 1 )
3242
3242
appendPQExpBufferChar (& buf , ',' );
3243
3243
0 commit comments