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

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 325 of file dummy_index_am.c.

References create_reloptions_table().

326 {
328 }
static void create_reloptions_table(void)

◆ create_reloptions_table()

static void create_reloptions_table ( void  )
static

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

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";
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";
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";
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";
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";
131  option_string_null_offset);
132 }
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:656

◆ dibeginscan()

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

Definition at line 245 of file dummy_index_am.c.

References RelationGetIndexScan().

Referenced by dihandler().

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

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

Referenced by dihandler().

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

Referenced by dihandler().

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

◆ dibulkdelete()

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

Definition at line 179 of file dummy_index_am.c.

Referenced by dihandler().

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

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

Referenced by dihandler().

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

◆ diendscan()

static void diendscan ( IndexScanDesc  scan)
static

Definition at line 268 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ dihandler()

Datum dihandler ( PG_FUNCTION_ARGS  )

Definition at line 278 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::ampredlocks, IndexAmRoutine::amproperty, IndexAmRoutine::amrescan, IndexAmRoutine::amrestrpos, IndexAmRoutine::amsearcharray, IndexAmRoutine::amsearchnulls, IndexAmRoutine::amstorage, IndexAmRoutine::amstrategies, IndexAmRoutine::amsupport, IndexAmRoutine::amvacuumcleanup, IndexAmRoutine::amvalidate, dibeginscan(), dibuild(), dibuildempty(), dibulkdelete(), dicostestimate(), diendscan(), diinsert(), dioptions(), direscan(), divacuumcleanup(), divalidate(), InvalidOid, makeNode, and PG_RETURN_POINTER.

279 {
280  IndexAmRoutine *amroutine = makeNode(IndexAmRoutine);
281 
282  amroutine->amstrategies = 0;
283  amroutine->amsupport = 1;
284  amroutine->amcanorder = false;
285  amroutine->amcanorderbyop = false;
286  amroutine->amcanbackward = false;
287  amroutine->amcanunique = false;
288  amroutine->amcanmulticol = false;
289  amroutine->amoptionalkey = false;
290  amroutine->amsearcharray = false;
291  amroutine->amsearchnulls = false;
292  amroutine->amstorage = false;
293  amroutine->amclusterable = false;
294  amroutine->ampredlocks = false;
295  amroutine->amcanparallel = false;
296  amroutine->amcaninclude = false;
297  amroutine->amkeytype = InvalidOid;
298 
299  amroutine->ambuild = dibuild;
300  amroutine->ambuildempty = dibuildempty;
301  amroutine->aminsert = diinsert;
302  amroutine->ambulkdelete = dibulkdelete;
303  amroutine->amvacuumcleanup = divacuumcleanup;
304  amroutine->amcanreturn = NULL;
305  amroutine->amcostestimate = dicostestimate;
306  amroutine->amoptions = dioptions;
307  amroutine->amproperty = NULL;
308  amroutine->ambuildphasename = NULL;
309  amroutine->amvalidate = divalidate;
310  amroutine->ambeginscan = dibeginscan;
311  amroutine->amrescan = direscan;
312  amroutine->amgettuple = NULL;
313  amroutine->amgetbitmap = NULL;
314  amroutine->amendscan = diendscan;
315  amroutine->ammarkpos = NULL;
316  amroutine->amrestrpos = NULL;
317  amroutine->amestimateparallelscan = NULL;
318  amroutine->aminitparallelscan = NULL;
319  amroutine->amparallelrescan = NULL;
320 
321  PG_RETURN_POINTER(amroutine);
322 }
ambeginscan_function ambeginscan
Definition: amapi.h:221
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
ambulkdelete_function ambulkdelete
Definition: amapi.h:213
bool amcanmulticol
Definition: amapi.h:183
uint16 amsupport
Definition: amapi.h:173
amgettuple_function amgettuple
Definition: amapi.h:223
bool amcanorderbyop
Definition: amapi.h:177
amproperty_function amproperty
Definition: amapi.h:218
static IndexBuildResult * dibuild(Relation heap, Relation index, IndexInfo *indexInfo)
static IndexScanDesc dibeginscan(Relation r, int nkeys, int norderbys)
amparallelrescan_function amparallelrescan
Definition: amapi.h:232
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:212
Oid amkeytype
Definition: amapi.h:201
static IndexBulkDeleteResult * divacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
bool amoptionalkey
Definition: amapi.h:185
amvalidate_function amvalidate
Definition: amapi.h:220
static void diendscan(IndexScanDesc scan)
amgetbitmap_function amgetbitmap
Definition: amapi.h:224
static bool divalidate(Oid opclassoid)
ambuild_function ambuild
Definition: amapi.h:210
amoptions_function amoptions
Definition: amapi.h:217
bool amcaninclude
Definition: amapi.h:199
amcostestimate_function amcostestimate
Definition: amapi.h:216
bool amcanunique
Definition: amapi.h:181
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:214
amendscan_function amendscan
Definition: amapi.h:225
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:222
bool amcanparallel
Definition: amapi.h:197
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
#define makeNode(_type_)
Definition: nodes.h:573
ammarkpos_function ammarkpos
Definition: amapi.h:226
bool amcanorder
Definition: amapi.h:175
ambuildphasename_function ambuildphasename
Definition: amapi.h:219
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:230
uint16 amstrategies
Definition: amapi.h:171
ambuildempty_function ambuildempty
Definition: amapi.h:211
static bytea * dioptions(Datum reloptions, bool validate)
amcanreturn_function amcanreturn
Definition: amapi.h:215
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:231
static void dibuildempty(Relation index)
amrestrpos_function amrestrpos
Definition: amapi.h:227

◆ diinsert()

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

Definition at line 166 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ dioptions()

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

Definition at line 223 of file dummy_index_am.c.

References build_reloptions(), di_relopt_kind, and lengthof.

Referenced by dihandler().

224 {
225  return (bytea *) build_reloptions(reloptions, validate,
227  sizeof(DummyIndexOptions),
229 }
#define lengthof(array)
Definition: c.h:663
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:1554
relopt_kind di_relopt_kind
relopt_parse_elt di_relopt_tab[6]
Definition: c.h:550

◆ direscan()

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

Definition at line 258 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ divacuumcleanup()

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

Definition at line 193 of file dummy_index_am.c.

Referenced by dihandler().

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

◆ divalidate()

static bool divalidate ( Oid  opclassoid)
static

Definition at line 235 of file dummy_index_am.c.

Referenced by dihandler().

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

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

References ereport, errmsg(), and NOTICE.

Referenced by create_reloptions_table().

65 {
67  (errmsg("new option value for string parameter %s",
68  value ? value : "NULL")));
69 }
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 31 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 28 of file dummy_index_am.c.

◆ dummyAmEnumValues

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

Definition at line 50 of file dummy_index_am.c.

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 23 of file dummy_index_am.c.