Skip to content

Commit c0f92b5

Browse files
committed
Allow extracting and parsing of reloptions from a bare pg_class tuple, and
refactor the relcache code that used to do that. This allows other callers (particularly autovacuum) to do the same without necessarily having to open and lock a table.
1 parent 39ab3c1 commit c0f92b5

File tree

3 files changed

+57
-30
lines changed

3 files changed

+57
-30
lines changed

src/backend/access/common/reloptions.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.18 2009/01/12 21:02:14 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.19 2009/01/26 19:41:06 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -558,6 +558,53 @@ untransformRelOptions(Datum options)
558558
return result;
559559
}
560560

561+
/*
562+
* Extract and parse reloptions from a pg_class tuple.
563+
*
564+
* This is a low-level routine, expected to be used by relcache code and
565+
* callers that do not have a table's relcache entry (e.g. autovacuum). For
566+
* other uses, consider grabbing the rd_options pointer from the relcache entry
567+
* instead.
568+
*
569+
* tupdesc is pg_class' tuple descriptor. amoptions is the amoptions regproc
570+
* in the case of the tuple corresponding to an index, or InvalidOid otherwise.
571+
*/
572+
bytea *
573+
extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, Oid amoptions)
574+
{
575+
bytea *options;
576+
bool isnull;
577+
Datum datum;
578+
Form_pg_class classForm;
579+
580+
datum = fastgetattr(tuple,
581+
Anum_pg_class_reloptions,
582+
tupdesc,
583+
&isnull);
584+
if (isnull)
585+
return NULL;
586+
587+
classForm = (Form_pg_class) GETSTRUCT(tuple);
588+
589+
/* Parse into appropriate format; don't error out here */
590+
switch (classForm->relkind)
591+
{
592+
case RELKIND_RELATION:
593+
case RELKIND_TOASTVALUE:
594+
case RELKIND_UNCATALOGED:
595+
options = heap_reloptions(classForm->relkind, datum, false);
596+
break;
597+
case RELKIND_INDEX:
598+
options = index_reloptions(amoptions, datum, false);
599+
break;
600+
default:
601+
Assert(false); /* can't get here */
602+
options = NULL; /* keep compiler quiet */
603+
break;
604+
}
605+
606+
return options;
607+
}
561608

562609
/*
563610
* Interpret reloptions that are given in text-array format.

src/backend/utils/cache/relcache.c

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.282 2009/01/22 20:16:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.283 2009/01/26 19:41:06 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -351,8 +351,6 @@ AllocateRelationDesc(Relation relation, Form_pg_class relp)
351351
static void
352352
RelationParseRelOptions(Relation relation, HeapTuple tuple)
353353
{
354-
Datum datum;
355-
bool isnull;
356354
bytea *options;
357355

358356
relation->rd_options = NULL;
@@ -374,31 +372,10 @@ RelationParseRelOptions(Relation relation, HeapTuple tuple)
374372
* we might not have any other for pg_class yet (consider executing this
375373
* code for pg_class itself)
376374
*/
377-
datum = fastgetattr(tuple,
378-
Anum_pg_class_reloptions,
379-
GetPgClassDescriptor(),
380-
&isnull);
381-
if (isnull)
382-
return;
383-
384-
/* Parse into appropriate format; don't error out here */
385-
switch (relation->rd_rel->relkind)
386-
{
387-
case RELKIND_RELATION:
388-
case RELKIND_TOASTVALUE:
389-
case RELKIND_UNCATALOGED:
390-
options = heap_reloptions(relation->rd_rel->relkind, datum,
391-
false);
392-
break;
393-
case RELKIND_INDEX:
394-
options = index_reloptions(relation->rd_am->amoptions, datum,
395-
false);
396-
break;
397-
default:
398-
Assert(false); /* can't get here */
399-
options = NULL; /* keep compiler quiet */
400-
break;
401-
}
375+
options = extractRelOptions(tuple,
376+
GetPgClassDescriptor(),
377+
relation->rd_rel->relkind == RELKIND_INDEX ?
378+
relation->rd_am->amoptions : InvalidOid);
402379

403380
/* Copy parsed data into CacheMemoryContext */
404381
if (options)

src/include/access/reloptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $PostgreSQL: pgsql/src/include/access/reloptions.h,v 1.10 2009/01/12 21:02:15 alvherre Exp $
14+
* $PostgreSQL: pgsql/src/include/access/reloptions.h,v 1.11 2009/01/26 19:41:06 alvherre Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
1818
#ifndef RELOPTIONS_H
1919
#define RELOPTIONS_H
2020

21+
#include "access/htup.h"
2122
#include "nodes/pg_list.h"
2223

2324
/* types supported by reloptions */
@@ -241,6 +242,8 @@ extern void add_string_reloption(int kind, char *name, char *desc,
241242
extern Datum transformRelOptions(Datum oldOptions, List *defList,
242243
bool ignoreOids, bool isReset);
243244
extern List *untransformRelOptions(Datum options);
245+
extern bytea *extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
246+
Oid amoptions);
244247
extern relopt_value *parseRelOptions(Datum options, bool validate,
245248
relopt_kind kind, int *numrelopts);
246249
extern void *allocateReloptStruct(Size base, relopt_value *options,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy