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

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

33 {
36 } 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 76 of file dummy_index_am.c.

77 {
79 
80  add_int_reloption(di_relopt_kind, "option_int",
81  "Integer option for dummy_index_am",
82  10, -10, 100, AccessExclusiveLock);
83  di_relopt_tab[0].optname = "option_int";
85  di_relopt_tab[0].offset = offsetof(DummyIndexOptions, option_int);
86 
87  add_real_reloption(di_relopt_kind, "option_real",
88  "Real option for dummy_index_am",
89  3.1415, -10, 100, AccessExclusiveLock);
90  di_relopt_tab[1].optname = "option_real";
92  di_relopt_tab[1].offset = offsetof(DummyIndexOptions, option_real);
93 
94  add_bool_reloption(di_relopt_kind, "option_bool",
95  "Boolean option for dummy_index_am",
96  true, AccessExclusiveLock);
97  di_relopt_tab[2].optname = "option_bool";
99  di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool);
100 
101  add_enum_reloption(di_relopt_kind, "option_enum",
102  "Enum option for dummy_index_am",
105  "Valid values are \"one\" and \"two\".",
107  di_relopt_tab[3].optname = "option_enum";
109  di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum);
110 
111  add_string_reloption(di_relopt_kind, "option_string_val",
112  "String option for dummy_index_am with non-NULL default",
113  "DefaultValue", &validate_string_option,
115  di_relopt_tab[4].optname = "option_string_val";
117  di_relopt_tab[4].offset = offsetof(DummyIndexOptions,
118  option_string_val_offset);
119 
120  /*
121  * String option for dummy_index_am with NULL default, and without
122  * description.
123  */
124  add_string_reloption(di_relopt_kind, "option_string_null",
125  NULL, /* description */
126  NULL, &validate_string_option,
128  di_relopt_tab[5].optname = "option_string_null";
130  di_relopt_tab[5].offset = offsetof(DummyIndexOptions,
131  option_string_null_offset);
132 }
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 246 of file dummy_index_am.c.

247 {
248  IndexScanDesc scan;
249 
250  /* Let's pretend we are doing something */
251  scan = RelationGetIndexScan(r, nkeys, norderbys);
252  return scan;
253 }
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 139 of file dummy_index_am.c.

140 {
141  IndexBuildResult *result;
142 
143  result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
144 
145  /* let's pretend that no tuples were scanned */
146  result->heap_tuples = 0;
147  /* and no index tuples were created (that is true) */
148  result->index_tuples = 0;
149 
150  return result;
151 }
void * palloc(Size size)
Definition: mcxt.c:1317
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 157 of file dummy_index_am.c.

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

Referenced by dihandler().

◆ dibulkdelete()

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

Definition at line 180 of file dummy_index_am.c.

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

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

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

Referenced by dihandler().

◆ diendscan()

static void diendscan ( IndexScanDesc  scan)
static

Definition at line 269 of file dummy_index_am.c.

270 {
271  /* nothing to do */
272 }

Referenced by dihandler().

◆ dihandler()

Datum dihandler ( PG_FUNCTION_ARGS  )

Definition at line 279 of file dummy_index_am.c.

280 {
281  IndexAmRoutine *amroutine = makeNode(IndexAmRoutine);
282 
283  amroutine->amstrategies = 0;
284  amroutine->amsupport = 1;
285  amroutine->amcanorder = false;
286  amroutine->amcanorderbyop = false;
287  amroutine->amcanbackward = false;
288  amroutine->amcanunique = false;
289  amroutine->amcanmulticol = false;
290  amroutine->amoptionalkey = false;
291  amroutine->amsearcharray = false;
292  amroutine->amsearchnulls = false;
293  amroutine->amstorage = false;
294  amroutine->amclusterable = false;
295  amroutine->ampredlocks = false;
296  amroutine->amcanparallel = false;
297  amroutine->amcanbuildparallel = false;
298  amroutine->amcaninclude = false;
299  amroutine->amusemaintenanceworkmem = false;
300  amroutine->amsummarizing = false;
302  amroutine->amkeytype = InvalidOid;
303 
304  amroutine->ambuild = dibuild;
305  amroutine->ambuildempty = dibuildempty;
306  amroutine->aminsert = diinsert;
307  amroutine->ambulkdelete = dibulkdelete;
308  amroutine->amvacuumcleanup = divacuumcleanup;
309  amroutine->amcanreturn = NULL;
310  amroutine->amcostestimate = dicostestimate;
311  amroutine->amgettreeheight = NULL;
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:155
#define InvalidOid
Definition: postgres_ext.h:36
ambuildphasename_function ambuildphasename
Definition: amapi.h:285
ambuildempty_function ambuildempty
Definition: amapi.h:275
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:279
bool amclusterable
Definition: amapi.h:249
amoptions_function amoptions
Definition: amapi.h:283
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:297
amrestrpos_function amrestrpos
Definition: amapi.h:294
aminsert_function aminsert
Definition: amapi.h:276
amendscan_function amendscan
Definition: amapi.h:292
amparallelrescan_function amparallelrescan
Definition: amapi.h:299
Oid amkeytype
Definition: amapi.h:265
bool ampredlocks
Definition: amapi.h:251
uint16 amsupport
Definition: amapi.h:227
amcostestimate_function amcostestimate
Definition: amapi.h:281
bool amcanorderbyop
Definition: amapi.h:233
ambuild_function ambuild
Definition: amapi.h:274
bool amstorage
Definition: amapi.h:247
uint16 amstrategies
Definition: amapi.h:225
bool amoptionalkey
Definition: amapi.h:241
amgettuple_function amgettuple
Definition: amapi.h:290
amcanreturn_function amcanreturn
Definition: amapi.h:280
bool amcanunique
Definition: amapi.h:237
amgetbitmap_function amgetbitmap
Definition: amapi.h:291
amproperty_function amproperty
Definition: amapi.h:284
ambulkdelete_function ambulkdelete
Definition: amapi.h:278
bool amsearcharray
Definition: amapi.h:243
bool amsummarizing
Definition: amapi.h:261
amvalidate_function amvalidate
Definition: amapi.h:286
ammarkpos_function ammarkpos
Definition: amapi.h:293
bool amcanmulticol
Definition: amapi.h:239
bool amusemaintenanceworkmem
Definition: amapi.h:259
ambeginscan_function ambeginscan
Definition: amapi.h:288
bool amcanparallel
Definition: amapi.h:253
amrescan_function amrescan
Definition: amapi.h:289
bool amcanorder
Definition: amapi.h:231
bool amcanbuildparallel
Definition: amapi.h:255
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:298
uint8 amparallelvacuumoptions
Definition: amapi.h:263
bool amcanbackward
Definition: amapi.h:235
amgettreeheight_function amgettreeheight
Definition: amapi.h:282
bool amcaninclude
Definition: amapi.h:257
bool amsearchnulls
Definition: amapi.h:245
#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 166 of file dummy_index_am.c.

171 {
172  /* nothing to do */
173  return false;
174 }

Referenced by dihandler().

◆ dioptions()

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

Definition at line 224 of file dummy_index_am.c.

225 {
226  return (bytea *) build_reloptions(reloptions, validate,
228  sizeof(DummyIndexOptions),
230 }
#define lengthof(array)
Definition: c.h:791
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:690

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

261 {
262  /* nothing to do */
263 }

Referenced by dihandler().

◆ divacuumcleanup()

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

Definition at line 194 of file dummy_index_am.c.

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

Referenced by dihandler().

◆ divalidate()

static bool divalidate ( Oid  opclassoid)
static

Definition at line 236 of file dummy_index_am.c.

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

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

65 {
67  (errmsg("new option value for string parameter %s",
68  value ? value : "NULL")));
69 }
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define NOTICE
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:149
static struct @157 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 30 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 27 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 50 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.