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

Commitc79b3f7

Browse files
committed
introduce InitWalkerContextCustomNode macro, new comments
1 parentd42fd8f commitc79b3f7

File tree

7 files changed

+72
-48
lines changed

7 files changed

+72
-48
lines changed

‎src/nodes_common.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ end_append_common(CustomScanState *node)
481481
{
482482
RuntimeAppendState*scan_state= (RuntimeAppendState*)node;
483483

484+
clear_walker_context(&scan_state->wcxt);
484485
clear_plan_states(&scan_state->css);
485486
hash_destroy(scan_state->children_table);
486487
}
@@ -498,21 +499,8 @@ rescan_append_common(CustomScanState *node)
498499

499500
ranges=list_make1_irange(make_irange(0,prel->children_count-1, false));
500501

501-
/*
502-
* We'd like to persist RangeEntry array
503-
* in case of range partitioning, so 'wcxt'
504-
* is stored inside of RuntimeAppendState
505-
*/
506-
if (!scan_state->wcxt_cached)
507-
{
508-
scan_state->wcxt.prel=prel;
509-
scan_state->wcxt.econtext=econtext;
510-
scan_state->wcxt.ranges=NULL;
511-
512-
scan_state->wcxt_cached= true;
513-
}
514-
scan_state->wcxt.hasLeast= false;/* refresh runtime values */
515-
scan_state->wcxt.hasGreatest= false;
502+
InitWalkerContextCustomNode(&scan_state->wcxt,scan_state->prel,
503+
econtext,&scan_state->wcxt_cached);
516504

517505
foreach (lc,scan_state->custom_exprs)
518506
{

‎src/partition_filter.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,8 @@ partition_filter_exec(CustomScanState *node)
159159
CopyToTempConst(constlen,attlen);
160160
CopyToTempConst(constbyval,attbyval);
161161

162-
/*
163-
* We'd like to persist RangeEntry array
164-
* in case of range partitioning, so 'wcxt'
165-
* is stored inside of PartitionFilterState
166-
*/
167-
if (!state->wcxt_cached)
168-
{
169-
state->wcxt.prel=state->prel;
170-
state->wcxt.econtext=econtext;
171-
state->wcxt.ranges=NULL;
172-
173-
state->wcxt_cached= true;
174-
}
175-
state->wcxt.hasLeast= false;/* refresh runtime values */
176-
state->wcxt.hasGreatest= false;
162+
InitWalkerContextCustomNode(&state->wcxt,state->prel,
163+
econtext,&state->wcxt_cached);
177164

178165
ranges=walk_expr_tree((Expr*)&state->temp_const,&state->wcxt)->rangeset;
179166
parts=get_partition_oids(ranges,&nparts,state->prel);
@@ -215,11 +202,12 @@ partition_filter_end(CustomScanState *node)
215202
heap_close(rri_handle->resultRelInfo->ri_RelationDesc,
216203
RowExclusiveLock);
217204
}
218-
219205
hash_destroy(state->result_rels_table);
220206

221207
Assert(list_length(node->custom_ps)==1);
222208
ExecEndNode((PlanState*)linitial(node->custom_ps));
209+
210+
clear_walker_context(&state->wcxt);
223211
}
224212

225213
void

‎src/partition_filter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ typedef struct
2323
ResultRelInfo*savedRelInfo;
2424

2525
Plan*subplan;
26-
Consttemp_const;/* temporary const for expr walker */
26+
Consttemp_const;/* temporary const for expr walker */
2727

2828
HTAB*result_rels_table;
2929
HASHCTLresult_rels_table_config;
3030

3131
WalkerContextwcxt;
32-
boolwcxt_cached;
32+
boolwcxt_cached;/* does wcxt contain cached data,
33+
e.g. RangeEntry array? */
3334
}PartitionFilterState;
3435

3536

‎src/pathman.h

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ typedef struct PartRelationInfo
7878
PartTypeparttype;
7979
Indexattnum;
8080
Oidatttype;
81-
8281
}PartRelationInfo;
8382

8483
/*
@@ -256,12 +255,12 @@ typedef struct
256255
typedefstruct
257256
{
258257
/* Main partitioning structure */
259-
PartRelationInfo*prel;
258+
constPartRelationInfo*prel;
260259

261260
/* Cached values */
262-
RangeEntry*ranges;/*cached RangeEntry array */
263-
size_tnranges;
264-
ExprContext*econtext;
261+
constRangeEntry*ranges;/*cached RangeEntry array (copy) */
262+
size_tnranges;/* number of RangeEntries */
263+
ExprContext*econtext;/* for ExecEvalExpr() */
265264

266265
/* Runtime values */
267266
boolhasLeast,
@@ -270,6 +269,9 @@ typedef struct
270269
greatest;
271270
}WalkerContext;
272271

272+
/*
273+
* Usual initialization procedure for WalkerContext
274+
*/
273275
#defineInitWalkerContext(context,prel_info,ecxt) \
274276
do { \
275277
(context)->prel = (prel_info); \
@@ -279,6 +281,24 @@ typedef struct
279281
(context)->hasGreatest = false; \
280282
} while (0)
281283

284+
/*
285+
* We'd like to persist RangeEntry (ranges) array
286+
* in case of range partitioning, so 'wcxt' is stored
287+
* inside of Custom Node
288+
*/
289+
#defineInitWalkerContextCustomNode(context,prel_info,ecxt,isCached) \
290+
do { \
291+
if (!*isCached) \
292+
{ \
293+
(context)->prel = prel_info; \
294+
(context)->econtext = ecxt; \
295+
(context)->ranges = NULL; \
296+
*isCached = true; \
297+
} \
298+
(context)->hasLeast = false; \
299+
(context)->hasGreatest = false; \
300+
} while (0)
301+
282302
voidselect_range_partitions(constDatumvalue,
283303
constboolbyVal,
284304
FmgrInfo*cmp_func,

‎src/pg_pathman.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ handle_modification_query(Query *parse)
313313
InitWalkerContext(&context,prel,NULL);
314314
wrap=walk_expr_tree(expr,&context);
315315
finish_least_greatest(wrap,&context);
316+
clear_walker_context(&context);
316317

317318
ranges=irange_list_intersect(ranges,wrap->rangeset);
318319

@@ -710,6 +711,12 @@ change_varnos_in_restrinct_info(RestrictInfo *rinfo, change_varno_context *conte
710711
}
711712
}
712713

714+
/*
715+
* Refresh cached RangeEntry array within WalkerContext
716+
*
717+
* This is essential when we add new partitions
718+
* while executing INSERT query on partitioned table.
719+
*/
713720
void
714721
refresh_walker_context_ranges(WalkerContext*context)
715722
{
@@ -721,12 +728,15 @@ refresh_walker_context_ranges(WalkerContext *context)
721728
context->nranges=rangerel->ranges.elem_count;
722729
}
723730

731+
/*
732+
* Free all temporary data cached by WalkerContext
733+
*/
724734
void
725735
clear_walker_context(WalkerContext*context)
726736
{
727737
if (context->ranges)
728738
{
729-
pfree(context->ranges);
739+
pfree((void*)context->ranges);
730740
context->ranges=NULL;
731741
}
732742
}
@@ -1023,14 +1033,14 @@ static void
10231033
handle_binary_opexpr(WalkerContext*context,WrapperNode*result,
10241034
constVar*v,constConst*c)
10251035
{
1026-
HashRelationKeykey;
1027-
intint_value,
1028-
strategy;
1029-
FmgrInfocmp_func;
1030-
Oidcmp_proc_oid;
1031-
constOpExpr*expr= (constOpExpr*)result->orig;
1032-
TypeCacheEntry*tce;
1033-
PartRelationInfo*prel=context->prel;
1036+
HashRelationKeykey;
1037+
intint_value,
1038+
strategy;
1039+
TypeCacheEntry*tce;
1040+
FmgrInfocmp_func;
1041+
Oidcmp_proc_oid;
1042+
constOpExpr*expr= (constOpExpr*)result->orig;
1043+
constPartRelationInfo*prel=context->prel;
10341044

10351045
/* Determine operator type */
10361046
tce=lookup_type_cache(v->vartype,

‎src/pl_funcs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,3 @@ release_partitions_lock(PG_FUNCTION_ARGS)
381381
LWLockRelease(pmstate->edit_partitions_lock);
382382
PG_RETURN_NULL();
383383
}
384-

‎src/utils.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
staticboolclause_contains_params_walker(Node*node,void*context);
2323

24+
25+
/*
26+
* Check whether clause contains PARAMs or not
27+
*/
2428
bool
2529
clause_contains_params(Node*clause)
2630
{
@@ -59,6 +63,11 @@ bms_print(Bitmapset *bms)
5963
returnstr.data;
6064
}
6165

66+
/*
67+
* Copied from util/plancat.c
68+
*
69+
* Build a targetlist representing the columns of the specified index.
70+
*/
6271
List*
6372
build_index_tlist(PlannerInfo*root,IndexOptInfo*index,
6473
RelationheapRelation)
@@ -143,6 +152,12 @@ check_rinfo_for_partitioned_attr(List *rinfo, Index varno, AttrNumber varattno)
143152
return false;
144153
}
145154

155+
/*
156+
* Append trigger info contained in 'more' to 'src'.
157+
*
158+
* This allows us to execute some of main table's triggers on children.
159+
* See ExecInsert() for more details.
160+
*/
146161
TriggerDesc*
147162
append_trigger_descs(TriggerDesc*src,TriggerDesc*more,bool*grown_up)
148163
{
@@ -234,6 +249,9 @@ add_missing_partition(Oid partitioned_table, Const *value)
234249
returnresult;
235250
}
236251

252+
/*
253+
* Get BTORDER_PROC for two types described by Oids
254+
*/
237255
void
238256
fill_type_cmp_fmgr_info(FmgrInfo*finfo,Oidtype1,Oidtype2)
239257
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp