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-2026, 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
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{
279 static const IndexAmRoutine amroutine = {
280 .type = T_IndexAmRoutine,
281 .amstrategies = 0,
282 .amsupport = 1,
283 .amcanorder = false,
284 .amcanorderbyop = false,
285 .amcanhash = false,
286 .amconsistentequality = false,
287 .amconsistentordering = false,
288 .amcanbackward = false,
289 .amcanunique = false,
290 .amcanmulticol = false,
291 .amoptionalkey = false,
292 .amsearcharray = false,
293 .amsearchnulls = false,
294 .amstorage = false,
295 .amclusterable = false,
296 .ampredlocks = false,
297 .amcanparallel = false,
298 .amcanbuildparallel = false,
299 .amcaninclude = false,
300 .amusemaintenanceworkmem = false,
301 .amsummarizing = false,
302 .amparallelvacuumoptions = VACUUM_OPTION_NO_PARALLEL,
303 .amkeytype = InvalidOid,
304
305 .ambuild = dibuild,
306 .ambuildempty = dibuildempty,
307 .aminsert = diinsert,
308 .ambulkdelete = dibulkdelete,
309 .amvacuumcleanup = divacuumcleanup,
310 .amcanreturn = NULL,
311 .amcostestimate = dicostestimate,
312 .amgettreeheight = NULL,
313 .amoptions = dioptions,
314 .amproperty = NULL,
315 .ambuildphasename = NULL,
316 .amvalidate = divalidate,
317 .ambeginscan = dibeginscan,
318 .amrescan = direscan,
319 .amgettuple = NULL,
320 .amgetbitmap = NULL,
321 .amendscan = diendscan,
322 .ammarkpos = NULL,
323 .amrestrpos = NULL,
324 .amestimateparallelscan = NULL,
325 .aminitparallelscan = NULL,
326 .amparallelrescan = NULL,
327 };
328
329 PG_RETURN_POINTER(&amroutine);
330}
331
332void
334{
336}
static bool validate(Port *port, const char *auth)
Definition: auth-oauth.c:638
static Datum values[MAXATTR]
Definition: bootstrap.c:153
int32_t int32
Definition: c.h:548
#define lengthof(array)
Definition: c.h:801
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:1080
#define NOTICE
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:150
#define palloc_object(type)
Definition: fe_memutils.h:74
#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:114
IndexUniqueCheck
Definition: genam.h:143
static struct @171 value
#define AccessExclusiveLock
Definition: lockdefs.h:43
double Cost
Definition: nodes.h:261
double Selectivity
Definition: nodes.h:260
uint64_t Datum
Definition: postgres.h:70
#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:921
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:1118
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:1038
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:1954
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:974
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:869
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:703
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
NodeTag type
Definition: amapi.h:234
double heap_tuples
Definition: genam.h:59
double index_tuples
Definition: genam.h:60
Definition: type.h:96
const char * optname
Definition: reloptions.h:152
relopt_type opttype
Definition: reloptions.h:153
Definition: c.h:706
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