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

Appearance settings

Commit 867cc7b

Browse filesBrowse files
committed
Revert "Custom reloptions for table AM"
This reverts commit c95c25f due to multiple design issues spotted after commit. Reported-by: Jeff Davis Discussion: https://postgr.es/m/11550b536211d5748bb2865ed6cb3502ff073bf7.camel%40j-davis.com
1 parent 667e65a commit 867cc7b
Copy full SHA for 867cc7b

File tree

Expand file treeCollapse file tree

8 files changed

+27
-126
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+27
-126
lines changed

‎src/backend/access/common/reloptions.c

Copy file name to clipboardExpand all lines: src/backend/access/common/reloptions.c
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "access/nbtree.h"
2525
#include "access/reloptions.h"
2626
#include "access/spgist_private.h"
27-
#include "access/tableam.h"
2827
#include "catalog/pg_type.h"
2928
#include "commands/defrem.h"
3029
#include "commands/tablespace.h"
@@ -1378,7 +1377,7 @@ untransformRelOptions(Datum options)
13781377
*/
13791378
bytea *
13801379
extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
1381-
const TableAmRoutine *tableam, amoptions_function amoptions)
1380+
amoptions_function amoptions)
13821381
{
13831382
bytea *options;
13841383
bool isnull;
@@ -1400,8 +1399,7 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
14001399
case RELKIND_RELATION:
14011400
case RELKIND_TOASTVALUE:
14021401
case RELKIND_MATVIEW:
1403-
options = tableam_reloptions(tableam, classForm->relkind,
1404-
datum, false);
1402+
options = heap_reloptions(classForm->relkind, datum, false);
14051403
break;
14061404
case RELKIND_PARTITIONED_TABLE:
14071405
options = partitioned_table_reloptions(datum, false);

‎src/backend/access/heap/heapam_handler.c

Copy file name to clipboardExpand all lines: src/backend/access/heap/heapam_handler.c
-12Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "access/heapam.h"
2424
#include "access/heaptoast.h"
2525
#include "access/multixact.h"
26-
#include "access/reloptions.h"
2726
#include "access/rewriteheap.h"
2827
#include "access/syncscan.h"
2928
#include "access/tableam.h"
@@ -2158,16 +2157,6 @@ heapam_relation_toast_am(Relation rel)
21582157
return rel->rd_rel->relam;
21592158
}
21602159

2161-
static bytea *
2162-
heapam_reloptions(char relkind, Datum reloptions, bool validate)
2163-
{
2164-
Assert(relkind == RELKIND_RELATION ||
2165-
relkind == RELKIND_TOASTVALUE ||
2166-
relkind == RELKIND_MATVIEW);
2167-
2168-
return heap_reloptions(relkind, reloptions, validate);
2169-
}
2170-
21712160

21722161
/* ------------------------------------------------------------------------
21732162
* Planner related callbacks for the heap AM
@@ -2673,7 +2662,6 @@ static const TableAmRoutine heapam_methods = {
26732662
.relation_needs_toast_table = heapam_relation_needs_toast_table,
26742663
.relation_toast_am = heapam_relation_toast_am,
26752664
.relation_fetch_toast_slice = heap_fetch_toast_slice,
2676-
.reloptions = heapam_reloptions,
26772665

26782666
.relation_estimate_size = heapam_estimate_rel_size,
26792667

‎src/backend/access/table/tableamapi.c

Copy file name to clipboardExpand all lines: src/backend/access/table/tableamapi.c
-25Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
#include "access/tableam.h"
1515
#include "access/xact.h"
16-
#include "catalog/pg_am.h"
1716
#include "commands/defrem.h"
1817
#include "miscadmin.h"
1918
#include "utils/guc_hooks.h"
20-
#include "utils/syscache.h"
2119

2220

2321
/*
@@ -100,29 +98,6 @@ GetTableAmRoutine(Oid amhandler)
10098
return routine;
10199
}
102100

103-
/*
104-
* GetTableAmRoutineByAmOid
105-
* Given the table access method oid get its TableAmRoutine struct, which
106-
* will be palloc'd in the caller's memory context.
107-
*/
108-
const TableAmRoutine *
109-
GetTableAmRoutineByAmOid(Oid amoid)
110-
{
111-
HeapTuple ht_am;
112-
Form_pg_am amrec;
113-
const TableAmRoutine *tableam = NULL;
114-
115-
ht_am = SearchSysCache1(AMOID, ObjectIdGetDatum(amoid));
116-
if (!HeapTupleIsValid(ht_am))
117-
elog(ERROR, "cache lookup failed for access method %u",
118-
amoid);
119-
amrec = (Form_pg_am) GETSTRUCT(ht_am);
120-
121-
tableam = GetTableAmRoutine(amrec->amhandler);
122-
ReleaseSysCache(ht_am);
123-
return tableam;
124-
}
125-
126101
/* check_hook: validate new default_table_access_method */
127102
bool
128103
check_default_table_access_method(char **newval, void **extra, GucSource source)

‎src/backend/commands/tablecmds.c

Copy file name to clipboardExpand all lines: src/backend/commands/tablecmds.c
+23-32Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
715715
ObjectAddress address;
716716
LOCKMODE parentLockmode;
717717
Oid accessMethodId = InvalidOid;
718-
const TableAmRoutine *tableam = NULL;
719718

720719
/*
721720
* Truncate relname to appropriate length (probably a waste of time, as
@@ -851,28 +850,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
851850
if (!OidIsValid(ownerId))
852851
ownerId = GetUserId();
853852

854-
/*
855-
* For relations with table AM and partitioned tables, select access
856-
* method to use: an explicitly indicated one, or (in the case of a
857-
* partitioned table) the parent's, if it has one.
858-
*/
859-
if (stmt->accessMethod != NULL)
860-
{
861-
Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE);
862-
accessMethodId = get_table_am_oid(stmt->accessMethod, false);
863-
}
864-
else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE)
865-
{
866-
if (stmt->partbound)
867-
{
868-
Assert(list_length(inheritOids) == 1);
869-
accessMethodId = get_rel_relam(linitial_oid(inheritOids));
870-
}
871-
872-
if (RELKIND_HAS_TABLE_AM(relkind) && !OidIsValid(accessMethodId))
873-
accessMethodId = get_table_am_oid(default_table_access_method, false);
874-
}
875-
876853
/*
877854
* Parse and validate reloptions, if any.
878855
*/
@@ -881,12 +858,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
881858

882859
switch (relkind)
883860
{
884-
case RELKIND_RELATION:
885-
case RELKIND_TOASTVALUE:
886-
case RELKIND_MATVIEW:
887-
tableam = GetTableAmRoutineByAmOid(accessMethodId);
888-
(void) tableam_reloptions(tableam, relkind, reloptions, true);
889-
break;
890861
case RELKIND_VIEW:
891862
(void) view_reloptions(reloptions, true);
892863
break;
@@ -895,7 +866,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
895866
break;
896867
default:
897868
(void) heap_reloptions(relkind, reloptions, true);
898-
break;
899869
}
900870

901871
if (stmt->ofTypename)
@@ -987,6 +957,28 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
987957
}
988958
}
989959

960+
/*
961+
* For relations with table AM and partitioned tables, select access
962+
* method to use: an explicitly indicated one, or (in the case of a
963+
* partitioned table) the parent's, if it has one.
964+
*/
965+
if (stmt->accessMethod != NULL)
966+
{
967+
Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE);
968+
accessMethodId = get_table_am_oid(stmt->accessMethod, false);
969+
}
970+
else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE)
971+
{
972+
if (stmt->partbound)
973+
{
974+
Assert(list_length(inheritOids) == 1);
975+
accessMethodId = get_rel_relam(linitial_oid(inheritOids));
976+
}
977+
978+
if (RELKIND_HAS_TABLE_AM(relkind) && !OidIsValid(accessMethodId))
979+
accessMethodId = get_table_am_oid(default_table_access_method, false);
980+
}
981+
990982
/*
991983
* Create the relation. Inherited defaults and constraints are passed in
992984
* for immediate handling --- since they don't need parsing, they can be
@@ -15536,8 +15528,7 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation,
1553615528
case RELKIND_RELATION:
1553715529
case RELKIND_TOASTVALUE:
1553815530
case RELKIND_MATVIEW:
15539-
(void) table_reloptions(rel, rel->rd_rel->relkind,
15540-
newOptions, true);
15531+
(void) heap_reloptions(rel->rd_rel->relkind, newOptions, true);
1554115532
break;
1554215533
case RELKIND_PARTITIONED_TABLE:
1554315534
(void) partitioned_table_reloptions(newOptions, true);

‎src/backend/postmaster/autovacuum.c

Copy file name to clipboardExpand all lines: src/backend/postmaster/autovacuum.c
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,9 +2661,7 @@ extract_autovac_opts(HeapTuple tup, TupleDesc pg_class_desc)
26612661
((Form_pg_class) GETSTRUCT(tup))->relkind == RELKIND_MATVIEW ||
26622662
((Form_pg_class) GETSTRUCT(tup))->relkind == RELKIND_TOASTVALUE);
26632663

2664-
relopts = extractRelOptions(tup, pg_class_desc,
2665-
GetTableAmRoutineByAmOid(((Form_pg_class) GETSTRUCT(tup))->relam),
2666-
NULL);
2664+
relopts = extractRelOptions(tup, pg_class_desc, NULL);
26672665
if (relopts == NULL)
26682666
return NULL;
26692667

‎src/backend/utils/cache/relcache.c

Copy file name to clipboardExpand all lines: src/backend/utils/cache/relcache.c
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "access/htup_details.h"
3434
#include "access/multixact.h"
3535
#include "access/parallel.h"
36-
#include "access/relation.h"
3736
#include "access/reloptions.h"
3837
#include "access/sysattr.h"
3938
#include "access/table.h"
@@ -465,7 +464,6 @@ RelationParseRelOptions(Relation relation, HeapTuple tuple)
465464
{
466465
bytea *options;
467466
amoptions_function amoptsfn;
468-
const TableAmRoutine *tableam = NULL;
469467

470468
relation->rd_options = NULL;
471469

@@ -480,7 +478,6 @@ RelationParseRelOptions(Relation relation, HeapTuple tuple)
480478
case RELKIND_VIEW:
481479
case RELKIND_MATVIEW:
482480
case RELKIND_PARTITIONED_TABLE:
483-
tableam = relation->rd_tableam;
484481
amoptsfn = NULL;
485482
break;
486483
case RELKIND_INDEX:
@@ -496,8 +493,7 @@ RelationParseRelOptions(Relation relation, HeapTuple tuple)
496493
* we might not have any other for pg_class yet (consider executing this
497494
* code for pg_class itself)
498495
*/
499-
options = extractRelOptions(tuple, GetPgClassDescriptor(),
500-
tableam, amoptsfn);
496+
options = extractRelOptions(tuple, GetPgClassDescriptor(), amoptsfn);
501497

502498
/*
503499
* Copy parsed data into CacheMemoryContext. To guard against the

‎src/include/access/reloptions.h

Copy file name to clipboardExpand all lines: src/include/access/reloptions.h
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include "access/amapi.h"
2323
#include "access/htup.h"
24-
#include "access/tableam.h"
2524
#include "access/tupdesc.h"
2625
#include "nodes/pg_list.h"
2726
#include "storage/lock.h"
@@ -225,7 +224,6 @@ extern Datum transformRelOptions(Datum oldOptions, List *defList,
225224
bool acceptOidsOff, bool isReset);
226225
extern List *untransformRelOptions(Datum options);
227226
extern bytea *extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
228-
const TableAmRoutine *tableam,
229227
amoptions_function amoptions);
230228
extern void *build_reloptions(Datum reloptions, bool validate,
231229
relopt_kind kind,

‎src/include/access/tableam.h

Copy file name to clipboardExpand all lines: src/include/access/tableam.h
-43Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -739,28 +739,6 @@ typedef struct TableAmRoutine
739739
int32 slicelength,
740740
struct varlena *result);
741741

742-
/*
743-
* This callback parses and validates the reloptions array for a table.
744-
*
745-
* This is called only when a non-null reloptions array exists for the
746-
* table. 'reloptions' is a text array containing entries of the form
747-
* "name=value". The function should construct a bytea value, which will
748-
* be copied into the rd_options field of the table's relcache entry. The
749-
* data contents of the bytea value are open for the access method to
750-
* define.
751-
*
752-
* When 'validate' is true, the function should report a suitable error
753-
* message if any of the options are unrecognized or have invalid values;
754-
* when 'validate' is false, invalid entries should be silently ignored.
755-
* ('validate' is false when loading options already stored in pg_catalog;
756-
* an invalid entry could only be found if the access method has changed
757-
* its rules for options, and in that case ignoring obsolete entries is
758-
* appropriate.)
759-
*
760-
* It is OK to return NULL if default behavior is wanted.
761-
*/
762-
bytea *(*reloptions) (char relkind, Datum reloptions, bool validate);
763-
764742

765743
/* ------------------------------------------------------------------------
766744
* Planner related functions.
@@ -1957,26 +1935,6 @@ table_relation_fetch_toast_slice(Relation toastrel, Oid valueid,
19571935
result);
19581936
}
19591937

1960-
/*
1961-
* Parse options for given table.
1962-
*/
1963-
static inline bytea *
1964-
table_reloptions(Relation rel, char relkind,
1965-
Datum reloptions, bool validate)
1966-
{
1967-
return rel->rd_tableam->reloptions(relkind, reloptions, validate);
1968-
}
1969-
1970-
/*
1971-
* Parse table options without knowledge of particular table.
1972-
*/
1973-
static inline bytea *
1974-
tableam_reloptions(const TableAmRoutine *tableam, char relkind,
1975-
Datum reloptions, bool validate)
1976-
{
1977-
return tableam->reloptions(relkind, reloptions, validate);
1978-
}
1979-
19801938

19811939
/* ----------------------------------------------------------------------------
19821940
* Planner related functionality
@@ -2155,7 +2113,6 @@ extern void table_block_relation_estimate_size(Relation rel,
21552113
*/
21562114

21572115
extern const TableAmRoutine *GetTableAmRoutine(Oid amhandler);
2158-
extern const TableAmRoutine *GetTableAmRoutineByAmOid(Oid amoid);
21592116

21602117
/* ----------------------------------------------------------------------------
21612118
* Functions in heapam_handler.c

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.