PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 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 [8]
 
static relopt_kind di_relopt_kind
 
static relopt_enum_elt_def dummyAmEnumValues []
 

Typedef Documentation

◆ DummyAmEnum

◆ DummyIndexOptions

Enumeration Type Documentation

◆ DummyAmEnum

Enumerator
DUMMY_AM_ENUM_ONE 
DUMMY_AM_ENUM_TWO 

Definition at line 30 of file dummy_index_am.c.

31{
DummyAmEnum
@ DUMMY_AM_ENUM_ONE
@ DUMMY_AM_ENUM_TWO

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 350 of file dummy_index_am.c.

351{
353}
static void create_reloptions_table(void)

References create_reloptions_table().

◆ create_reloptions_table()

static void create_reloptions_table ( void  )
static

Definition at line 75 of file dummy_index_am.c.

76{
77 int i = 0;
78
80
82 "Integer option for dummy_index_am",
83 10, -10, 100, AccessExclusiveLock);
84 di_relopt_tab[i].optname = "option_int";
87 i++;
88
90 "Real option for dummy_index_am",
91 3.1415, -10, 100, AccessExclusiveLock);
92 di_relopt_tab[i].optname = "option_real";
95 i++;
96
98 "Boolean option for dummy_index_am",
100 di_relopt_tab[i].optname = "option_bool";
103 i++;
104
105 add_ternary_reloption(di_relopt_kind, "option_ternary_1",
106 "One ternary option for dummy_index_am",
108 di_relopt_tab[i].optname = "option_ternary_1";
110 di_relopt_tab[i].offset = offsetof(DummyIndexOptions, option_ternary_1);
111 i++;
112
113 add_enum_reloption(di_relopt_kind, "option_enum",
114 "Enum option for dummy_index_am",
117 "Valid values are \"one\" and \"two\".",
119 di_relopt_tab[i].optname = "option_enum";
122 i++;
123
124 add_string_reloption(di_relopt_kind, "option_string_val",
125 "String option for dummy_index_am with non-NULL default",
126 "DefaultValue", &validate_string_option,
128 di_relopt_tab[i].optname = "option_string_val";
131 option_string_val_offset);
132 i++;
133
134 /*
135 * String option for dummy_index_am with NULL default, and without
136 * description.
137 */
138 add_string_reloption(di_relopt_kind, "option_string_null",
139 NULL, /* description */
142 di_relopt_tab[i].optname = "option_string_null";
145 option_string_null_offset);
146 i++;
147}
static relopt_parse_elt di_relopt_tab[8]
static void validate_string_option(const char *value)
static relopt_enum_elt_def dummyAmEnumValues[]
static relopt_kind di_relopt_kind
int i
Definition isn.c:77
#define AccessExclusiveLock
Definition lockdefs.h:43
static int fb(int x)
void add_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
void add_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
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)
void add_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition reloptions.c:900
relopt_kind add_reloption_kind(void)
Definition reloptions.c:731
void add_ternary_reloption(bits32 kinds, const char *name, const char *desc, LOCKMODE lockmode)
Definition reloptions.c:947
@ RELOPT_TYPE_ENUM
Definition reloptions.h:35
@ RELOPT_TYPE_INT
Definition reloptions.h:33
@ RELOPT_TYPE_TERNARY
Definition reloptions.h:32
@ RELOPT_TYPE_BOOL
Definition reloptions.h:31
@ RELOPT_TYPE_REAL
Definition reloptions.h:34
@ RELOPT_TYPE_STRING
Definition reloptions.h:36
const char * optname
Definition reloptions.h:160
relopt_type opttype
Definition reloptions.h:161

References AccessExclusiveLock, add_bool_reloption(), add_enum_reloption(), add_int_reloption(), add_real_reloption(), add_reloption_kind(), add_string_reloption(), add_ternary_reloption(), di_relopt_kind, di_relopt_tab, DUMMY_AM_ENUM_ONE, dummyAmEnumValues, fb(), i, 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, RELOPT_TYPE_TERNARY, and validate_string_option().

Referenced by _PG_init().

◆ dibeginscan()

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

Definition at line 261 of file dummy_index_am.c.

262{
263 IndexScanDesc scan;
264
265 /* Let's pretend we are doing something */
266 scan = RelationGetIndexScan(r, nkeys, norderbys);
267 return scan;
268}
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 154 of file dummy_index_am.c.

155{
156 IndexBuildResult *result;
157
159
160 /* let's pretend that no tuples were scanned */
161 result->heap_tuples = 0;
162 /* and no index tuples were created (that is true) */
163 result->index_tuples = 0;
164
165 return result;
166}
#define palloc_object(type)
Definition fe_memutils.h:74
double heap_tuples
Definition genam.h:38
double index_tuples
Definition genam.h:39

References IndexBuildResult::heap_tuples, IndexBuildResult::index_tuples, and palloc_object.

Referenced by dihandler().

◆ dibuildempty()

static void dibuildempty ( Relation  index)
static

Definition at line 172 of file dummy_index_am.c.

173{
174 /* No need to build an init fork for a dummy index */
175}

Referenced by dihandler().

◆ dibulkdelete()

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

Definition at line 195 of file dummy_index_am.c.

197{
198 /*
199 * There is nothing to delete. Return NULL as there is nothing to pass to
200 * amvacuumcleanup.
201 */
202 return NULL;
203}

References fb().

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

223{
224 /* Tell planner to never use this index! */
225 *indexStartupCost = 1.0e10;
226 *indexTotalCost = 1.0e10;
227
228 /* Do not care about the rest */
229 *indexSelectivity = 1;
230 *indexCorrelation = 0;
231 *indexPages = 1;
232}

References fb().

Referenced by dihandler().

◆ diendscan()

static void diendscan ( IndexScanDesc  scan)
static

Definition at line 284 of file dummy_index_am.c.

285{
286 /* nothing to do */
287}

Referenced by dihandler().

◆ dihandler()

Datum dihandler ( PG_FUNCTION_ARGS  )

Definition at line 294 of file dummy_index_am.c.

295{
296 static const IndexAmRoutine amroutine = {
298 .amstrategies = 0,
299 .amsupport = 1,
300 .amcanorder = false,
301 .amcanorderbyop = false,
302 .amcanhash = false,
303 .amconsistentequality = false,
304 .amconsistentordering = false,
305 .amcanbackward = false,
306 .amcanunique = false,
307 .amcanmulticol = false,
308 .amoptionalkey = false,
309 .amsearcharray = false,
310 .amsearchnulls = false,
311 .amstorage = false,
312 .amclusterable = false,
313 .ampredlocks = false,
314 .amcanparallel = false,
315 .amcanbuildparallel = false,
316 .amcaninclude = false,
317 .amusemaintenanceworkmem = false,
318 .amsummarizing = false,
319 .amparallelvacuumoptions = VACUUM_OPTION_NO_PARALLEL,
320 .amkeytype = InvalidOid,
321
322 .ambuild = dibuild,
323 .ambuildempty = dibuildempty,
324 .aminsert = diinsert,
325 .ambulkdelete = dibulkdelete,
326 .amvacuumcleanup = divacuumcleanup,
327 .amcanreturn = NULL,
328 .amcostestimate = dicostestimate,
329 .amgettreeheight = NULL,
330 .amoptions = dioptions,
331 .amproperty = NULL,
332 .ambuildphasename = NULL,
333 .amvalidate = divalidate,
334 .ambeginscan = dibeginscan,
335 .amrescan = direscan,
336 .amgettuple = NULL,
337 .amgetbitmap = NULL,
338 .amendscan = diendscan,
339 .ammarkpos = NULL,
340 .amrestrpos = NULL,
341 .amestimateparallelscan = NULL,
342 .aminitparallelscan = NULL,
343 .amparallelrescan = NULL,
344 };
345
347}
static bool divalidate(Oid opclassoid)
static void diendscan(IndexScanDesc scan)
static void dibuildempty(Relation index)
static IndexBuildResult * dibuild(Relation heap, Relation index, IndexInfo *indexInfo)
static bytea * dioptions(Datum reloptions, bool validate)
static IndexBulkDeleteResult * dibulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
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 * 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:363
#define InvalidOid
NodeTag type
Definition amapi.h:234
#define VACUUM_OPTION_NO_PARALLEL
Definition vacuum.h:42

References dibeginscan(), dibuild(), dibuildempty(), dibulkdelete(), dicostestimate(), diendscan(), diinsert(), dioptions(), direscan(), divacuumcleanup(), divalidate(), fb(), InvalidOid, PG_RETURN_POINTER, IndexAmRoutine::type, 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 181 of file dummy_index_am.c.

186{
187 /* nothing to do */
188 return false;
189}

Referenced by dihandler().

◆ dioptions()

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

Definition at line 239 of file dummy_index_am.c.

240{
241 return (bytea *) build_reloptions(reloptions, validate,
243 sizeof(DummyIndexOptions),
245}
static bool validate(Port *port, const char *auth)
Definition auth-oauth.c:638
#define lengthof(array)
Definition c.h:803
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 c.h:706

References build_reloptions(), di_relopt_kind, di_relopt_tab, lengthof, and validate().

Referenced by dihandler().

◆ direscan()

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

Definition at line 274 of file dummy_index_am.c.

276{
277 /* nothing to do */
278}

Referenced by dihandler().

◆ divacuumcleanup()

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

Definition at line 209 of file dummy_index_am.c.

210{
211 /* Index has not been modified, so returning NULL is fine */
212 return NULL;
213}

References fb().

Referenced by dihandler().

◆ divalidate()

static bool divalidate ( Oid  opclassoid)
static

Definition at line 251 of file dummy_index_am.c.

252{
253 /* Index is dummy so we are happy with any opclass */
254 return true;
255}

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

64{
66 (errmsg("new option value for string parameter %s",
67 value ? value : "NULL")));
68}
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define NOTICE
Definition elog.h:35
#define ereport(elevel,...)
Definition elog.h:150
static struct @172 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 28 of file dummy_index_am.c.

Referenced by create_reloptions_table(), and dioptions().

◆ di_relopt_tab

relopt_parse_elt di_relopt_tab[8]
static

Definition at line 25 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 49 of file dummy_index_am.c.

50{
51 {"one", DUMMY_AM_ENUM_ONE},
52 {"two", DUMMY_AM_ENUM_TWO},
53 {(const char *) NULL} /* list terminator */
54};

Referenced by create_reloptions_table().

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 22 of file dummy_index_am.c.