1616#include <time.h>
1717
1818#include "catalog/pg_am_d.h"
19+ #include "catalog/pg_class_d.h"
1920#include "catalog/pg_namespace_d.h"
2021#include "common/logging.h"
2122#include "common/username.h"
@@ -857,7 +858,7 @@ prepare_heap_command(PQExpBuffer sql, RelationInfo *rel, PGconn *conn)
857858
858859 appendPQExpBuffer (sql ,
859860 "\n) v WHERE c.oid = %u "
860- "AND c.relpersistence != 't'" ,
861+ "AND c.relpersistence != " CppAsString2 ( RELPERSISTENCE_TEMP ) ,
861862 rel -> reloid );
862863}
863864
@@ -890,7 +891,7 @@ prepare_btree_command(PQExpBuffer sql, RelationInfo *rel, PGconn *conn)
890891 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_index i "
891892 "WHERE c.oid = %u "
892893 "AND c.oid = i.indexrelid "
893- "AND c.relpersistence != 't' "
894+ "AND c.relpersistence != " CppAsString2 ( RELPERSISTENCE_TEMP ) " "
894895 "AND i.indisready AND i.indisvalid AND i.indislive" ,
895896 rel -> datinfo -> amcheck_schema ,
896897 (opts .heapallindexed ? "true" : "false" ),
@@ -905,7 +906,7 @@ prepare_btree_command(PQExpBuffer sql, RelationInfo *rel, PGconn *conn)
905906 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_index i "
906907 "WHERE c.oid = %u "
907908 "AND c.oid = i.indexrelid "
908- "AND c.relpersistence != 't' "
909+ "AND c.relpersistence != " CppAsString2 ( RELPERSISTENCE_TEMP ) " "
909910 "AND i.indisready AND i.indisvalid AND i.indislive" ,
910911 rel -> datinfo -> amcheck_schema ,
911912 (opts .heapallindexed ? "true" : "false" ),
@@ -1952,7 +1953,8 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
19521953 * until firing off the amcheck command, as the state of an index may
19531954 * change by then.
19541955 */
1955- appendPQExpBufferStr (& sql , "\nWHERE c.relpersistence != 't'" );
1956+ appendPQExpBufferStr (& sql , "\nWHERE c.relpersistence != "
1957+ CppAsString2 (RELPERSISTENCE_TEMP ));
19561958 if (opts .excludetbl || opts .excludeidx || opts .excludensp )
19571959 appendPQExpBufferStr (& sql , "\nAND ep.pattern_id IS NULL" );
19581960
@@ -1972,15 +1974,29 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
19721974 if (opts .allrel )
19731975 appendPQExpBuffer (& sql ,
19741976 " AND c.relam = %u "
1975- "AND c.relkind IN ('r', 'S', 'm', 't') "
1977+ "AND c.relkind IN ("
1978+ CppAsString2 (RELKIND_RELATION ) ", "
1979+ CppAsString2 (RELKIND_SEQUENCE ) ", "
1980+ CppAsString2 (RELKIND_MATVIEW ) ", "
1981+ CppAsString2 (RELKIND_TOASTVALUE ) ") "
19761982 "AND c.relnamespace != %u" ,
19771983 HEAP_TABLE_AM_OID , PG_TOAST_NAMESPACE );
19781984 else
19791985 appendPQExpBuffer (& sql ,
19801986 " AND c.relam IN (%u, %u)"
1981- "AND c.relkind IN ('r', 'S', 'm', 't', 'i') "
1982- "AND ((c.relam = %u AND c.relkind IN ('r', 'S', 'm', 't')) OR "
1983- "(c.relam = %u AND c.relkind = 'i'))" ,
1987+ "AND c.relkind IN ("
1988+ CppAsString2 (RELKIND_RELATION ) ", "
1989+ CppAsString2 (RELKIND_SEQUENCE ) ", "
1990+ CppAsString2 (RELKIND_MATVIEW ) ", "
1991+ CppAsString2 (RELKIND_TOASTVALUE ) ", "
1992+ CppAsString2 (RELKIND_INDEX ) ") "
1993+ "AND ((c.relam = %u AND c.relkind IN ("
1994+ CppAsString2 (RELKIND_RELATION ) ", "
1995+ CppAsString2 (RELKIND_SEQUENCE ) ", "
1996+ CppAsString2 (RELKIND_MATVIEW ) ", "
1997+ CppAsString2 (RELKIND_TOASTVALUE ) ")) OR "
1998+ "(c.relam = %u AND c.relkind = "
1999+ CppAsString2 (RELKIND_INDEX ) "))" ,
19842000 HEAP_TABLE_AM_OID , BTREE_AM_OID ,
19852001 HEAP_TABLE_AM_OID , BTREE_AM_OID );
19862002
@@ -2007,7 +2023,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
20072023 "\nAND (t.relname ~ ep.rel_regex OR ep.rel_regex IS NULL)"
20082024 "\nAND ep.heap_only"
20092025 "\nWHERE ep.pattern_id IS NULL"
2010- "\nAND t.relpersistence != 't'" );
2026+ "\nAND t.relpersistence != " CppAsString2 ( RELPERSISTENCE_TEMP ) );
20112027 appendPQExpBufferStr (& sql ,
20122028 "\n)" );
20132029 }
@@ -2026,7 +2042,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
20262042 "ON r.oid = i.indrelid "
20272043 "INNER JOIN pg_catalog.pg_class c "
20282044 "ON i.indexrelid = c.oid "
2029- "AND c.relpersistence != 't'" );
2045+ "AND c.relpersistence != " CppAsString2 ( RELPERSISTENCE_TEMP ) );
20302046 if (opts .excludeidx || opts .excludensp )
20312047 appendPQExpBufferStr (& sql ,
20322048 "\nINNER JOIN pg_catalog.pg_namespace n "
@@ -2041,7 +2057,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
20412057 "\nWHERE true" );
20422058 appendPQExpBuffer (& sql ,
20432059 " AND c.relam = %u "
2044- "AND c.relkind = 'i'" ,
2060+ "AND c.relkind = " CppAsString2 ( RELKIND_INDEX ) ,
20452061 BTREE_AM_OID );
20462062 if (opts .no_toast_expansion )
20472063 appendPQExpBuffer (& sql ,
@@ -2065,7 +2081,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
20652081 "ON t.oid = i.indrelid"
20662082 "\nINNER JOIN pg_catalog.pg_class c "
20672083 "ON i.indexrelid = c.oid "
2068- "AND c.relpersistence != 't'" );
2084+ "AND c.relpersistence != " CppAsString2 ( RELPERSISTENCE_TEMP ) );
20692085 if (opts .excludeidx )
20702086 appendPQExpBufferStr (& sql ,
20712087 "\nLEFT OUTER JOIN exclude_pat ep "
@@ -2078,7 +2094,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
20782094 "\nWHERE true" );
20792095 appendPQExpBuffer (& sql ,
20802096 " AND c.relam = %u"
2081- " AND c.relkind = 'i' )" ,
2097+ " AND c.relkind = " CppAsString2 ( RELKIND_INDEX ) " )" ,
20822098 BTREE_AM_OID );
20832099 }
20842100
0 commit comments