PostgreSQL Source Code git master
dummy_index_am.c File Reference
#include "postgres.h"
#include "access/amapi.h"
#include "access/reloptions.h"
#include "catalog/index.h"
#include "commands/vacuum.h"
#include "nodes/pathnodes.h"
Include dependency graph for dummy_index_am.c:

Go to the source code of this file.

Data Structures

struct  DummyIndexOptions
 

Typedefs

typedef enum DummyAmEnum DummyAmEnum
 
typedef struct DummyIndexOptions DummyIndexOptions
 

Enumerations

enum  DummyAmEnum { DUMMY_AM_ENUM_ONE , DUMMY_AM_ENUM_TWO }
 

Functions

 PG_FUNCTION_INFO_V1 (dihandler)
 
static void validate_string_option (const char *value)
 
static void create_reloptions_table (void)
 
static IndexBuildResultdibuild (Relation heap, Relation index, IndexInfo *indexInfo)
 
static void dibuildempty (Relation index)
 
static bool diinsert (Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
 
static IndexBulkDeleteResultdibulkdelete (IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
 
static IndexBulkDeleteResultdivacuumcleanup (IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
 
static void dicostestimate (PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
 
static byteadioptions (Datum reloptions, bool validate)
 
static bool divalidate (Oid opclassoid)
 
static IndexScanDesc dibeginscan (Relation r, int nkeys, int norderbys)
 
static void direscan (IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
 
static void diendscan (IndexScanDesc scan)
 
Datum dihandler (PG_FUNCTION_ARGS)
 
void _PG_init (void)
 

Variables

 PG_MODULE_MAGIC
 
static relopt_parse_elt di_relopt_tab [6]
 
static relopt_kind di_relopt_kind
 
static relopt_enum_elt_def dummyAmEnumValues []
 

Typedef Documentation

◆ DummyAmEnum

typedef enum DummyAmEnum DummyAmEnum

◆ DummyIndexOptions

Enumeration Type Documentation

◆ DummyAmEnum

Enumerator
DUMMY_AM_ENUM_ONE 
DUMMY_AM_ENUM_TWO 

Definition at line 30 of file dummy_index_am.c.

31{
DummyAmEnum
@ DUMMY_AM_ENUM_ONE
@ DUMMY_AM_ENUM_TWO

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 329 of file dummy_index_am.c.

330{
332}
static void create_reloptions_table(void)

References create_reloptions_table().

◆ create_reloptions_table()

static void create_reloptions_table ( void  )
static

Definition at line 74 of file dummy_index_am.c.

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}
static void validate_string_option(const char *value)
static relopt_enum_elt_def dummyAmEnumValues[]
static relopt_parse_elt di_relopt_tab[6]
static relopt_kind di_relopt_kind
#define AccessExclusiveLock
Definition: lockdefs.h:43
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:901
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:1098
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:1018
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:954
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:849
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:683
@ 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
const char * optname
Definition: reloptions.h:152
relopt_type opttype
Definition: reloptions.h:153

References AccessExclusiveLock, add_bool_reloption(), add_enum_reloption(), add_int_reloption(), add_real_reloption(), add_reloption_kind(), add_string_reloption(), di_relopt_kind, di_relopt_tab, DUMMY_AM_ENUM_ONE, dummyAmEnumValues, relopt_parse_elt::offset, relopt_parse_elt::optname, relopt_parse_elt::opttype, RELOPT_TYPE_BOOL, RELOPT_TYPE_ENUM, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING, and validate_string_option().

Referenced by _PG_init().

◆ dibeginscan()

static IndexScanDesc dibeginscan ( Relation  r,
int  nkeys,
int  norderbys 
)
static

Definition at line 244 of file dummy_index_am.c.

245{
246 IndexScanDesc scan;
247
248 /* Let's pretend we are doing something */
249 scan = RelationGetIndexScan(r, nkeys, norderbys);
250 return scan;
251}
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
Definition: genam.c:80

References RelationGetIndexScan().

Referenced by dihandler().

◆ dibuild()

static IndexBuildResult * dibuild ( Relation  heap,
Relation  index,
IndexInfo indexInfo 
)
static

Definition at line 137 of file dummy_index_am.c.

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}
void * palloc(Size size)
Definition: mcxt.c:1317
double heap_tuples
Definition: genam.h:34
double index_tuples
Definition: genam.h:35

References IndexBuildResult::heap_tuples, IndexBuildResult::index_tuples, and palloc().

Referenced by dihandler().

◆ dibuildempty()

static void dibuildempty ( Relation  index)
static

Definition at line 155 of file dummy_index_am.c.

156{
157 /* No need to build an init fork for a dummy index */
158}

Referenced by dihandler().

◆ dibulkdelete()

static IndexBulkDeleteResult * dibulkdelete ( IndexVacuumInfo info,
IndexBulkDeleteResult stats,
IndexBulkDeleteCallback  callback,
void *  callback_state 
)
static

Definition at line 178 of file dummy_index_am.c.

180{
181 /*
182 * There is nothing to delete. Return NULL as there is nothing to pass to
183 * amvacuumcleanup.
184 */
185 return NULL;
186}

Referenced by dihandler().

◆ dicostestimate()

static void dicostestimate ( PlannerInfo root,
IndexPath path,
double  loop_count,
Cost indexStartupCost,
Cost indexTotalCost,
Selectivity indexSelectivity,
double *  indexCorrelation,
double *  indexPages 
)
static

Definition at line 202 of file dummy_index_am.c.

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}

Referenced by dihandler().

◆ diendscan()

static void diendscan ( IndexScanDesc  scan)
static

Definition at line 267 of file dummy_index_am.c.

268{
269 /* nothing to do */
270}

Referenced by dihandler().

◆ dihandler()

Datum dihandler ( PG_FUNCTION_ARGS  )

Definition at line 277 of file dummy_index_am.c.

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}
static bool divalidate(Oid opclassoid)
static void diendscan(IndexScanDesc scan)
static void dibuildempty(Relation index)
static IndexBuildResult * dibuild(Relation heap, Relation index, IndexInfo *indexInfo)
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)
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)
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define makeNode(_type_)
Definition: nodes.h:155
#define InvalidOid
Definition: postgres_ext.h:37
ambuildphasename_function ambuildphasename
Definition: amapi.h:289
ambuildempty_function ambuildempty
Definition: amapi.h:279
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:283
bool amclusterable
Definition: amapi.h:253
amoptions_function amoptions
Definition: amapi.h:287
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:301
amrestrpos_function amrestrpos
Definition: amapi.h:298
aminsert_function aminsert
Definition: amapi.h:280
amendscan_function amendscan
Definition: amapi.h:296
amparallelrescan_function amparallelrescan
Definition: amapi.h:303
Oid amkeytype
Definition: amapi.h:269
bool ampredlocks
Definition: amapi.h:255
uint16 amsupport
Definition: amapi.h:231
amcostestimate_function amcostestimate
Definition: amapi.h:285
bool amcanorderbyop
Definition: amapi.h:237
ambuild_function ambuild
Definition: amapi.h:278
bool amstorage
Definition: amapi.h:251
uint16 amstrategies
Definition: amapi.h:229
bool amoptionalkey
Definition: amapi.h:245
amgettuple_function amgettuple
Definition: amapi.h:294
amcanreturn_function amcanreturn
Definition: amapi.h:284
bool amcanunique
Definition: amapi.h:241
amgetbitmap_function amgetbitmap
Definition: amapi.h:295
amproperty_function amproperty
Definition: amapi.h:288
ambulkdelete_function ambulkdelete
Definition: amapi.h:282
bool amsearcharray
Definition: amapi.h:247
bool amsummarizing
Definition: amapi.h:265
amvalidate_function amvalidate
Definition: amapi.h:290
ammarkpos_function ammarkpos
Definition: amapi.h:297
bool amcanmulticol
Definition: amapi.h:243
bool amusemaintenanceworkmem
Definition: amapi.h:263
ambeginscan_function ambeginscan
Definition: amapi.h:292
bool amcanparallel
Definition: amapi.h:257
amrescan_function amrescan
Definition: amapi.h:293
bool amcanorder
Definition: amapi.h:235
bool amcanbuildparallel
Definition: amapi.h:259
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:302
uint8 amparallelvacuumoptions
Definition: amapi.h:267
bool amcanbackward
Definition: amapi.h:239
amgettreeheight_function amgettreeheight
Definition: amapi.h:286
bool amcaninclude
Definition: amapi.h:261
bool amsearchnulls
Definition: amapi.h:249
#define VACUUM_OPTION_NO_PARALLEL
Definition: vacuum.h:42

References IndexAmRoutine::ambeginscan, IndexAmRoutine::ambuild, IndexAmRoutine::ambuildempty, IndexAmRoutine::ambuildphasename, IndexAmRoutine::ambulkdelete, IndexAmRoutine::amcanbackward, IndexAmRoutine::amcanbuildparallel, IndexAmRoutine::amcaninclude, IndexAmRoutine::amcanmulticol, IndexAmRoutine::amcanorder, IndexAmRoutine::amcanorderbyop, IndexAmRoutine::amcanparallel, IndexAmRoutine::amcanreturn, IndexAmRoutine::amcanunique, IndexAmRoutine::amclusterable, IndexAmRoutine::amcostestimate, IndexAmRoutine::amendscan, IndexAmRoutine::amestimateparallelscan, IndexAmRoutine::amgetbitmap, IndexAmRoutine::amgettreeheight, IndexAmRoutine::amgettuple, IndexAmRoutine::aminitparallelscan, IndexAmRoutine::aminsert, IndexAmRoutine::amkeytype, IndexAmRoutine::ammarkpos, IndexAmRoutine::amoptionalkey, IndexAmRoutine::amoptions, IndexAmRoutine::amparallelrescan, IndexAmRoutine::amparallelvacuumoptions, IndexAmRoutine::ampredlocks, IndexAmRoutine::amproperty, IndexAmRoutine::amrescan, IndexAmRoutine::amrestrpos, IndexAmRoutine::amsearcharray, IndexAmRoutine::amsearchnulls, IndexAmRoutine::amstorage, IndexAmRoutine::amstrategies, IndexAmRoutine::amsummarizing, IndexAmRoutine::amsupport, IndexAmRoutine::amusemaintenanceworkmem, IndexAmRoutine::amvacuumcleanup, IndexAmRoutine::amvalidate, dibeginscan(), dibuild(), dibuildempty(), dibulkdelete(), dicostestimate(), diendscan(), diinsert(), dioptions(), direscan(), divacuumcleanup(), divalidate(), InvalidOid, makeNode, PG_RETURN_POINTER, and VACUUM_OPTION_NO_PARALLEL.

◆ diinsert()

static bool diinsert ( Relation  index,
Datum values,
bool *  isnull,
ItemPointer  ht_ctid,
Relation  heapRel,
IndexUniqueCheck  checkUnique,
bool  indexUnchanged,
IndexInfo indexInfo 
)
static

Definition at line 164 of file dummy_index_am.c.

169{
170 /* nothing to do */
171 return false;
172}

Referenced by dihandler().

◆ dioptions()

static bytea * dioptions ( Datum  reloptions,
bool  validate 
)
static

Definition at line 222 of file dummy_index_am.c.

223{
224 return (bytea *) build_reloptions(reloptions, validate,
226 sizeof(DummyIndexOptions),
228}
#define lengthof(array)
Definition: c.h:745
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:1908
Definition: c.h:644

References build_reloptions(), di_relopt_kind, di_relopt_tab, and lengthof.

Referenced by dihandler().

◆ direscan()

static void direscan ( IndexScanDesc  scan,
ScanKey  scankey,
int  nscankeys,
ScanKey  orderbys,
int  norderbys 
)
static

Definition at line 257 of file dummy_index_am.c.

259{
260 /* nothing to do */
261}

Referenced by dihandler().

◆ divacuumcleanup()

static IndexBulkDeleteResult * divacuumcleanup ( IndexVacuumInfo info,
IndexBulkDeleteResult stats 
)
static

Definition at line 192 of file dummy_index_am.c.

193{
194 /* Index has not been modified, so returning NULL is fine */
195 return NULL;
196}

Referenced by dihandler().

◆ divalidate()

static bool divalidate ( Oid  opclassoid)
static

Definition at line 234 of file dummy_index_am.c.

235{
236 /* Index is dummy so we are happy with any opclass */
237 return true;
238}

Referenced by dihandler().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( dihandler  )

◆ validate_string_option()

static void validate_string_option ( const char *  value)
static

Definition at line 62 of file dummy_index_am.c.

63{
65 (errmsg("new option value for string parameter %s",
66 value ? value : "NULL")));
67}
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define NOTICE
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:149
static struct @162 value

References ereport, errmsg(), NOTICE, and value.

Referenced by create_reloptions_table().

Variable Documentation

◆ di_relopt_kind

relopt_kind di_relopt_kind
static

Definition at line 28 of file dummy_index_am.c.

Referenced by create_reloptions_table(), and dioptions().

◆ di_relopt_tab

relopt_parse_elt di_relopt_tab[6]
static

Definition at line 25 of file dummy_index_am.c.

Referenced by create_reloptions_table(), and dioptions().

◆ dummyAmEnumValues

relopt_enum_elt_def dummyAmEnumValues[]
static
Initial value:
=
{
{(const char *) NULL}
}

Definition at line 48 of file dummy_index_am.c.

Referenced by create_reloptions_table().

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 22 of file dummy_index_am.c.