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, 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.

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 328 of file dummy_index_am.c.

References create_reloptions_table().

329 {
331 }
static void create_reloptions_table(void)

◆ create_reloptions_table()

static void create_reloptions_table ( void  )
static

Definition at line 77 of file dummy_index_am.c.

References AccessExclusiveLock, add_bool_reloption(), add_enum_reloption(), add_int_reloption(), add_real_reloption(), add_reloption_kind(), add_string_reloption(), di_relopt_kind, DUMMY_AM_ENUM_ONE, relopt_parse_elt::offset, offsetof, DummyIndexOptions::option_bool, DummyIndexOptions::option_enum, DummyIndexOptions::option_int, DummyIndexOptions::option_real, DummyIndexOptions::option_string_null_offset, DummyIndexOptions::option_string_val_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().

78 {
80 
81  add_int_reloption(di_relopt_kind, "option_int",
82  "Integer option for dummy_index_am",
83  10, -10, 100, AccessExclusiveLock);
84  di_relopt_tab[0].optname = "option_int";
87 
88  add_real_reloption(di_relopt_kind, "option_real",
89  "Real option for dummy_index_am",
90  3.1415, -10, 100, AccessExclusiveLock);
91  di_relopt_tab[1].optname = "option_real";
94 
95  add_bool_reloption(di_relopt_kind, "option_bool",
96  "Boolean option for dummy_index_am",
97  true, AccessExclusiveLock);
98  di_relopt_tab[2].optname = "option_bool";
100  di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool);
101 
102  add_enum_reloption(di_relopt_kind, "option_enum",
103  "Enum option for dummy_index_am",
106  "Valid values are \"one\" and \"two\".",
108  di_relopt_tab[3].optname = "option_enum";
110  di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum);
111 
112  add_string_reloption(di_relopt_kind, "option_string_val",
113  "String option for dummy_index_am with non-NULL default",
114  "DefaultValue", &validate_string_option,
116  di_relopt_tab[4].optname = "option_string_val";
119  option_string_val_offset);
120 
121  /*
122  * String option for dummy_index_am with NULL default, and without
123  * description.
124  */
125  add_string_reloption(di_relopt_kind, "option_string_null",
126  NULL, /* description */
127  NULL, &validate_string_option,
129  di_relopt_tab[5].optname = "option_string_null";
132  option_string_null_offset);
133 }
relopt_type opttype
Definition: reloptions.h:147
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:739
relopt_enum_elt_def dummyAmEnumValues[]
const char * optname
Definition: reloptions.h:146
static void validate_string_option(const char *value)
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:758
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:618
relopt_kind di_relopt_kind
#define AccessExclusiveLock
Definition: lockdefs.h:45
relopt_parse_elt di_relopt_tab[6]
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:810
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:785
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:722
#define offsetof(type, field)
Definition: c.h:662

◆ dibeginscan()

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

Definition at line 246 of file dummy_index_am.c.

References RelationGetIndexScan().

Referenced by dihandler().

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

◆ dibuild()

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

Definition at line 140 of file dummy_index_am.c.

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

Referenced by dihandler().

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

◆ dibuildempty()

static void dibuildempty ( Relation  index)
static

Definition at line 158 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ dibulkdelete()

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

Definition at line 180 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ 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.

Referenced by dihandler().

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 }

◆ diendscan()

static void diendscan ( IndexScanDesc  scan)
static

Definition at line 269 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ dihandler()

Datum dihandler ( PG_FUNCTION_ARGS  )

Definition at line 279 of file dummy_index_am.c.

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::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.

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->amcaninclude = false;
298  amroutine->amusemaintenanceworkmem = 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->amoptions = dioptions;
310  amroutine->amproperty = NULL;
311  amroutine->ambuildphasename = NULL;
312  amroutine->amvalidate = divalidate;
313  amroutine->ambeginscan = dibeginscan;
314  amroutine->amrescan = direscan;
315  amroutine->amgettuple = NULL;
316  amroutine->amgetbitmap = NULL;
317  amroutine->amendscan = diendscan;
318  amroutine->ammarkpos = NULL;
319  amroutine->amrestrpos = NULL;
320  amroutine->amestimateparallelscan = NULL;
321  amroutine->aminitparallelscan = NULL;
322  amroutine->amparallelrescan = NULL;
323 
324  PG_RETURN_POINTER(amroutine);
325 }
ambeginscan_function ambeginscan
Definition: amapi.h:225
uint8 amparallelvacuumoptions
Definition: amapi.h:203
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
ambulkdelete_function ambulkdelete
Definition: amapi.h:217
bool amcanmulticol
Definition: amapi.h:183
uint16 amsupport
Definition: amapi.h:173
amgettuple_function amgettuple
Definition: amapi.h:227
bool amcanorderbyop
Definition: amapi.h:177
amproperty_function amproperty
Definition: amapi.h:222
static IndexBuildResult * dibuild(Relation heap, Relation index, IndexInfo *indexInfo)
static IndexScanDesc dibeginscan(Relation r, int nkeys, int norderbys)
amparallelrescan_function amparallelrescan
Definition: amapi.h:236
bool amstorage
Definition: amapi.h:191
static IndexBulkDeleteResult * dibulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
bool ampredlocks
Definition: amapi.h:195
aminsert_function aminsert
Definition: amapi.h:216
Oid amkeytype
Definition: amapi.h:205
static IndexBulkDeleteResult * divacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
bool amoptionalkey
Definition: amapi.h:185
amvalidate_function amvalidate
Definition: amapi.h:224
static void diendscan(IndexScanDesc scan)
amgetbitmap_function amgetbitmap
Definition: amapi.h:228
static bool divalidate(Oid opclassoid)
ambuild_function ambuild
Definition: amapi.h:214
amoptions_function amoptions
Definition: amapi.h:221
bool amcaninclude
Definition: amapi.h:199
amcostestimate_function amcostestimate
Definition: amapi.h:220
bool amcanunique
Definition: amapi.h:181
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:218
amendscan_function amendscan
Definition: amapi.h:229
bool amcanbackward
Definition: amapi.h:179
static void direscan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
amrescan_function amrescan
Definition: amapi.h:226
bool amcanparallel
Definition: amapi.h:197
#define VACUUM_OPTION_NO_PARALLEL
Definition: vacuum.h:39
bool amsearchnulls
Definition: amapi.h:189
static bool diinsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, IndexInfo *indexInfo)
static void dicostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
bool amclusterable
Definition: amapi.h:193
bool amsearcharray
Definition: amapi.h:187
#define InvalidOid
Definition: postgres_ext.h:36
bool amusemaintenanceworkmem
Definition: amapi.h:201
#define makeNode(_type_)
Definition: nodes.h:573
ammarkpos_function ammarkpos
Definition: amapi.h:230
bool amcanorder
Definition: amapi.h:175
ambuildphasename_function ambuildphasename
Definition: amapi.h:223
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:234
uint16 amstrategies
Definition: amapi.h:171
ambuildempty_function ambuildempty
Definition: amapi.h:215
static bytea * dioptions(Datum reloptions, bool validate)
amcanreturn_function amcanreturn
Definition: amapi.h:219
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:235
static void dibuildempty(Relation index)
amrestrpos_function amrestrpos
Definition: amapi.h:231

◆ diinsert()

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

Definition at line 167 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ dioptions()

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

Definition at line 224 of file dummy_index_am.c.

References build_reloptions(), di_relopt_kind, and lengthof.

Referenced by dihandler().

225 {
226  return (bytea *) build_reloptions(reloptions, validate,
228  sizeof(DummyIndexOptions),
230 }
#define lengthof(array)
Definition: c.h:669
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:1552
relopt_kind di_relopt_kind
relopt_parse_elt di_relopt_tab[6]
Definition: c.h:556

◆ 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.

Referenced by dihandler().

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

◆ divacuumcleanup()

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

Definition at line 194 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ divalidate()

static bool divalidate ( Oid  opclassoid)
static

Definition at line 236 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( dihandler  )

◆ validate_string_option()

static void validate_string_option ( const char *  value)
static

Definition at line 65 of file dummy_index_am.c.

References ereport, errmsg(), and NOTICE.

Referenced by create_reloptions_table().

66 {
68  (errmsg("new option value for string parameter %s",
69  value ? value : "NULL")));
70 }
static struct @145 value
#define ereport(elevel, rest)
Definition: elog.h:141
#define NOTICE
Definition: elog.h:37
int errmsg(const char *fmt,...)
Definition: elog.c:822

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.

◆ dummyAmEnumValues

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

Definition at line 51 of file dummy_index_am.c.

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 24 of file dummy_index_am.c.