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

References create_reloptions_table().

330 {
332 }
static void create_reloptions_table(void)

◆ create_reloptions_table()

static void create_reloptions_table ( void  )
static

Definition at line 78 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().

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 }
relopt_type opttype
Definition: reloptions.h:153
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:877
relopt_enum_elt_def dummyAmEnumValues[]
const char * optname
Definition: reloptions.h:152
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:930
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:659
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:1074
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:994
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:825
#define offsetof(type, field)
Definition: c.h:661

◆ dibeginscan()

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

Definition at line 247 of file dummy_index_am.c.

References RelationGetIndexScan().

Referenced by dihandler().

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

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

Referenced by dihandler().

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

Referenced by dihandler().

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

◆ dibulkdelete()

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

Definition at line 181 of file dummy_index_am.c.

Referenced by dihandler().

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

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

Referenced by dihandler().

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

◆ diendscan()

static void diendscan ( IndexScanDesc  scan)
static

Definition at line 270 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ dihandler()

Datum dihandler ( PG_FUNCTION_ARGS  )

Definition at line 280 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.

281 {
282  IndexAmRoutine *amroutine = makeNode(IndexAmRoutine);
283 
284  amroutine->amstrategies = 0;
285  amroutine->amsupport = 1;
286  amroutine->amcanorder = false;
287  amroutine->amcanorderbyop = false;
288  amroutine->amcanbackward = false;
289  amroutine->amcanunique = false;
290  amroutine->amcanmulticol = false;
291  amroutine->amoptionalkey = false;
292  amroutine->amsearcharray = false;
293  amroutine->amsearchnulls = false;
294  amroutine->amstorage = false;
295  amroutine->amclusterable = false;
296  amroutine->ampredlocks = false;
297  amroutine->amcanparallel = false;
298  amroutine->amcaninclude = false;
299  amroutine->amusemaintenanceworkmem = false;
301  amroutine->amkeytype = InvalidOid;
302 
303  amroutine->ambuild = dibuild;
304  amroutine->ambuildempty = dibuildempty;
305  amroutine->aminsert = diinsert;
306  amroutine->ambulkdelete = dibulkdelete;
307  amroutine->amvacuumcleanup = divacuumcleanup;
308  amroutine->amcanreturn = NULL;
309  amroutine->amcostestimate = dicostestimate;
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 }
ambeginscan_function ambeginscan
Definition: amapi.h:227
uint8 amparallelvacuumoptions
Definition: amapi.h:205
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
ambulkdelete_function ambulkdelete
Definition: amapi.h:219
bool amcanmulticol
Definition: amapi.h:185
uint16 amsupport
Definition: amapi.h:173
amgettuple_function amgettuple
Definition: amapi.h:229
bool amcanorderbyop
Definition: amapi.h:179
amproperty_function amproperty
Definition: amapi.h:224
static IndexBuildResult * dibuild(Relation heap, Relation index, IndexInfo *indexInfo)
static IndexScanDesc dibeginscan(Relation r, int nkeys, int norderbys)
amparallelrescan_function amparallelrescan
Definition: amapi.h:238
bool amstorage
Definition: amapi.h:193
static IndexBulkDeleteResult * dibulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
bool ampredlocks
Definition: amapi.h:197
aminsert_function aminsert
Definition: amapi.h:218
Oid amkeytype
Definition: amapi.h:207
static IndexBulkDeleteResult * divacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
bool amoptionalkey
Definition: amapi.h:187
amvalidate_function amvalidate
Definition: amapi.h:226
static void diendscan(IndexScanDesc scan)
amgetbitmap_function amgetbitmap
Definition: amapi.h:230
static bool divalidate(Oid opclassoid)
ambuild_function ambuild
Definition: amapi.h:216
amoptions_function amoptions
Definition: amapi.h:223
bool amcaninclude
Definition: amapi.h:201
amcostestimate_function amcostestimate
Definition: amapi.h:222
bool amcanunique
Definition: amapi.h:183
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:220
amendscan_function amendscan
Definition: amapi.h:231
bool amcanbackward
Definition: amapi.h:181
static void direscan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
amrescan_function amrescan
Definition: amapi.h:228
bool amcanparallel
Definition: amapi.h:199
#define VACUUM_OPTION_NO_PARALLEL
Definition: vacuum.h:39
bool amsearchnulls
Definition: amapi.h:191
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:195
bool amsearcharray
Definition: amapi.h:189
#define InvalidOid
Definition: postgres_ext.h:36
bool amusemaintenanceworkmem
Definition: amapi.h:203
#define makeNode(_type_)
Definition: nodes.h:577
ammarkpos_function ammarkpos
Definition: amapi.h:232
bool amcanorder
Definition: amapi.h:177
ambuildphasename_function ambuildphasename
Definition: amapi.h:225
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:236
uint16 amstrategies
Definition: amapi.h:171
ambuildempty_function ambuildempty
Definition: amapi.h:217
static bytea * dioptions(Datum reloptions, bool validate)
amcanreturn_function amcanreturn
Definition: amapi.h:221
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:237
static void dibuildempty(Relation index)
amrestrpos_function amrestrpos
Definition: amapi.h:233

◆ diinsert()

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

Definition at line 168 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ dioptions()

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

Definition at line 225 of file dummy_index_am.c.

References build_reloptions(), di_relopt_kind, and lengthof.

Referenced by dihandler().

226 {
227  return (bytea *) build_reloptions(reloptions, validate,
229  sizeof(DummyIndexOptions),
231 }
#define lengthof(array)
Definition: c.h:668
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:1887
relopt_kind di_relopt_kind
relopt_parse_elt di_relopt_tab[6]
Definition: c.h:555

◆ direscan()

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

Definition at line 260 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ divacuumcleanup()

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

Definition at line 195 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ divalidate()

static bool divalidate ( Oid  opclassoid)
static

Definition at line 237 of file dummy_index_am.c.

Referenced by dihandler().

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

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

References ereport, errmsg(), and NOTICE.

Referenced by create_reloptions_table().

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

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

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 24 of file dummy_index_am.c.