Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc0f92b5

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 openand lock a table.
1 parent39ab3c1 commitc0f92b5

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
returnresult;
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(HeapTupletuple,TupleDesctupdesc,Oidamoptions)
574+
{
575+
bytea*options;
576+
boolisnull;
577+
Datumdatum;
578+
Form_pg_classclassForm;
579+
580+
datum=fastgetattr(tuple,
581+
Anum_pg_class_reloptions,
582+
tupdesc,
583+
&isnull);
584+
if (isnull)
585+
returnNULL;
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+
caseRELKIND_RELATION:
593+
caseRELKIND_TOASTVALUE:
594+
caseRELKIND_UNCATALOGED:
595+
options=heap_reloptions(classForm->relkind,datum, false);
596+
break;
597+
caseRELKIND_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+
returnoptions;
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:06tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.283 2009/01/26 19:41:06alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -351,8 +351,6 @@ AllocateRelationDesc(Relation relation, Form_pg_class relp)
351351
staticvoid
352352
RelationParseRelOptions(Relationrelation,HeapTupletuple)
353353
{
354-
Datumdatum;
355-
boolisnull;
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-
caseRELKIND_RELATION:
388-
caseRELKIND_TOASTVALUE:
389-
caseRELKIND_UNCATALOGED:
390-
options=heap_reloptions(relation->rd_rel->relkind,datum,
391-
false);
392-
break;
393-
caseRELKIND_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
#ifndefRELOPTIONS_H
1919
#defineRELOPTIONS_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
externDatumtransformRelOptions(DatumoldOptions,List*defList,
242243
boolignoreOids,boolisReset);
243244
externList*untransformRelOptions(Datumoptions);
245+
externbytea*extractRelOptions(HeapTupletuple,TupleDesctupdesc,
246+
Oidamoptions);
244247
externrelopt_value*parseRelOptions(Datumoptions,boolvalidate,
245248
relopt_kindkind,int*numrelopts);
246249
externvoid*allocateReloptStruct(Sizebase,relopt_value*options,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp