PostgreSQL Source Code git master
extendplan.c File Reference
#include "postgres.h"
#include "optimizer/extendplan.h"
#include "port/pg_bitutils.h"
#include "utils/memutils.h"
Include dependency graph for extendplan.c:

Go to the source code of this file.

Functions

int GetPlannerExtensionId (const char *extension_name)
 
void SetPlannerGlobalExtensionState (PlannerGlobal *glob, int extension_id, void *opaque)
 
void SetPlannerInfoExtensionState (PlannerInfo *root, int extension_id, void *opaque)
 
void SetRelOptInfoExtensionState (RelOptInfo *rel, int extension_id, void *opaque)
 

Variables

static const char ** PlannerExtensionNameArray = NULL
 
static int PlannerExtensionNamesAssigned = 0
 
static int PlannerExtensionNamesAllocated = 0
 

Function Documentation

◆ GetPlannerExtensionId()

int GetPlannerExtensionId ( const char *  extension_name)

Definition at line 41 of file extendplan.c.

42{
43 /* Search for an existing extension by this name; if found, return ID. */
44 for (int i = 0; i < PlannerExtensionNamesAssigned; ++i)
45 if (strcmp(PlannerExtensionNameArray[i], extension_name) == 0)
46 return i;
47
48 /* If there is no array yet, create one. */
49 if (PlannerExtensionNameArray == NULL)
50 {
52 PlannerExtensionNameArray = (const char **)
55 * sizeof(char *));
56 }
57
58 /* If there's an array but it's currently full, expand it. */
60 {
62
63 PlannerExtensionNameArray = (const char **)
64 repalloc(PlannerExtensionNameArray, i * sizeof(char *));
66 }
67
68 /* Assign and return new ID. */
71}
static const char ** PlannerExtensionNameArray
Definition: extendplan.c:28
static int PlannerExtensionNamesAssigned
Definition: extendplan.c:29
static int PlannerExtensionNamesAllocated
Definition: extendplan.c:30
int i
Definition: isn.c:77
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1229
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1610
MemoryContext TopMemoryContext
Definition: mcxt.c:166
static uint32 pg_nextpower2_32(uint32 num)
Definition: pg_bitutils.h:189

References i, MemoryContextAlloc(), pg_nextpower2_32(), PlannerExtensionNameArray, PlannerExtensionNamesAllocated, PlannerExtensionNamesAssigned, repalloc(), and TopMemoryContext.

Referenced by geqo().

◆ SetPlannerGlobalExtensionState()

void SetPlannerGlobalExtensionState ( PlannerGlobal glob,
int  extension_id,
void *  opaque 
)

Definition at line 77 of file extendplan.c.

79{
80 Assert(extension_id >= 0);
81
82 /* If there is no array yet, create one. */
83 if (glob->extension_state == NULL)
84 {
85 MemoryContext planner_cxt;
86 Size sz;
87
88 planner_cxt = GetMemoryChunkContext(glob);
90 Max(4, pg_nextpower2_32(extension_id + 1));
91 sz = glob->extension_state_allocated * sizeof(void *);
92 glob->extension_state = MemoryContextAllocZero(planner_cxt, sz);
93 }
94
95 /* If there's an array but it's currently full, expand it. */
96 if (extension_id >= glob->extension_state_allocated)
97 {
98 int i;
99
100 i = pg_nextpower2_32(extension_id + 1);
101 glob->extension_state = (void **)
102 repalloc0(glob->extension_state,
103 glob->extension_state_allocated * sizeof(void *),
104 i * sizeof(void *));
106 }
107
108 glob->extension_state[extension_id] = opaque;
109}
#define Max(x, y)
Definition: c.h:1000
size_t Size
Definition: c.h:613
Assert(PointerIsAligned(start, uint64))
void * repalloc0(void *pointer, Size oldsize, Size size)
Definition: mcxt.c:1682
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1263
MemoryContext GetMemoryChunkContext(void *pointer)
Definition: mcxt.c:753
int extension_state_allocated
Definition: pathnodes.h:191

References Assert(), PlannerGlobal::extension_state_allocated, GetMemoryChunkContext(), i, Max, MemoryContextAllocZero(), pg_nextpower2_32(), and repalloc0().

◆ SetPlannerInfoExtensionState()

void SetPlannerInfoExtensionState ( PlannerInfo root,
int  extension_id,
void *  opaque 
)

Definition at line 115 of file extendplan.c.

117{
118 Assert(extension_id >= 0);
119
120 /* If there is no array yet, create one. */
121 if (root->extension_state == NULL)
122 {
123 Size sz;
124
125 root->extension_state_allocated =
126 Max(4, pg_nextpower2_32(extension_id + 1));
127 sz = root->extension_state_allocated * sizeof(void *);
128 root->extension_state = MemoryContextAllocZero(root->planner_cxt, sz);
129 }
130
131 /* If there's an array but it's currently full, expand it. */
132 if (extension_id >= root->extension_state_allocated)
133 {
134 int i;
135
136 i = pg_nextpower2_32(extension_id + 1);
137 root->extension_state = (void **)
138 repalloc0(root->extension_state,
139 root->extension_state_allocated * sizeof(void *),
140 i * sizeof(void *));
141 root->extension_state_allocated = i;
142 }
143
144 root->extension_state[extension_id] = opaque;
145}
tree ctl root
Definition: radixtree.h:1857

References Assert(), i, Max, MemoryContextAllocZero(), pg_nextpower2_32(), repalloc0(), and root.

Referenced by geqo().

◆ SetRelOptInfoExtensionState()

void SetRelOptInfoExtensionState ( RelOptInfo rel,
int  extension_id,
void *  opaque 
)

Definition at line 151 of file extendplan.c.

153{
154 Assert(extension_id >= 0);
155
156 /* If there is no array yet, create one. */
157 if (rel->extension_state == NULL)
158 {
159 MemoryContext planner_cxt;
160 Size sz;
161
162 planner_cxt = GetMemoryChunkContext(rel);
164 Max(4, pg_nextpower2_32(extension_id + 1));
165 sz = rel->extension_state_allocated * sizeof(void *);
166 rel->extension_state = MemoryContextAllocZero(planner_cxt, sz);
167 }
168
169 /* If there's an array but it's currently full, expand it. */
170 if (extension_id >= rel->extension_state_allocated)
171 {
172 int i;
173
174 i = pg_nextpower2_32(extension_id + 1);
175 rel->extension_state = (void **)
176 repalloc0(rel->extension_state,
177 rel->extension_state_allocated * sizeof(void *),
178 i * sizeof(void *));
180 }
181
182 rel->extension_state[extension_id] = opaque;
183}
int extension_state_allocated
Definition: pathnodes.h:1124

References Assert(), RelOptInfo::extension_state_allocated, GetMemoryChunkContext(), i, Max, MemoryContextAllocZero(), pg_nextpower2_32(), and repalloc0().

Variable Documentation

◆ PlannerExtensionNameArray

const char** PlannerExtensionNameArray = NULL
static

Definition at line 28 of file extendplan.c.

Referenced by GetPlannerExtensionId().

◆ PlannerExtensionNamesAllocated

int PlannerExtensionNamesAllocated = 0
static

Definition at line 30 of file extendplan.c.

Referenced by GetPlannerExtensionId().

◆ PlannerExtensionNamesAssigned

int PlannerExtensionNamesAssigned = 0
static

Definition at line 29 of file extendplan.c.

Referenced by GetPlannerExtensionId().