]> granicus.if.org Git - postgresql/commitdiff
Only allow heap in a number of contrib modules.
authorAndres Freund <andres@anarazel.de>
Mon, 1 Apr 2019 21:57:21 +0000 (14:57 -0700)
committerAndres Freund <andres@anarazel.de>
Mon, 1 Apr 2019 21:57:21 +0000 (14:57 -0700)
Contrib modules pgrowlocks, pgstattuple and some functionality in
pageinspect currently only supports the heap table AM. As they are all
concerned with low-level details that aren't reasonably exposed via
tableam, error out if invoked on a non heap relation.

Author: Andres Freund
Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de

contrib/pageinspect/heapfuncs.c
contrib/pgrowlocks/pgrowlocks.c
contrib/pgstattuple/pgstatapprox.c
contrib/pgstattuple/pgstattuple.c

index 987d576c01156dce283f6f1fe434e87eb320a1ea..64a6e351d5f85b114993e8fe1ab428141c71da5a 100644 (file)
@@ -30,6 +30,7 @@
 #include "access/htup_details.h"
 #include "access/relation.h"
 #include "funcapi.h"
+#include "catalog/pg_am_d.h"
 #include "catalog/pg_type.h"
 #include "miscadmin.h"
 #include "utils/array.h"
@@ -318,6 +319,10 @@ tuple_data_split_internal(Oid relid, char *tupdata,
        raw_attrs = initArrayResult(BYTEAOID, CurrentMemoryContext, false);
        nattrs = tupdesc->natts;
 
+       if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
+               ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                               errmsg("only heap AM is supported")));
+
        if (nattrs < (t_infomask2 & HEAP_NATTS_MASK))
                ereport(ERROR,
                                (errcode(ERRCODE_DATA_CORRUPTED),
index 61b753f8565a3d0ae45cc3974453c6b9953ccef9..a2c44a916cff84c5921d96c7b2ae5e4209727666 100644 (file)
@@ -30,6 +30,7 @@
 #include "access/tableam.h"
 #include "access/xact.h"
 #include "catalog/namespace.h"
+#include "catalog/pg_am_d.h"
 #include "catalog/pg_authid.h"
 #include "funcapi.h"
 #include "miscadmin.h"
@@ -101,6 +102,10 @@ pgrowlocks(PG_FUNCTION_ARGS)
                relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
                rel = relation_openrv(relrv, AccessShareLock);
 
+               if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
+                       ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                                       errmsg("only heap AM is supported")));
+
                if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
                        ereport(ERROR,
                                        (errcode(ERRCODE_WRONG_OBJECT_TYPE),
index d36758af9a6a6dccefa10d4149bceee6c04e9d7b..ed62aef766972a77bfd61097469bb659fa47089a 100644 (file)
@@ -20,6 +20,8 @@
 #include "access/multixact.h"
 #include "access/htup_details.h"
 #include "catalog/namespace.h"
+#include "catalog/pg_am_d.h"
+#include "commands/vacuum.h"
 #include "funcapi.h"
 #include "miscadmin.h"
 #include "storage/bufmgr.h"
@@ -27,7 +29,6 @@
 #include "storage/procarray.h"
 #include "storage/lmgr.h"
 #include "utils/builtins.h"
-#include "commands/vacuum.h"
 
 PG_FUNCTION_INFO_V1(pgstattuple_approx);
 PG_FUNCTION_INFO_V1(pgstattuple_approx_v1_5);
@@ -291,6 +292,10 @@ pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
                                 errmsg("\"%s\" is not a table or materialized view",
                                                RelationGetRelationName(rel))));
 
+       if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
+               ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                               errmsg("only heap AM is supported")));
+
        statapprox_heap(rel, &stat);
 
        relation_close(rel, AccessShareLock);
index 7e1c30800069a565aaf96dd3010c69ed0f030dc3..6151e8095d0cf29c8460d483416bef3643122295 100644 (file)
@@ -31,7 +31,7 @@
 #include "access/relscan.h"
 #include "access/tableam.h"
 #include "catalog/namespace.h"
-#include "catalog/pg_am.h"
+#include "catalog/pg_am_d.h"
 #include "funcapi.h"
 #include "miscadmin.h"
 #include "storage/bufmgr.h"
@@ -328,6 +328,11 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
        pgstattuple_type stat = {0};
        SnapshotData SnapshotDirty;
 
+       if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
+               ereport(ERROR,
+                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                errmsg("only heap AM is supported")));
+
        /* Disable syncscan because we assume we scan from block zero upwards */
        scan = table_beginscan_strat(rel, SnapshotAny, 0, NULL, true, false);
        hscan = (HeapScanDesc) scan;