Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4b82664

Browse files
committed
Only allow heap in a number of contrib modules.
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
1 parent d45e401 commit 4b82664

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

contrib/pageinspect/heapfuncs.c

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "access/htup_details.h"
3131
#include "access/relation.h"
3232
#include "funcapi.h"
33+
#include "catalog/pg_am_d.h"
3334
#include "catalog/pg_type.h"
3435
#include "miscadmin.h"
3536
#include "utils/array.h"
@@ -318,6 +319,10 @@ tuple_data_split_internal(Oid relid, char *tupdata,
318319
raw_attrs = initArrayResult(BYTEAOID, CurrentMemoryContext, false);
319320
nattrs = tupdesc->natts;
320321

322+
if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
323+
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
324+
errmsg("only heap AM is supported")));
325+
321326
if (nattrs < (t_infomask2 & HEAP_NATTS_MASK))
322327
ereport(ERROR,
323328
(errcode(ERRCODE_DATA_CORRUPTED),

contrib/pgrowlocks/pgrowlocks.c

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "access/tableam.h"
3131
#include "access/xact.h"
3232
#include "catalog/namespace.h"
33+
#include "catalog/pg_am_d.h"
3334
#include "catalog/pg_authid.h"
3435
#include "funcapi.h"
3536
#include "miscadmin.h"
@@ -101,6 +102,10 @@ pgrowlocks(PG_FUNCTION_ARGS)
101102
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
102103
rel = relation_openrv(relrv, AccessShareLock);
103104

105+
if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
106+
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
107+
errmsg("only heap AM is supported")));
108+
104109
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
105110
ereport(ERROR,
106111
(errcode(ERRCODE_WRONG_OBJECT_TYPE),

contrib/pgstattuple/pgstatapprox.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
#include "access/multixact.h"
2121
#include "access/htup_details.h"
2222
#include "catalog/namespace.h"
23+
#include "catalog/pg_am_d.h"
24+
#include "commands/vacuum.h"
2325
#include "funcapi.h"
2426
#include "miscadmin.h"
2527
#include "storage/bufmgr.h"
2628
#include "storage/freespace.h"
2729
#include "storage/procarray.h"
2830
#include "storage/lmgr.h"
2931
#include "utils/builtins.h"
30-
#include "commands/vacuum.h"
3132

3233
PG_FUNCTION_INFO_V1(pgstattuple_approx);
3334
PG_FUNCTION_INFO_V1(pgstattuple_approx_v1_5);
@@ -291,6 +292,10 @@ pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
291292
errmsg("\"%s\" is not a table or materialized view",
292293
RelationGetRelationName(rel))));
293294

295+
if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
296+
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
297+
errmsg("only heap AM is supported")));
298+
294299
statapprox_heap(rel, &stat);
295300

296301
relation_close(rel, AccessShareLock);

contrib/pgstattuple/pgstattuple.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "access/relscan.h"
3232
#include "access/tableam.h"
3333
#include "catalog/namespace.h"
34-
#include "catalog/pg_am.h"
34+
#include "catalog/pg_am_d.h"
3535
#include "funcapi.h"
3636
#include "miscadmin.h"
3737
#include "storage/bufmgr.h"
@@ -328,6 +328,11 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
328328
pgstattuple_type stat = {0};
329329
SnapshotData SnapshotDirty;
330330

331+
if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
332+
ereport(ERROR,
333+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
334+
errmsg("only heap AM is supported")));
335+
331336
/* Disable syncscan because we assume we scan from block zero upwards */
332337
scan = table_beginscan_strat(rel, SnapshotAny, 0, NULL, true, false);
333338
hscan = (HeapScanDesc) scan;

0 commit comments

Comments
 (0)