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 "utils/guc.h"
#include "utils/rel.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

void _PG_init (void)
 
 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)
 

Variables

 PG_MODULE_MAGIC
 
relopt_parse_elt di_relopt_tab [6]
 
relopt_kind di_relopt_kind
 
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 34 of file dummy_index_am.c.

35 {
38 } DummyAmEnum;
DummyAmEnum
@ DUMMY_AM_ENUM_ONE
@ DUMMY_AM_ENUM_TWO

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 331 of file dummy_index_am.c.

332 {
334 }
static void create_reloptions_table(void)

References create_reloptions_table().

◆ create_reloptions_table()

static void create_reloptions_table ( void  )
static

Definition at line 78 of file dummy_index_am.c.

79 {
81 
82  add_int_reloption(di_relopt_kind, "option_int",
83  "Integer option for dummy_index_am",
84  10, -10, 100, AccessExclusiveLock);
85  di_relopt_tab[0].optname = "option_int";
88 
89  add_real_reloption(di_relopt_kind, "option_real",
90  "Real option for dummy_index_am",
91  3.1415, -10, 100, AccessExclusiveLock);
92  di_relopt_tab[1].optname = "option_real";
95 
96  add_bool_reloption(di_relopt_kind, "option_bool",
97  "Boolean option for dummy_index_am",
98  true, AccessExclusiveLock);
99  di_relopt_tab[2].optname = "option_bool";
101  di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool);
102 
103  add_enum_reloption(di_relopt_kind, "option_enum",
104  "Enum option for dummy_index_am",
107  "Valid values are \"one\" and \"two\".",
109  di_relopt_tab[3].optname = "option_enum";
111  di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum);
112 
113  add_string_reloption(di_relopt_kind, "option_string_val",
114  "String option for dummy_index_am with non-NULL default",
115  "DefaultValue", &validate_string_option,
117  di_relopt_tab[4].optname = "option_string_val";
120  option_string_val_offset);
121 
122  /*
123  * String option for dummy_index_am with NULL default, and without
124  * description.
125  */
126  add_string_reloption(di_relopt_kind, "option_string_null",
127  NULL, /* description */
128  NULL, &validate_string_option,
130  di_relopt_tab[5].optname = "option_string_null";
133  option_string_null_offset);
134 }
#define offsetof(type, field)
Definition: c.h:727
static void validate_string_option(const char *value)
relopt_enum_elt_def dummyAmEnumValues[]
relopt_parse_elt di_relopt_tab[6]
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:894
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:1091
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:1011
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:947
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:842
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:676
@ 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, offsetof, 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 248 of file dummy_index_am.c.

249 {
250  IndexScanDesc scan;
251 
252  /* Let's pretend we are doing something */
253  scan = RelationGetIndexScan(r, nkeys, norderbys);
254  return scan;
255 }
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
Definition: genam.c:81

References RelationGetIndexScan().

Referenced by dihandler().

◆ dibuild()

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

Definition at line 141 of file dummy_index_am.c.

142 {
143  IndexBuildResult *result;
144 
145  result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
146 
147  /* let's pretend that no tuples were scanned */
148  result->heap_tuples = 0;
149  /* and no index tuples were created (that is true) */
150  result->index_tuples = 0;
151 
152  return result;
153 }
void * palloc(Size size)
Definition: mcxt.c:1062
double heap_tuples
Definition: genam.h:32
double index_tuples
Definition: genam.h:33

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

Referenced by dihandler().

◆ dibuildempty()

static void dibuildempty ( Relation  index)
static

Definition at line 159 of file dummy_index_am.c.

160 {
161  /* No need to build an init fork for a dummy index */
162 }

Referenced by dihandler().

◆ dibulkdelete()

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

Definition at line 182 of file dummy_index_am.c.

184 {
185  /*
186  * There is nothing to delete. Return NULL as there is nothing to pass to
187  * amvacuumcleanup.
188  */
189  return NULL;
190 }

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 206 of file dummy_index_am.c.

210 {
211  /* Tell planner to never use this index! */
212  *indexStartupCost = 1.0e10;
213  *indexTotalCost = 1.0e10;
214 
215  /* Do not care about the rest */
216  *indexSelectivity = 1;
217  *indexCorrelation = 0;
218  *indexPages = 1;
219 }

Referenced by dihandler().

◆ diendscan()

static void diendscan ( IndexScanDesc  scan)
static

Definition at line 271 of file dummy_index_am.c.

272 {
273  /* nothing to do */
274 }

Referenced by dihandler().

◆ dihandler()

Datum dihandler ( PG_FUNCTION_ARGS  )

Definition at line 281 of file dummy_index_am.c.

282 {
283  IndexAmRoutine *amroutine = makeNode(IndexAmRoutine);
284 
285  amroutine->amstrategies = 0;
286  amroutine->amsupport = 1;
287  amroutine->amcanorder = false;
288  amroutine->amcanorderbyop = false;
289  amroutine->amcanbackward = false;
290  amroutine->amcanunique = false;
291  amroutine->amcanmulticol = false;
292  amroutine->amoptionalkey = false;
293  amroutine->amsearcharray = false;
294  amroutine->amsearchnulls = false;
295  amroutine->amstorage = false;
296  amroutine->amclusterable = false;
297  amroutine->ampredlocks = false;
298  amroutine->amcanparallel = false;
299  amroutine->amcaninclude = false;
300  amroutine->amusemaintenanceworkmem = false;
301  amroutine->amhotblocking = true;
303  amroutine->amkeytype = InvalidOid;
304 
305  amroutine->ambuild = dibuild;
306  amroutine->ambuildempty = dibuildempty;
307  amroutine->aminsert = diinsert;
308  amroutine->ambulkdelete = dibulkdelete;
309  amroutine->amvacuumcleanup = divacuumcleanup;
310  amroutine->amcanreturn = NULL;
311  amroutine->amcostestimate = dicostestimate;
312  amroutine->amoptions = dioptions;
313  amroutine->amproperty = NULL;
314  amroutine->ambuildphasename = NULL;
315  amroutine->amvalidate = divalidate;
316  amroutine->ambeginscan = dibeginscan;
317  amroutine->amrescan = direscan;
318  amroutine->amgettuple = NULL;
319  amroutine->amgetbitmap = NULL;
320  amroutine->amendscan = diendscan;
321  amroutine->ammarkpos = NULL;
322  amroutine->amrestrpos = NULL;
323  amroutine->amestimateparallelscan = NULL;
324  amroutine->aminitparallelscan = NULL;
325  amroutine->amparallelrescan = NULL;
326 
327  PG_RETURN_POINTER(amroutine);
328 }
static bool divalidate(Oid opclassoid)
static bytea * dioptions(Datum reloptions, bool validate)
static void diendscan(IndexScanDesc scan)
static IndexBuildResult * dibuild(Relation heap, Relation index, IndexInfo *indexInfo)
static void dibuildempty(Relation index)
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 * dibulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
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:587
#define InvalidOid
Definition: postgres_ext.h:36
ambuildphasename_function ambuildphasename
Definition: amapi.h:270
ambuildempty_function ambuildempty
Definition: amapi.h:262
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:265
bool amclusterable
Definition: amapi.h:238
amoptions_function amoptions
Definition: amapi.h:268
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:282
amrestrpos_function amrestrpos
Definition: amapi.h:279
aminsert_function aminsert
Definition: amapi.h:263
amendscan_function amendscan
Definition: amapi.h:277
amparallelrescan_function amparallelrescan
Definition: amapi.h:284
Oid amkeytype
Definition: amapi.h:252
bool ampredlocks
Definition: amapi.h:240
uint16 amsupport
Definition: amapi.h:216
amcostestimate_function amcostestimate
Definition: amapi.h:267
bool amcanorderbyop
Definition: amapi.h:222
ambuild_function ambuild
Definition: amapi.h:261
bool amstorage
Definition: amapi.h:236
uint16 amstrategies
Definition: amapi.h:214
bool amoptionalkey
Definition: amapi.h:230
amgettuple_function amgettuple
Definition: amapi.h:275
amcanreturn_function amcanreturn
Definition: amapi.h:266
bool amcanunique
Definition: amapi.h:226
amgetbitmap_function amgetbitmap
Definition: amapi.h:276
amproperty_function amproperty
Definition: amapi.h:269
ambulkdelete_function ambulkdelete
Definition: amapi.h:264
bool amsearcharray
Definition: amapi.h:232
amvalidate_function amvalidate
Definition: amapi.h:271
ammarkpos_function ammarkpos
Definition: amapi.h:278
bool amcanmulticol
Definition: amapi.h:228
bool amusemaintenanceworkmem
Definition: amapi.h:246
ambeginscan_function ambeginscan
Definition: amapi.h:273
bool amcanparallel
Definition: amapi.h:242
amrescan_function amrescan
Definition: amapi.h:274
bool amcanorder
Definition: amapi.h:220
bool amhotblocking
Definition: amapi.h:248
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:283
uint8 amparallelvacuumoptions
Definition: amapi.h:250
bool amcanbackward
Definition: amapi.h:224
bool amcaninclude
Definition: amapi.h:244
bool amsearchnulls
Definition: amapi.h:234
#define VACUUM_OPTION_NO_PARALLEL
Definition: vacuum.h:41

References IndexAmRoutine::ambeginscan, IndexAmRoutine::ambuild, IndexAmRoutine::ambuildempty, IndexAmRoutine::ambuildphasename, IndexAmRoutine::ambulkdelete, IndexAmRoutine::amcanbackward, 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::amgettuple, IndexAmRoutine::amhotblocking, 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::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 168 of file dummy_index_am.c.

173 {
174  /* nothing to do */
175  return false;
176 }

Referenced by dihandler().

◆ dioptions()

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

Definition at line 226 of file dummy_index_am.c.

227 {
228  return (bytea *) build_reloptions(reloptions, validate,
230  sizeof(DummyIndexOptions),
232 }
#define lengthof(array)
Definition: c.h:734
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:1904
Definition: c.h:622

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 261 of file dummy_index_am.c.

263 {
264  /* nothing to do */
265 }

Referenced by dihandler().

◆ divacuumcleanup()

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

Definition at line 196 of file dummy_index_am.c.

197 {
198  /* Index has not been modified, so returning NULL is fine */
199  return NULL;
200 }

Referenced by dihandler().

◆ divalidate()

static bool divalidate ( Oid  opclassoid)
static

Definition at line 238 of file dummy_index_am.c.

239 {
240  /* Index is dummy so we are happy with any opclass */
241  return true;
242 }

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 66 of file dummy_index_am.c.

67 {
69  (errmsg("new option value for string parameter %s",
70  value ? value : "NULL")));
71 }
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define NOTICE
Definition: elog.h:29
#define ereport(elevel,...)
Definition: elog.h:143
static struct @142 value

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

Referenced by create_reloptions_table().

Variable Documentation

◆ di_relopt_kind

relopt_kind di_relopt_kind

Definition at line 32 of file dummy_index_am.c.

Referenced by create_reloptions_table(), and dioptions().

◆ di_relopt_tab

relopt_parse_elt di_relopt_tab[6]

Definition at line 29 of file dummy_index_am.c.

Referenced by create_reloptions_table(), and dioptions().

◆ dummyAmEnumValues

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

Definition at line 52 of file dummy_index_am.c.

Referenced by create_reloptions_table().

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 24 of file dummy_index_am.c.