PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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
35
36/* Dummy index options */
48
50{
51 {"one", DUMMY_AM_ENUM_ONE},
52 {"two", DUMMY_AM_ENUM_TWO},
53 {(const char *) NULL} /* list terminator */
54};
55
56/* Handler for index AM */
58
59/*
60 * Validation function for string relation options.
61 */
62static void
64{
66 (errmsg("new option value for string parameter %s",
67 value ? value : "NULL")));
68}
69
70/*
71 * This function creates a full set of relation option types,
72 * with various patterns.
73 */
74static void
76{
77 int i = 0;
78
80
82 "Integer option for dummy_index_am",
83 10, -10, 100, AccessExclusiveLock);
84 di_relopt_tab[i].optname = "option_int";
87 i++;
88
90 "Real option for dummy_index_am",
91 3.1415, -10, 100, AccessExclusiveLock);
92 di_relopt_tab[i].optname = "option_real";
95 i++;
96
98 "Boolean option for dummy_index_am",
100 di_relopt_tab[i].optname = "option_bool";
103 i++;
104
105 add_ternary_reloption(di_relopt_kind, "option_ternary_1",
106 "One ternary option for dummy_index_am",
108 di_relopt_tab[i].optname = "option_ternary_1";
110 di_relopt_tab[i].offset = offsetof(DummyIndexOptions, option_ternary_1);
111 i++;
112
113 add_enum_reloption(di_relopt_kind, "option_enum",
114 "Enum option for dummy_index_am",
117 "Valid values are \"one\" and \"two\".",
119 di_relopt_tab[i].optname = "option_enum";
122 i++;
123
124 add_string_reloption(di_relopt_kind, "option_string_val",
125 "String option for dummy_index_am with non-NULL default",
126 "DefaultValue", &validate_string_option,
128 di_relopt_tab[i].optname = "option_string_val";
131 option_string_val_offset);
132 i++;
133
134 /*
135 * String option for dummy_index_am with NULL default, and without
136 * description.
137 */
138 add_string_reloption(di_relopt_kind, "option_string_null",
139 NULL, /* description */
142 di_relopt_tab[i].optname = "option_string_null";
145 option_string_null_offset);
146 i++;
147}
148
149
150/*
151 * Build a new index.
152 */
153static IndexBuildResult *
155{
156 IndexBuildResult *result;
157
159
160 /* let's pretend that no tuples were scanned */
161 result->heap_tuples = 0;
162 /* and no index tuples were created (that is true) */
163 result->index_tuples = 0;
164
165 return result;
166}
167
168/*
169 * Build an empty index for the initialization fork.
170 */
171static void
173{
174 /* No need to build an init fork for a dummy index */
175}
176
177/*
178 * Insert new tuple to index AM.
179 */
180static bool
184 bool indexUnchanged,
185 IndexInfo *indexInfo)
186{
187 /* nothing to do */
188 return false;
189}
190
191/*
192 * Bulk deletion of all index entries pointing to a set of table tuples.
193 */
196 IndexBulkDeleteCallback callback, void *callback_state)
197{
198 /*
199 * There is nothing to delete. Return NULL as there is nothing to pass to
200 * amvacuumcleanup.
201 */
202 return NULL;
203}
204
205/*
206 * Post-VACUUM cleanup for index AM.
207 */
210{
211 /* Index has not been modified, so returning NULL is fine */
212 return NULL;
213}
214
215/*
216 * Estimate cost of index AM.
217 */
218static void
220 Cost *indexStartupCost, Cost *indexTotalCost,
221 Selectivity *indexSelectivity, double *indexCorrelation,
222 double *indexPages)
223{
224 /* Tell planner to never use this index! */
225 *indexStartupCost = 1.0e10;
226 *indexTotalCost = 1.0e10;
227
228 /* Do not care about the rest */
229 *indexSelectivity = 1;
230 *indexCorrelation = 0;
231 *indexPages = 1;
232}
233
234/*
235 * Parse relation options for index AM, returning a DummyIndexOptions
236 * structure filled with option values.
237 */
238static bytea *
239dioptions(Datum reloptions, bool validate)
240{
241 return (bytea *) build_reloptions(reloptions, validate,
243 sizeof(DummyIndexOptions),
245}
246
247/*
248 * Validator for index AM.
249 */
250static bool
251divalidate(Oid opclassoid)
252{
253 /* Index is dummy so we are happy with any opclass */
254 return true;
255}
256
257/*
258 * Begin scan of index AM.
259 */
260static IndexScanDesc
261dibeginscan(Relation r, int nkeys, int norderbys)
262{
263 IndexScanDesc scan;
264
265 /* Let's pretend we are doing something */
266 scan = RelationGetIndexScan(r, nkeys, norderbys);
267 return scan;
268}
269
270/*
271 * Rescan of index AM.
272 */
273static void
275 ScanKey orderbys, int norderbys)
276{
277 /* nothing to do */
278}
279
280/*
281 * End scan of index AM.
282 */
283static void
285{
286 /* nothing to do */
287}
288
289/*
290 * Index AM handler function: returns IndexAmRoutine with access method
291 * parameters and callbacks.
292 */
293Datum
295{
296 static const IndexAmRoutine amroutine = {
298 .amstrategies = 0,
299 .amsupport = 1,
300 .amcanorder = false,
301 .amcanorderbyop = false,
302 .amcanhash = false,
303 .amconsistentequality = false,
304 .amconsistentordering = false,
305 .amcanbackward = false,
306 .amcanunique = false,
307 .amcanmulticol = false,
308 .amoptionalkey = false,
309 .amsearcharray = false,
310 .amsearchnulls = false,
311 .amstorage = false,
312 .amclusterable = false,
313 .ampredlocks = false,
314 .amcanparallel = false,
315 .amcanbuildparallel = false,
316 .amcaninclude = false,
317 .amusemaintenanceworkmem = false,
318 .amsummarizing = false,
319 .amparallelvacuumoptions = VACUUM_OPTION_NO_PARALLEL,
320 .amkeytype = InvalidOid,
321
322 .ambuild = dibuild,
323 .ambuildempty = dibuildempty,
324 .aminsert = diinsert,
325 .ambulkdelete = dibulkdelete,
326 .amvacuumcleanup = divacuumcleanup,
327 .amcanreturn = NULL,
328 .amcostestimate = dicostestimate,
329 .amgettreeheight = NULL,
330 .amoptions = dioptions,
331 .amproperty = NULL,
332 .ambuildphasename = NULL,
333 .amvalidate = divalidate,
334 .ambeginscan = dibeginscan,
335 .amrescan = direscan,
336 .amgettuple = NULL,
337 .amgetbitmap = NULL,
338 .amendscan = diendscan,
339 .ammarkpos = NULL,
340 .amrestrpos = NULL,
341 .amestimateparallelscan = NULL,
342 .aminitparallelscan = NULL,
343 .amparallelrescan = NULL,
344 };
345
347}
348
349void
351{
353}
static bool validate(Port *port, const char *auth)
Definition auth-oauth.c:638
static Datum values[MAXATTR]
Definition bootstrap.c:155
int32_t int32
Definition c.h:542
#define lengthof(array)
Definition c.h:803
static bool divalidate(Oid opclassoid)
static relopt_parse_elt di_relopt_tab[8]
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_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)
static void dicostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
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_FUNCTION_INFO_V1(funcname)
Definition fmgr.h:417
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
#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:93
IndexUniqueCheck
Definition genam.h:122
static struct @172 value
int i
Definition isn.c:77
#define AccessExclusiveLock
Definition lockdefs.h:43
double Cost
Definition nodes.h:261
double Selectivity
Definition nodes.h:260
pg_ternary
Definition postgres.h:554
uint64_t Datum
Definition postgres.h:70
#define InvalidOid
unsigned int Oid
static int fb(int x)
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)
void add_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
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)
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
void add_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition reloptions.c:900
relopt_kind add_reloption_kind(void)
Definition reloptions.c:731
void add_ternary_reloption(bits32 kinds, const char *name, const char *desc, LOCKMODE lockmode)
Definition reloptions.c:947
relopt_kind
Definition reloptions.h:41
@ RELOPT_TYPE_ENUM
Definition reloptions.h:35
@ RELOPT_TYPE_INT
Definition reloptions.h:33
@ RELOPT_TYPE_TERNARY
Definition reloptions.h:32
@ RELOPT_TYPE_BOOL
Definition reloptions.h:31
@ RELOPT_TYPE_REAL
Definition reloptions.h:34
@ RELOPT_TYPE_STRING
Definition reloptions.h:36
DummyAmEnum option_enum
pg_ternary option_ternary_1
NodeTag type
Definition amapi.h:234
double heap_tuples
Definition genam.h:38
double index_tuples
Definition genam.h:39
Definition type.h:96
const char * optname
Definition reloptions.h:160
relopt_type opttype
Definition reloptions.h:161
Definition c.h:706
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
#define VACUUM_OPTION_NO_PARALLEL
Definition vacuum.h:42