Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf85232a

Browse files
committed
refactoring (move functions, renames and fixes), use bounds cache instead of constraints cache, introduce macro AssertTemporaryContext()
1 parent20fbd32 commitf85232a

File tree

8 files changed

+451
-319
lines changed

8 files changed

+451
-319
lines changed

‎src/hooks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,8 @@ pathman_relcache_hook(Datum arg, Oid relid)
624624
if (relid==get_pathman_config_relid(false))
625625
delay_pathman_shutdown();
626626

627-
/* InvalidatePartConstraintInfo cache if needed */
628-
forget_constraint_of_partition(relid);
627+
/* InvalidatePartBoundInfo cache if needed */
628+
forget_bounds_of_partition(relid);
629629

630630
/* Invalidate PartParentInfo cache if needed */
631631
partitioned_table=forget_parent_of_partition(relid,&search);

‎src/include/init.h

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,26 @@ typedef struct
3737
}PathmanInitState;
3838

3939

40+
/* Check that this is a temporary memory context that's going to be destroyed */
41+
#defineAssertTemporaryContext() \
42+
do { \
43+
Assert(CurrentMemoryContext != TopMemoryContext); \
44+
Assert(CurrentMemoryContext != TopPathmanContext); \
45+
Assert(CurrentMemoryContext != PathmanRelationCacheContext); \
46+
Assert(CurrentMemoryContext != PathmanParentCacheContext); \
47+
Assert(CurrentMemoryContext != PathmanBoundCacheContext); \
48+
} while (0)
49+
50+
4051
#definePATHMAN_MCXT_COUNT4
4152
externMemoryContextTopPathmanContext;
4253
externMemoryContextPathmanRelationCacheContext;
4354
externMemoryContextPathmanParentCacheContext;
44-
externMemoryContextPathmanCostraintCacheContext;
55+
externMemoryContextPathmanBoundCacheContext;
4556

4657
externHTAB*partitioned_rels;
4758
externHTAB*parent_cache;
48-
externHTAB*constraint_cache;
59+
externHTAB*bound_cache;
4960

5061
/* pg_pathman's initialization state */
5162
externPathmanInitStatepg_pathman_init_state;
@@ -55,10 +66,10 @@ extern PathmanInitState pg_pathman_init_state;
5566
staticinlineconstchar*
5667
simpify_mcxt_name(MemoryContextmcxt)
5768
{
58-
staticconstchar*top_mcxt="maintenance";
59-
staticconstchar*bound_mcxt="boundscache";
60-
staticconstchar*parent_mcxt="parentscache";
61-
staticconstchar*constr_mcxt="constraints cache";
69+
staticconstchar*top_mcxt="maintenance",
70+
*bound_mcxt="partition infocache",
71+
*parent_mcxt="parent mappingcache",
72+
*constr_mcxt="bounds cache";
6273

6374
if (mcxt==TopPathmanContext)
6475
returntop_mcxt;
@@ -69,7 +80,7 @@ simpify_mcxt_name(MemoryContext mcxt)
6980
elseif (mcxt==PathmanParentCacheContext)
7081
returnparent_mcxt;
7182

72-
elseif (mcxt==PathmanCostraintCacheContext)
83+
elseif (mcxt==PathmanBoundCacheContext)
7384
returnconstr_mcxt;
7485

7586
elseelog(ERROR,"error in function "CppAsString(simpify_mcxt_name));
@@ -166,11 +177,6 @@ bool load_config(void);
166177
voidunload_config(void);
167178

168179

169-
voidfill_prel_with_partitions(constOid*partitions,
170-
constuint32parts_count,
171-
constchar*part_column_name,
172-
PartRelationInfo*prel);
173-
174180
/* Result of find_inheritance_children_array() */
175181
typedefenum
176182
{
@@ -203,4 +209,16 @@ bool read_pathman_params(Oid relid,
203209
bool*isnull);
204210

205211

212+
boolvalidate_range_constraint(constExpr*expr,
213+
constPartRelationInfo*prel,
214+
constAttrNumberpart_attno,
215+
Datum*lower,Datum*upper,
216+
bool*lower_null,bool*upper_null);
217+
218+
boolvalidate_hash_constraint(constExpr*expr,
219+
constPartRelationInfo*prel,
220+
constAttrNumberpart_attno,
221+
uint32*part_hash);
222+
223+
206224
#endif/* PATHMAN_INIT_H */

‎src/include/relation_info.h

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ typedef struct
3737
#defineIsPlusInfinity(i)( (i)->is_infinite == PLUS_INFINITY )
3838
#defineIsMinusInfinity(i)( (i)->is_infinite == MINUS_INFINITY )
3939

40-
4140
staticinlineBound
4241
CopyBound(constBound*src,boolbyval,inttyplen)
4342
{
@@ -75,6 +74,13 @@ BoundGetValue(const Bound *bound)
7574
returnbound->value;
7675
}
7776

77+
staticinlinevoid
78+
FreeBound(Bound*bound,boolbyval)
79+
{
80+
if (!IsInfinite(bound)&& !byval)
81+
pfree(DatumGetPointer(BoundGetValue(bound)));
82+
}
83+
7884
staticinlineint
7985
cmp_bounds(FmgrInfo*cmp_func,constBound*b1,constBound*b2)
8086
{
@@ -97,7 +103,7 @@ cmp_bounds(FmgrInfo *cmp_func, const Bound *b1, const Bound *b2)
97103
*/
98104
typedefenum
99105
{
100-
PT_INDIFFERENT=0,/* for part type traits (virtual type) */
106+
PT_ANY=0,/* for part type traits (virtual type) */
101107
PT_HASH,
102108
PT_RANGE
103109
}PartType;
@@ -122,11 +128,14 @@ typedef struct
122128
boolvalid;/* is this entry valid? */
123129
boolenable_parent;/* include parent to the plan */
124130

131+
PartTypeparttype;/* partitioning type (HASH | RANGE) */
132+
125133
uint32children_count;
126134
Oid*children;/* Oids of child partitions */
127135
RangeEntry*ranges;/* per-partition range entry or NULL */
128136

129-
PartTypeparttype;/* partitioning type (HASH | RANGE) */
137+
constchar*attname;/* name of the partitioned column */
138+
130139
AttrNumberattnum;/* partitioned column's index */
131140
Oidatttype;/* partitioned column's type */
132141
int32atttypmod;/* partitioned column type modifier */
@@ -140,7 +149,7 @@ typedef struct
140149
}PartRelationInfo;
141150

142151
/*
143-
*RelParentInfo
152+
*PartParentInfo
144153
*Cached parent of the specified partition.
145154
*Allows us to quickly search for PartRelationInfo.
146155
*/
@@ -150,12 +159,24 @@ typedef struct
150159
Oidparent_rel;
151160
}PartParentInfo;
152161

162+
/*
163+
* PartBoundInfo
164+
*Cached bounds of the specified partition.
165+
*/
153166
typedefstruct
154167
{
155168
Oidchild_rel;/* key */
156-
Oidconid;
157-
Expr*constraint;
158-
}PartConstraintInfo;
169+
170+
PartTypeparttype;
171+
172+
/* For RANGE partitions */
173+
Boundrange_min;
174+
Boundrange_max;
175+
boolbyval;
176+
177+
/* For HASH partitions */
178+
uint32hash;
179+
}PartBoundInfo;
159180

160181
/*
161182
* PartParentSearch
@@ -220,38 +241,50 @@ void cache_parent_of_partition(Oid partition, Oid parent);
220241
Oidforget_parent_of_partition(Oidpartition,PartParentSearch*status);
221242
Oidget_parent_of_partition(Oidpartition,PartParentSearch*status);
222243

223-
/* Constraint cache */
224-
voidforget_constraint_of_partition(Oidpartition);
225-
Expr*get_constraint_of_partition(Oidpartition,AttrNumberpart_attno);
244+
/* Bounds cache */
245+
voidforget_bounds_of_partition(Oidpartition);
246+
PartBoundInfo*get_bounds_of_partition(Oidpartition,
247+
constPartRelationInfo*prel);
226248

227249
/* Safe casts for PartType */
228250
PartTypeDatumGetPartType(Datumdatum);
229251
char*PartTypeToCString(PartTypeparttype);
230252

231253
/* PartRelationInfo checker */
232-
voidshout_if_prel_is_invalid(Oidparent_oid,
254+
voidshout_if_prel_is_invalid(constOidparent_oid,
233255
constPartRelationInfo*prel,
234-
PartTypeexpected_part_type);
256+
constPartTypeexpected_part_type);
235257

236258

237259
/*
238-
* Usefulstaticfunctions for freeing memory.
260+
* Useful functions & macros for freeing memory.
239261
*/
240262

263+
#defineFreeIfNotNull(ptr) \
264+
do { \
265+
if (ptr) \
266+
{ \
267+
pfree((void *) ptr); \
268+
ptr = NULL; \
269+
} \
270+
} while(0)
271+
241272
staticinlinevoid
242273
FreeChildrenArray(PartRelationInfo*prel)
243274
{
244275
uint32i;
245276

246-
Assert(PrelIsValid(prel));
247-
248277
/* Remove relevant PartParentInfos */
249278
if (prel->children)
250279
{
251280
for (i=0;i<PrelChildrenCount(prel);i++)
252281
{
253282
Oidchild=prel->children[i];
254283

284+
/* Skip if Oid is invalid (e.g. initialization error) */
285+
if (!OidIsValid(child))
286+
continue;
287+
255288
/* If it's *always been* relid's partition, free cache */
256289
if (PrelParentRelid(prel)==get_parent_of_partition(child,NULL))
257290
forget_parent_of_partition(child,NULL);
@@ -267,8 +300,6 @@ FreeRangesArray(PartRelationInfo *prel)
267300
{
268301
uint32i;
269302

270-
Assert(PrelIsValid(prel));
271-
272303
/* Remove RangeEntries array */
273304
if (prel->ranges)
274305
{
@@ -277,11 +308,14 @@ FreeRangesArray(PartRelationInfo *prel)
277308
{
278309
for (i=0;i<PrelChildrenCount(prel);i++)
279310
{
280-
if (!IsInfinite(&prel->ranges[i].min))
281-
pfree(DatumGetPointer(BoundGetValue(&prel->ranges[i].min)));
311+
Oidchild=prel->ranges[i].child_oid;
282312

283-
if (!IsInfinite(&prel->ranges[i].max))
284-
pfree(DatumGetPointer(BoundGetValue(&prel->ranges[i].max)));
313+
/* Skip if Oid is invalid (e.g. initialization error) */
314+
if (!OidIsValid(child))
315+
continue;
316+
317+
FreeBound(&prel->ranges[i].min,prel->attbyval);
318+
FreeBound(&prel->ranges[i].max,prel->attbyval);
285319
}
286320
}
287321

@@ -290,5 +324,4 @@ FreeRangesArray(PartRelationInfo *prel)
290324
}
291325
}
292326

293-
294327
#endif/* RELATION_INFO_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp