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.
This commit is contained in:
parent
39ab3c1c61
commit
c0f92b57dc
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.18 2009/01/12 21:02:14 alvherre Exp $
|
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.19 2009/01/26 19:41:06 alvherre Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -558,6 +558,53 @@ untransformRelOptions(Datum options)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Extract and parse reloptions from a pg_class tuple.
|
||||||
|
*
|
||||||
|
* This is a low-level routine, expected to be used by relcache code and
|
||||||
|
* callers that do not have a table's relcache entry (e.g. autovacuum). For
|
||||||
|
* other uses, consider grabbing the rd_options pointer from the relcache entry
|
||||||
|
* instead.
|
||||||
|
*
|
||||||
|
* tupdesc is pg_class' tuple descriptor. amoptions is the amoptions regproc
|
||||||
|
* in the case of the tuple corresponding to an index, or InvalidOid otherwise.
|
||||||
|
*/
|
||||||
|
bytea *
|
||||||
|
extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, Oid amoptions)
|
||||||
|
{
|
||||||
|
bytea *options;
|
||||||
|
bool isnull;
|
||||||
|
Datum datum;
|
||||||
|
Form_pg_class classForm;
|
||||||
|
|
||||||
|
datum = fastgetattr(tuple,
|
||||||
|
Anum_pg_class_reloptions,
|
||||||
|
tupdesc,
|
||||||
|
&isnull);
|
||||||
|
if (isnull)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
classForm = (Form_pg_class) GETSTRUCT(tuple);
|
||||||
|
|
||||||
|
/* Parse into appropriate format; don't error out here */
|
||||||
|
switch (classForm->relkind)
|
||||||
|
{
|
||||||
|
case RELKIND_RELATION:
|
||||||
|
case RELKIND_TOASTVALUE:
|
||||||
|
case RELKIND_UNCATALOGED:
|
||||||
|
options = heap_reloptions(classForm->relkind, datum, false);
|
||||||
|
break;
|
||||||
|
case RELKIND_INDEX:
|
||||||
|
options = index_reloptions(amoptions, datum, false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Assert(false); /* can't get here */
|
||||||
|
options = NULL; /* keep compiler quiet */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Interpret reloptions that are given in text-array format.
|
* Interpret reloptions that are given in text-array format.
|
||||||
|
33
src/backend/utils/cache/relcache.c
vendored
33
src/backend/utils/cache/relcache.c
vendored
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.282 2009/01/22 20:16:06 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.283 2009/01/26 19:41:06 alvherre Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -351,8 +351,6 @@ AllocateRelationDesc(Relation relation, Form_pg_class relp)
|
|||||||
static void
|
static void
|
||||||
RelationParseRelOptions(Relation relation, HeapTuple tuple)
|
RelationParseRelOptions(Relation relation, HeapTuple tuple)
|
||||||
{
|
{
|
||||||
Datum datum;
|
|
||||||
bool isnull;
|
|
||||||
bytea *options;
|
bytea *options;
|
||||||
|
|
||||||
relation->rd_options = NULL;
|
relation->rd_options = NULL;
|
||||||
@ -374,31 +372,10 @@ RelationParseRelOptions(Relation relation, HeapTuple tuple)
|
|||||||
* we might not have any other for pg_class yet (consider executing this
|
* we might not have any other for pg_class yet (consider executing this
|
||||||
* code for pg_class itself)
|
* code for pg_class itself)
|
||||||
*/
|
*/
|
||||||
datum = fastgetattr(tuple,
|
options = extractRelOptions(tuple,
|
||||||
Anum_pg_class_reloptions,
|
GetPgClassDescriptor(),
|
||||||
GetPgClassDescriptor(),
|
relation->rd_rel->relkind == RELKIND_INDEX ?
|
||||||
&isnull);
|
relation->rd_am->amoptions : InvalidOid);
|
||||||
if (isnull)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Parse into appropriate format; don't error out here */
|
|
||||||
switch (relation->rd_rel->relkind)
|
|
||||||
{
|
|
||||||
case RELKIND_RELATION:
|
|
||||||
case RELKIND_TOASTVALUE:
|
|
||||||
case RELKIND_UNCATALOGED:
|
|
||||||
options = heap_reloptions(relation->rd_rel->relkind, datum,
|
|
||||||
false);
|
|
||||||
break;
|
|
||||||
case RELKIND_INDEX:
|
|
||||||
options = index_reloptions(relation->rd_am->amoptions, datum,
|
|
||||||
false);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Assert(false); /* can't get here */
|
|
||||||
options = NULL; /* keep compiler quiet */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy parsed data into CacheMemoryContext */
|
/* Copy parsed data into CacheMemoryContext */
|
||||||
if (options)
|
if (options)
|
||||||
|
@ -11,13 +11,14 @@
|
|||||||
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/access/reloptions.h,v 1.10 2009/01/12 21:02:15 alvherre Exp $
|
* $PostgreSQL: pgsql/src/include/access/reloptions.h,v 1.11 2009/01/26 19:41:06 alvherre Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
#ifndef RELOPTIONS_H
|
#ifndef RELOPTIONS_H
|
||||||
#define RELOPTIONS_H
|
#define RELOPTIONS_H
|
||||||
|
|
||||||
|
#include "access/htup.h"
|
||||||
#include "nodes/pg_list.h"
|
#include "nodes/pg_list.h"
|
||||||
|
|
||||||
/* types supported by reloptions */
|
/* types supported by reloptions */
|
||||||
@ -241,6 +242,8 @@ extern void add_string_reloption(int kind, char *name, char *desc,
|
|||||||
extern Datum transformRelOptions(Datum oldOptions, List *defList,
|
extern Datum transformRelOptions(Datum oldOptions, List *defList,
|
||||||
bool ignoreOids, bool isReset);
|
bool ignoreOids, bool isReset);
|
||||||
extern List *untransformRelOptions(Datum options);
|
extern List *untransformRelOptions(Datum options);
|
||||||
|
extern bytea *extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
|
||||||
|
Oid amoptions);
|
||||||
extern relopt_value *parseRelOptions(Datum options, bool validate,
|
extern relopt_value *parseRelOptions(Datum options, bool validate,
|
||||||
relopt_kind kind, int *numrelopts);
|
relopt_kind kind, int *numrelopts);
|
||||||
extern void *allocateReloptStruct(Size base, relopt_value *options,
|
extern void *allocateReloptStruct(Size base, relopt_value *options,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user