PostgreSQL Source Code git master
dummy_index_am.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * dummy_index_am.c
4 * Index AM template main file.
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * IDENTIFICATION
10 * src/test/modules/dummy_index_am/dummy_index_am.c
11 *
12 *-------------------------------------------------------------------------
13 */
14#include "postgres.h"
15
16#include "access/amapi.h"
17#include "access/reloptions.h"
18#include "catalog/index.h"
19#include "commands/vacuum.h"
20#include "nodes/pathnodes.h"
21
23
24/* parse table for fillRelOptions */
26
27/* Kind of relation options for dummy index */
29
30typedef enum DummyAmEnum
31{
35
36/* Dummy index options */
37typedef struct DummyIndexOptions
38{
39 int32 vl_len_; /* varlena header (do not touch directly!) */
47
49{
50 {"one", DUMMY_AM_ENUM_ONE},
51 {"two", DUMMY_AM_ENUM_TWO},
52 {(const char *) NULL} /* list terminator */
53};
54
55/* Handler for index AM */
57
58/*
59 * Validation function for string relation options.
60 */
61static void
63{
65 (errmsg("new option value for string parameter %s",
66 value ? value : "NULL")));
67}
68
69/*
70 * This function creates a full set of relation option types,
71 * with various patterns.
72 */
73static void
75{
77
79 "Integer option for dummy_index_am",
80 10, -10, 100, AccessExclusiveLock);
81 di_relopt_tab[0].optname = "option_int";
83 di_relopt_tab[0].offset = offsetof(DummyIndexOptions, option_int);
84
86 "Real option for dummy_index_am",
87 3.1415, -10, 100, AccessExclusiveLock);
88 di_relopt_tab[1].optname = "option_real";
90 di_relopt_tab[1].offset = offsetof(DummyIndexOptions, option_real);
91
93 "Boolean option for dummy_index_am",
95 di_relopt_tab[2].optname = "option_bool";
97 di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool);
98
100 "Enum option for dummy_index_am",
103 "Valid values are \"one\" and \"two\".",
105 di_relopt_tab[3].optname = "option_enum";
107 di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum);
108
109 add_string_reloption(di_relopt_kind, "option_string_val",
110 "String option for dummy_index_am with non-NULL default",
111 "DefaultValue", &validate_string_option,
113 di_relopt_tab[4].optname = "option_string_val";
116 option_string_val_offset);
117
118 /*
119 * String option for dummy_index_am with NULL default, and without
120 * description.
121 */
122 add_string_reloption(di_relopt_kind, "option_string_null",
123 NULL, /* description */
126 di_relopt_tab[5].optname = "option_string_null";
129 option_string_null_offset);
130}
131
132
133/*
134 * Build a new index.
135 */
136static IndexBuildResult *
138{
139 IndexBuildResult *result;
140
141 result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
142
143 /* let's pretend that no tuples were scanned */
144 result->heap_tuples = 0;
145 /* and no index tuples were created (that is true) */
146 result->index_tuples = 0;
147
148 return result;
149}
150
151/*
152 * Build an empty index for the initialization fork.
153 */
154static void
156{
157 /* No need to build an init fork for a dummy index */
158}
159
160/*
161 * Insert new tuple to index AM.
162 */
163static bool
165 ItemPointer ht_ctid, Relation heapRel,
166 IndexUniqueCheck checkUnique,
167 bool indexUnchanged,
168 IndexInfo *indexInfo)
169{
170 /* nothing to do */
171 return false;
172}
173
174/*
175 * Bulk deletion of all index entries pointing to a set of table tuples.
176 */
179 IndexBulkDeleteCallback callback, void *callback_state)
180{
181 /*
182 * There is nothing to delete. Return NULL as there is nothing to pass to
183 * amvacuumcleanup.
184 */
185 return NULL;
186}
187
188/*
189 * Post-VACUUM cleanup for index AM.
190 */
193{
194 /* Index has not been modified, so returning NULL is fine */
195 return NULL;
196}
197
198/*
199 * Estimate cost of index AM.
200 */
201static void
202dicostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
203 Cost *indexStartupCost, Cost *indexTotalCost,
204 Selectivity *indexSelectivity, double *indexCorrelation,
205 double *indexPages)
206{
207 /* Tell planner to never use this index! */
208 *indexStartupCost = 1.0e10;
209 *indexTotalCost = 1.0e10;
210
211 /* Do not care about the rest */
212 *indexSelectivity = 1;
213 *indexCorrelation = 0;
214 *indexPages = 1;
215}
216
217/*
218 * Parse relation options for index AM, returning a DummyIndexOptions
219 * structure filled with option values.
220 */
221static bytea *
222dioptions(Datum reloptions, bool validate)
223{
224 return (bytea *) build_reloptions(reloptions, validate,
226 sizeof(DummyIndexOptions),
228}
229
230/*
231 * Validator for index AM.
232 */
233static bool
234divalidate(Oid opclassoid)
235{
236 /* Index is dummy so we are happy with any opclass */
237 return true;
238}
239
240/*
241 * Begin scan of index AM.
242 */
243static IndexScanDesc
244dibeginscan(Relation r, int nkeys, int norderbys)
245{
246 IndexScanDesc scan;
247
248 /* Let's pretend we are doing something */
249 scan = RelationGetIndexScan(r, nkeys, norderbys);
250 return scan;
251}
252
253/*
254 * Rescan of index AM.
255 */
256static void
257direscan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
258 ScanKey orderbys, int norderbys)
259{
260 /* nothing to do */
261}
262
263/*
264 * End scan of index AM.
265 */
266static void
268{
269 /* nothing to do */
270}
271
272/*
273 * Index AM handler function: returns IndexAmRoutine with access method
274 * parameters and callbacks.
275 */
276Datum
278{
280
281 amroutine->amstrategies = 0;
282 amroutine->amsupport = 1;
283 amroutine->amcanorder = false;
284 amroutine->amcanorderbyop = false;
285 amroutine->amcanbackward = false;
286 amroutine->amcanunique = false;
287 amroutine->amcanmulticol = false;
288 amroutine->amoptionalkey = false;
289 amroutine->amsearcharray = false;
290 amroutine->amsearchnulls = false;
291 amroutine->amstorage = false;
292 amroutine->amclusterable = false;
293 amroutine->ampredlocks = false;
294 amroutine->amcanparallel = false;
295 amroutine->amcanbuildparallel = false;
296 amroutine->amcaninclude = false;
297 amroutine->amusemaintenanceworkmem = false;
298 amroutine->amsummarizing = false;
300 amroutine->amkeytype = InvalidOid;
301
302 amroutine->ambuild = dibuild;
303 amroutine->ambuildempty = dibuildempty;
304 amroutine->aminsert = diinsert;
305 amroutine->ambulkdelete = dibulkdelete;
306 amroutine->amvacuumcleanup = divacuumcleanup;
307 amroutine->amcanreturn = NULL;
308 amroutine->amcostestimate = dicostestimate;
309 amroutine->amgettreeheight = NULL;
310 amroutine->amoptions = dioptions;
311 amroutine->amproperty = NULL;
312 amroutine->ambuildphasename = NULL;
313 amroutine->amvalidate = divalidate;
314 amroutine->ambeginscan = dibeginscan;
315 amroutine->amrescan = direscan;
316 amroutine->amgettuple = NULL;
317 amroutine->amgetbitmap = NULL;
318 amroutine->amendscan = diendscan;
319 amroutine->ammarkpos = NULL;
320 amroutine->amrestrpos = NULL;
321 amroutine->amestimateparallelscan = NULL;
322 amroutine->aminitparallelscan = NULL;
323 amroutine->amparallelrescan = NULL;
324
325 PG_RETURN_POINTER(amroutine);
326}
327
328void
330{
332}
static Datum values[MAXATTR]
Definition: bootstrap.c:151
int32_t int32
Definition: c.h:484
#define lengthof(array)
Definition: c.h:745
static bool divalidate(Oid opclassoid)
static void validate_string_option(const char *value)
static void diendscan(IndexScanDesc scan)
void _PG_init(void)
static void dibuildempty(Relation index)
static IndexBuildResult * dibuild(Relation heap, Relation index, IndexInfo *indexInfo)
static relopt_enum_elt_def dummyAmEnumValues[]
PG_FUNCTION_INFO_V1(dihandler)
PG_MODULE_MAGIC
static void create_reloptions_table(void)
static bytea * dioptions(Datum reloptions, bool validate)
static IndexBulkDeleteResult * dibulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
static IndexScanDesc dibeginscan(Relation r, int nkeys, int norderbys)
static bool diinsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
static void direscan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
DummyAmEnum
@ DUMMY_AM_ENUM_ONE
@ DUMMY_AM_ENUM_TWO
static IndexBulkDeleteResult * divacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
struct DummyIndexOptions DummyIndexOptions
static void dicostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
static relopt_parse_elt di_relopt_tab[6]
Datum dihandler(PG_FUNCTION_ARGS)
static relopt_kind di_relopt_kind
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define NOTICE
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
Definition: genam.c:80
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition: genam.h:89
IndexUniqueCheck
Definition: genam.h:118
static struct @162 value
#define AccessExclusiveLock
Definition: lockdefs.h:43
void * palloc(Size size)
Definition: mcxt.c:1317
double Cost
Definition: nodes.h:251
double Selectivity
Definition: nodes.h:250
#define makeNode(_type_)
Definition: nodes.h:155
uintptr_t Datum
Definition: postgres.h:69
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
tree ctl root
Definition: radixtree.h:1857
void add_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
Definition: reloptions.c:920
void add_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
Definition: reloptions.c:1117
void add_enum_reloption(bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
Definition: reloptions.c:1037
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1931
void add_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
Definition: reloptions.c:973
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:868
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:702
relopt_kind
Definition: reloptions.h:40
@ RELOPT_TYPE_ENUM
Definition: reloptions.h:34
@ RELOPT_TYPE_INT
Definition: reloptions.h:32
@ RELOPT_TYPE_BOOL
Definition: reloptions.h:31
@ RELOPT_TYPE_REAL
Definition: reloptions.h:33
@ RELOPT_TYPE_STRING
Definition: reloptions.h:35
DummyAmEnum option_enum
ambuildphasename_function ambuildphasename
Definition: amapi.h:297
ambuildempty_function ambuildempty
Definition: amapi.h:287
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:291
bool amclusterable
Definition: amapi.h:261
amoptions_function amoptions
Definition: amapi.h:295
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:309
amrestrpos_function amrestrpos
Definition: amapi.h:306
aminsert_function aminsert
Definition: amapi.h:288
amendscan_function amendscan
Definition: amapi.h:304
amparallelrescan_function amparallelrescan
Definition: amapi.h:311
Oid amkeytype
Definition: amapi.h:277
bool ampredlocks
Definition: amapi.h:263
uint16 amsupport
Definition: amapi.h:239
amcostestimate_function amcostestimate
Definition: amapi.h:293
bool amcanorderbyop
Definition: amapi.h:245
ambuild_function ambuild
Definition: amapi.h:286
bool amstorage
Definition: amapi.h:259
uint16 amstrategies
Definition: amapi.h:237
bool amoptionalkey
Definition: amapi.h:253
amgettuple_function amgettuple
Definition: amapi.h:302
amcanreturn_function amcanreturn
Definition: amapi.h:292
bool amcanunique
Definition: amapi.h:249
amgetbitmap_function amgetbitmap
Definition: amapi.h:303
amproperty_function amproperty
Definition: amapi.h:296
ambulkdelete_function ambulkdelete
Definition: amapi.h:290
bool amsearcharray
Definition: amapi.h:255
bool amsummarizing
Definition: amapi.h:273
amvalidate_function amvalidate
Definition: amapi.h:298
ammarkpos_function ammarkpos
Definition: amapi.h:305
bool amcanmulticol
Definition: amapi.h:251
bool amusemaintenanceworkmem
Definition: amapi.h:271
ambeginscan_function ambeginscan
Definition: amapi.h:300
bool amcanparallel
Definition: amapi.h:265
amrescan_function amrescan
Definition: amapi.h:301
bool amcanorder
Definition: amapi.h:243
bool amcanbuildparallel
Definition: amapi.h:267
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:310
uint8 amparallelvacuumoptions
Definition: amapi.h:275
bool amcanbackward
Definition: amapi.h:247
amgettreeheight_function amgettreeheight
Definition: amapi.h:294
bool amcaninclude
Definition: amapi.h:269
bool amsearchnulls
Definition: amapi.h:257
double heap_tuples
Definition: genam.h:34
double index_tuples
Definition: genam.h:35
Definition: type.h:96
const char * optname
Definition: reloptions.h:152
relopt_type opttype
Definition: reloptions.h:153
Definition: c.h:644
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
#define VACUUM_OPTION_NO_PARALLEL
Definition: vacuum.h:42