PostgreSQL Source Code  git master
tableamapi.c File Reference
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/tableam.h"
#include "access/xact.h"
#include "catalog/pg_am.h"
#include "catalog/pg_proc.h"
#include "commands/defrem.h"
#include "miscadmin.h"
#include "utils/fmgroids.h"
#include "utils/memutils.h"
#include "utils/syscache.h"
Include dependency graph for tableamapi.c:

Go to the source code of this file.

Functions

const TableAmRoutineGetTableAmRoutine (Oid amhandler)
 
bool check_default_table_access_method (char **newval, void **extra, GucSource source)
 

Function Documentation

◆ check_default_table_access_method()

bool check_default_table_access_method ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 111 of file tableamapi.c.

References ereport, errcode(), errmsg(), get_table_am_oid(), GUC_check_errdetail, InvalidOid, IsTransactionState(), MyDatabaseId, NAMEDATALEN, NOTICE, OidIsValid, and PGC_S_TEST.

Referenced by table_scan_sample_next_tuple().

112 {
113  if (**newval == '\0')
114  {
115  GUC_check_errdetail("%s cannot be empty.",
116  "default_table_access_method");
117  return false;
118  }
119 
120  if (strlen(*newval) >= NAMEDATALEN)
121  {
122  GUC_check_errdetail("%s is too long (maximum %d characters).",
123  "default_table_access_method", NAMEDATALEN - 1);
124  return false;
125  }
126 
127  /*
128  * If we aren't inside a transaction, or not connected to a database, we
129  * cannot do the catalog access necessary to verify the method. Must
130  * accept the value on faith.
131  */
133  {
134  if (!OidIsValid(get_table_am_oid(*newval, true)))
135  {
136  /*
137  * When source == PGC_S_TEST, don't throw a hard error for a
138  * nonexistent table access method, only a NOTICE. See comments in
139  * guc.h.
140  */
141  if (source == PGC_S_TEST)
142  {
143  ereport(NOTICE,
144  (errcode(ERRCODE_UNDEFINED_OBJECT),
145  errmsg("table access method \"%s\" does not exist",
146  *newval)));
147  }
148  else
149  {
150  GUC_check_errdetail("Table access method \"%s\" does not exist.",
151  *newval);
152  return false;
153  }
154  }
155  }
156 
157  return true;
158 }
#define GUC_check_errdetail
Definition: guc.h:409
int errcode(int sqlerrcode)
Definition: elog.c:570
#define OidIsValid(objectId)
Definition: c.h:638
#define NAMEDATALEN
#define ereport(elevel, rest)
Definition: elog.h:141
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
#define NOTICE
Definition: elog.h:37
Oid get_table_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:197
#define newval
bool IsTransactionState(void)
Definition: xact.c:356
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ GetTableAmRoutine()

const TableAmRoutine* GetTableAmRoutine ( Oid  amhandler)

Definition at line 34 of file tableamapi.c.

References Assert, TableAmRoutine::compute_xid_horizon_for_tuples, DatumGetPointer, elog, ERROR, TableAmRoutine::index_build_range_scan, TableAmRoutine::index_fetch_begin, TableAmRoutine::index_fetch_end, TableAmRoutine::index_fetch_reset, TableAmRoutine::index_fetch_tuple, TableAmRoutine::index_validate_scan, IsA, TableAmRoutine::multi_insert, OidFunctionCall0, TableAmRoutine::parallelscan_estimate, TableAmRoutine::parallelscan_initialize, TableAmRoutine::parallelscan_reinitialize, TableAmRoutine::relation_copy_data, TableAmRoutine::relation_copy_for_cluster, TableAmRoutine::relation_estimate_size, TableAmRoutine::relation_needs_toast_table, TableAmRoutine::relation_nontransactional_truncate, TableAmRoutine::relation_set_new_filenode, TableAmRoutine::relation_size, TableAmRoutine::relation_vacuum, TableAmRoutine::scan_analyze_next_block, TableAmRoutine::scan_analyze_next_tuple, TableAmRoutine::scan_begin, TableAmRoutine::scan_bitmap_next_block, TableAmRoutine::scan_bitmap_next_tuple, TableAmRoutine::scan_end, TableAmRoutine::scan_getnextslot, TableAmRoutine::scan_rescan, TableAmRoutine::scan_sample_next_block, TableAmRoutine::scan_sample_next_tuple, TableAmRoutine::tuple_complete_speculative, TableAmRoutine::tuple_delete, TableAmRoutine::tuple_fetch_row_version, TableAmRoutine::tuple_get_latest_tid, TableAmRoutine::tuple_insert, TableAmRoutine::tuple_insert_speculative, TableAmRoutine::tuple_lock, TableAmRoutine::tuple_satisfies_snapshot, TableAmRoutine::tuple_tid_valid, and TableAmRoutine::tuple_update.

Referenced by InitTableAmRoutine(), and table_scan_sample_next_tuple().

35 {
36  Datum datum;
37  const TableAmRoutine *routine;
38 
39  datum = OidFunctionCall0(amhandler);
40  routine = (TableAmRoutine *) DatumGetPointer(datum);
41 
42  if (routine == NULL || !IsA(routine, TableAmRoutine))
43  elog(ERROR, "table access method handler %u did not return a TableAmRoutine struct",
44  amhandler);
45 
46  /*
47  * Assert that all required callbacks are present. That makes it a bit
48  * easier to keep AMs up to date, e.g. when forward porting them to a new
49  * major version.
50  */
51  Assert(routine->scan_begin != NULL);
52  Assert(routine->scan_end != NULL);
53  Assert(routine->scan_rescan != NULL);
54  Assert(routine->scan_getnextslot != NULL);
55 
56  Assert(routine->parallelscan_estimate != NULL);
57  Assert(routine->parallelscan_initialize != NULL);
58  Assert(routine->parallelscan_reinitialize != NULL);
59 
60  Assert(routine->index_fetch_begin != NULL);
61  Assert(routine->index_fetch_reset != NULL);
62  Assert(routine->index_fetch_end != NULL);
63  Assert(routine->index_fetch_tuple != NULL);
64 
65  Assert(routine->tuple_fetch_row_version != NULL);
66  Assert(routine->tuple_tid_valid != NULL);
67  Assert(routine->tuple_get_latest_tid != NULL);
68  Assert(routine->tuple_satisfies_snapshot != NULL);
69  Assert(routine->compute_xid_horizon_for_tuples != NULL);
70 
71  Assert(routine->tuple_insert != NULL);
72 
73  /*
74  * Could be made optional, but would require throwing error during
75  * parse-analysis.
76  */
77  Assert(routine->tuple_insert_speculative != NULL);
78  Assert(routine->tuple_complete_speculative != NULL);
79 
80  Assert(routine->multi_insert != NULL);
81  Assert(routine->tuple_delete != NULL);
82  Assert(routine->tuple_update != NULL);
83  Assert(routine->tuple_lock != NULL);
84 
85  Assert(routine->relation_set_new_filenode != NULL);
87  Assert(routine->relation_copy_data != NULL);
88  Assert(routine->relation_copy_for_cluster != NULL);
89  Assert(routine->relation_vacuum != NULL);
90  Assert(routine->scan_analyze_next_block != NULL);
91  Assert(routine->scan_analyze_next_tuple != NULL);
92  Assert(routine->index_build_range_scan != NULL);
93  Assert(routine->index_validate_scan != NULL);
94 
95  Assert(routine->relation_size != NULL);
96  Assert(routine->relation_needs_toast_table != NULL);
97 
98  Assert(routine->relation_estimate_size != NULL);
99 
100  /* optional, but one callback implies presence of the other */
101  Assert((routine->scan_bitmap_next_block == NULL) ==
102  (routine->scan_bitmap_next_tuple == NULL));
103  Assert(routine->scan_sample_next_block != NULL);
104  Assert(routine->scan_sample_next_tuple != NULL);
105 
106  return routine;
107 }
bool(* scan_getnextslot)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:222
void(* relation_estimate_size)(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: tableam.h:600
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Size(* parallelscan_estimate)(Relation rel)
Definition: tableam.h:236
TM_Result(* tuple_update)(Relation rel, ItemPointer otid, TupleTableSlot *slot, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode, bool *update_indexes)
Definition: tableam.h:388
struct IndexFetchTableData *(* index_fetch_begin)(Relation rel)
Definition: tableam.h:267
void(* index_fetch_reset)(struct IndexFetchTableData *data)
Definition: tableam.h:273
void(* scan_end)(TableScanDesc scan)
Definition: tableam.h:209
bool(* scan_sample_next_block)(TableScanDesc scan, struct SampleScanState *scanstate)
Definition: tableam.h:684
uint64(* relation_size)(Relation rel, ForkNumber forkNumber)
Definition: tableam.h:572
double(* index_build_range_scan)(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, bool allow_sync, bool anyvisible, bool progress, BlockNumber start_blockno, BlockNumber numblocks, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
Definition: tableam.h:539
void(* index_validate_scan)(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
Definition: tableam.h:552
bool(* tuple_fetch_row_version)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition: tableam.h:317
void(* relation_nontransactional_truncate)(Relation rel)
Definition: tableam.h:461
TransactionId(* compute_xid_horizon_for_tuples)(Relation rel, ItemPointerData *items, int nitems)
Definition: tableam.h:344
bool(* scan_analyze_next_block)(TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy)
Definition: tableam.h:520
Size(* parallelscan_initialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:243
void(* tuple_insert_speculative)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate, uint32 specToken)
Definition: tableam.h:360
void(* scan_rescan)(TableScanDesc scan, struct ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:215
void(* tuple_insert)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:355
#define ERROR
Definition: elog.h:43
void(* tuple_complete_speculative)(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition: tableam.h:368
bool(* scan_bitmap_next_block)(TableScanDesc scan, struct TBMIterateResult *tbmres)
Definition: tableam.h:641
void(* relation_set_new_filenode)(Relation rel, const RelFileNode *newrnode, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
Definition: tableam.h:447
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:199
void(* multi_insert)(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:374
void(* relation_copy_for_cluster)(Relation NewTable, Relation OldTable, Relation OldIndex, bool use_sort, TransactionId OldestXmin, TransactionId *xid_cutoff, MultiXactId *multi_cutoff, double *num_tuples, double *tups_vacuumed, double *tups_recently_dead)
Definition: tableam.h:473
bool(* scan_analyze_next_tuple)(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
Definition: tableam.h:532
bool(* scan_bitmap_next_tuple)(TableScanDesc scan, struct TBMIterateResult *tbmres, TupleTableSlot *slot)
Definition: tableam.h:655
void(* relation_copy_data)(Relation rel, const RelFileNode *newrnode)
Definition: tableam.h:469
void(* parallelscan_reinitialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:250
uintptr_t Datum
Definition: postgres.h:367
bool(* relation_needs_toast_table)(Relation rel)
Definition: tableam.h:582
#define OidFunctionCall0(functionId)
Definition: fmgr.h:653
void(* index_fetch_end)(struct IndexFetchTableData *data)
Definition: tableam.h:278
TM_Result(* tuple_lock)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy, uint8 flags, TM_FailureData *tmfd)
Definition: tableam.h:400
#define Assert(condition)
Definition: c.h:732
void(* tuple_get_latest_tid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:332
bool(* tuple_satisfies_snapshot)(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition: tableam.h:339
bool(* scan_sample_next_tuple)(TableScanDesc scan, struct SampleScanState *scanstate, TupleTableSlot *slot)
Definition: tableam.h:700
#define DatumGetPointer(X)
Definition: postgres.h:549
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:325
#define elog(elevel,...)
Definition: elog.h:226
void(* relation_vacuum)(Relation onerel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: tableam.h:499
bool(* index_fetch_tuple)(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition: tableam.h:300
TM_Result(* tuple_delete)(Relation rel, ItemPointer tid, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool changingPart)
Definition: tableam.h:378