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

Commitf1e59a1

Browse files
committed
initial commit (not done yet)
1 parent006850e commitf1e59a1

File tree

5 files changed

+459
-32
lines changed

5 files changed

+459
-32
lines changed

‎Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# contrib/pg_pathman/Makefile
22

33
MODULE_big = pg_pathman
4-
OBJS = init.o pg_pathman.o dsm_array.o rangeset.o pl_funcs.o worker.o$(WIN32RES)
4+
OBJS = init.opickyappend.opg_pathman.o dsm_array.o rangeset.o pl_funcs.o worker.o$(WIN32RES)
55

66
EXTENSION = pg_pathman
77
EXTVERSION = 0.1
@@ -36,4 +36,4 @@ isolationcheck: | submake-isolation
3636
$(pg_isolation_regress_check)\
3737
--temp-config=$(top_srcdir)/$(subdir)/conf.add\
3838
--outputdir=./isolation_output\
39-
$(ISOLATIONCHECKS)
39+
$(ISOLATIONCHECKS)

‎pathman.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include"nodes/pg_list.h"
1818
#include"storage/dsm.h"
1919
#include"storage/lwlock.h"
20+
#include"nodes/primnodes.h"
21+
#include"nodes/execnodes.h"
2022

2123
/* Check PostgreSQL version */
2224
#ifPG_VERSION_NUM<90500
@@ -191,4 +193,19 @@ FmgrInfo *get_cmp_func(Oid type1, Oid type2);
191193
Oidcreate_partitions_bg_worker(Oidrelid,Datumvalue,Oidvalue_type,bool*crashed);
192194
Oidcreate_partitions(Oidrelid,Datumvalue,Oidvalue_type,bool*crashed);
193195

196+
typedefstruct
197+
{
198+
constNode*orig;
199+
List*args;
200+
List*rangeset;
201+
}WrapperNode;
202+
203+
typedefstruct
204+
{
205+
PlanState*pstate;
206+
ExprContext*econtext;
207+
}WalkerContext;
208+
209+
WrapperNode*walk_expr_tree(WalkerContext*wcxt,Expr*expr,constPartRelationInfo*prel);
210+
194211
#endif/* PATHMAN_H */

‎pg_pathman.c

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include"nodes/nodeFuncs.h"
1616
#include"nodes/pg_list.h"
1717
#include"nodes/relation.h"
18+
#include"nodes/makefuncs.h"
1819
#include"nodes/primnodes.h"
1920
#include"optimizer/clauses.h"
2021
#include"optimizer/paths.h"
@@ -38,6 +39,7 @@
3839
#include"catalog/pg_operator.h"
3940
#include"catalog/pg_type.h"
4041
#include"foreign/fdwapi.h"
42+
#include"pickyappend.h"
4143

4244
PG_MODULE_MAGIC;
4345

@@ -47,13 +49,6 @@ typedef struct
4749
Oidnew_varno;
4850
}change_varno_context;
4951

50-
typedefstruct
51-
{
52-
constNode*orig;
53-
List*args;
54-
List*rangeset;
55-
}WrapperNode;
56-
5752
/* Original hooks */
5853
staticset_rel_pathlist_hook_typeset_rel_pathlist_hook_original=NULL;
5954
staticshmem_startup_hook_typeshmem_startup_hook_original=NULL;
@@ -79,12 +74,11 @@ static void disable_inheritance(Query *parse);
7974
boolinheritance_disabled;
8075

8176
/* Expression tree handlers */
82-
staticWrapperNode*walk_expr_tree(Expr*expr,constPartRelationInfo*prel);
8377
staticintmake_hash(constPartRelationInfo*prel,intvalue);
8478
staticvoidhandle_binary_opexpr(constPartRelationInfo*prel,WrapperNode*result,constVar*v,constConst*c);
85-
staticWrapperNode*handle_opexpr(constOpExpr*expr,constPartRelationInfo*prel);
86-
staticWrapperNode*handle_boolexpr(constBoolExpr*expr,constPartRelationInfo*prel);
87-
staticWrapperNode*handle_arrexpr(constScalarArrayOpExpr*expr,constPartRelationInfo*prel);
79+
staticWrapperNode*handle_opexpr(WalkerContext*wcxt,constOpExpr*expr,constPartRelationInfo*prel);
80+
staticWrapperNode*handle_boolexpr(WalkerContext*wcxt,constBoolExpr*expr,constPartRelationInfo*prel);
81+
staticWrapperNode*handle_arrexpr(WalkerContext*wcxt,constScalarArrayOpExpr*expr,constPartRelationInfo*prel);
8882
staticvoidchange_varnos_in_restrinct_info(RestrictInfo*rinfo,change_varno_context*context);
8983
staticvoidchange_varnos(Node*node,Oidold_varno,Oidnew_varno);
9084
staticboolchange_varno_walker(Node*node,change_varno_context*context);
@@ -113,6 +107,10 @@ static void set_pathkeys(PlannerInfo *root, RelOptInfo *childrel, Path *path);
113107
#definecheck_gt(flinfo,arg1,arg2) \
114108
((int) FunctionCall2(cmp_func, arg1, arg2) > 0)
115109

110+
#defineIsConstValue(node) \
111+
( IsA((node), Const) || IsA((node), Param) )
112+
#defineExtractConst(wcxt,node) \
113+
( IsA((node), Param) ? extract_const((wcxt), (Param *) (node)) : ((Const *) (node)) )
116114

117115
/*
118116
* Entry point
@@ -136,12 +134,29 @@ _PG_init(void)
136134

137135
set_rel_pathlist_hook_original=set_rel_pathlist_hook;
138136
set_rel_pathlist_hook=pathman_set_rel_pathlist_hook;
137+
set_join_pathlist_next=set_join_pathlist_hook;
138+
set_join_pathlist_hook=pathman_join_pathlist_hook;
139139
shmem_startup_hook_original=shmem_startup_hook;
140140
shmem_startup_hook=pathman_shmem_startup;
141141
post_parse_analyze_hook_original=post_parse_analyze_hook;
142142
post_parse_analyze_hook=pathman_post_parse_analysis_hook;
143143
planner_hook_original=planner_hook;
144144
planner_hook=pathman_planner_hook;
145+
146+
pickyappend_path_methods.CustomName="PickyAppend";
147+
pickyappend_path_methods.PlanCustomPath=create_pickyappend_plan;
148+
149+
pickyappend_plan_methods.CustomName="PickyAppend";
150+
pickyappend_plan_methods.CreateCustomScanState=pickyappend_create_scan_state;
151+
152+
pickyappend_exec_methods.CustomName="PickyAppend";
153+
pickyappend_exec_methods.BeginCustomScan=pickyappend_begin;
154+
pickyappend_exec_methods.ExecCustomScan=pickyappend_exec;
155+
pickyappend_exec_methods.EndCustomScan=pickyappend_end;
156+
pickyappend_exec_methods.ReScanCustomScan=pickyappend_rescan;
157+
pickyappend_exec_methods.MarkPosCustomScan=NULL;
158+
pickyappend_exec_methods.RestrPosCustomScan=NULL;
159+
pickyappend_exec_methods.ExplainCustomScan=pickyppend_explain;
145160
}
146161

147162
void
@@ -319,7 +334,7 @@ handle_modification_query(Query *parse)
319334

320335
/* Parse syntax tree and extract partition ranges */
321336
ranges=list_make1_int(make_irange(0,prel->children_count-1, false));
322-
wrap=walk_expr_tree((Expr*)eval_const_expressions(NULL,parse->jointree->quals),prel);
337+
wrap=walk_expr_tree(NULL,(Expr*)eval_const_expressions(NULL,parse->jointree->quals),prel);
323338
wrappers=lappend(wrappers,wrap);
324339
ranges=irange_list_intersect(ranges,wrap->rangeset);
325340

@@ -395,7 +410,7 @@ pathman_set_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, Ran
395410

396411
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
397412

398-
wrap=walk_expr_tree(rinfo->clause,prel);
413+
wrap=walk_expr_tree(NULL,rinfo->clause,prel);
399414
wrappers=lappend(wrappers,wrap);
400415
ranges=irange_list_intersect(ranges,wrap->rangeset);
401416
}
@@ -708,8 +723,8 @@ change_varnos_in_restrinct_info(RestrictInfo *rinfo, change_varno_context *conte
708723
/*
709724
* Recursive function to walk through conditions tree
710725
*/
711-
staticWrapperNode*
712-
walk_expr_tree(Expr*expr,constPartRelationInfo*prel)
726+
WrapperNode*
727+
walk_expr_tree(WalkerContext*wcxt,Expr*expr,constPartRelationInfo*prel)
713728
{
714729
BoolExpr*boolexpr;
715730
OpExpr*opexpr;
@@ -721,15 +736,15 @@ walk_expr_tree(Expr *expr, const PartRelationInfo *prel)
721736
/* AND, OR, NOT expressions */
722737
caseT_BoolExpr:
723738
boolexpr= (BoolExpr*)expr;
724-
returnhandle_boolexpr(boolexpr,prel);
739+
returnhandle_boolexpr(wcxt,boolexpr,prel);
725740
/* =, !=, <, > etc. */
726741
caseT_OpExpr:
727742
opexpr= (OpExpr*)expr;
728-
returnhandle_opexpr(opexpr,prel);
743+
returnhandle_opexpr(wcxt,opexpr,prel);
729744
/* IN expression */
730745
caseT_ScalarArrayOpExpr:
731746
arrexpr= (ScalarArrayOpExpr*)expr;
732-
returnhandle_arrexpr(arrexpr,prel);
747+
returnhandle_arrexpr(wcxt,arrexpr,prel);
733748
default:
734749
result= (WrapperNode*)palloc(sizeof(WrapperNode));
735750
result->orig= (constNode*)expr;
@@ -813,29 +828,29 @@ handle_binary_opexpr(const PartRelationInfo *prel, WrapperNode *result,
813828

814829
if ((cmp_min<0&&
815830
(strategy==BTLessEqualStrategyNumber||
816-
strategy==BTEqualStrategyNumber))||
831+
strategy==BTEqualStrategyNumber))||
817832
(cmp_min <=0&&strategy==BTLessStrategyNumber))
818833
{
819834
result->rangeset=NIL;
820835
return;
821836
}
822837

823-
if (cmp_max >=0&& (strategy==BTGreaterEqualStrategyNumber||
838+
if (cmp_max >=0&& (strategy==BTGreaterEqualStrategyNumber||
824839
strategy==BTGreaterStrategyNumber||
825840
strategy==BTEqualStrategyNumber))
826841
{
827842
result->rangeset=NIL;
828843
return;
829844
}
830845

831-
if ((cmp_min<0&&strategy==BTGreaterStrategyNumber)||
846+
if ((cmp_min<0&&strategy==BTGreaterStrategyNumber)||
832847
(cmp_min <=0&&strategy==BTGreaterEqualStrategyNumber))
833848
{
834849
result->rangeset=list_make1_irange(make_irange(startidx,endidx, false));
835850
return;
836851
}
837852

838-
if (cmp_max >=0&& (strategy==BTLessEqualStrategyNumber||
853+
if (cmp_max >=0&& (strategy==BTLessEqualStrategyNumber||
839854
strategy==BTLessStrategyNumber))
840855
{
841856
result->rangeset=list_make1_irange(make_irange(startidx,endidx, false));
@@ -1002,11 +1017,23 @@ range_binary_search(const RangeRelation *rangerel, FmgrInfo *cmp_func, Datum val
10021017
returni;
10031018
}
10041019

1020+
staticConst*
1021+
extract_const(WalkerContext*wcxt,Param*param)
1022+
{
1023+
ExprState*estate=ExecInitExpr((Expr*)param,NULL);
1024+
boolisnull;
1025+
Datumvalue=ExecEvalExpr(estate,wcxt->econtext,&isnull,NULL);
1026+
1027+
returnmakeConst(param->paramtype,param->paramtypmod,
1028+
param->paramcollid,get_typlen(param->paramtype),
1029+
value,isnull,get_typbyval(param->paramtype));
1030+
}
1031+
10051032
/*
10061033
* Operator expression handler
10071034
*/
10081035
staticWrapperNode*
1009-
handle_opexpr(constOpExpr*expr,constPartRelationInfo*prel)
1036+
handle_opexpr(WalkerContext*wcxt,constOpExpr*expr,constPartRelationInfo*prel)
10101037
{
10111038
WrapperNode*result= (WrapperNode*)palloc(sizeof(WrapperNode));
10121039
Node*firstarg=NULL,
@@ -1020,16 +1047,16 @@ handle_opexpr(const OpExpr *expr, const PartRelationInfo *prel)
10201047
firstarg= (Node*)linitial(expr->args);
10211048
secondarg= (Node*)lsecond(expr->args);
10221049

1023-
if (IsA(firstarg,Var)&&IsA(secondarg,Const)&&
1050+
if (IsA(firstarg,Var)&&IsConstValue(secondarg)&&
10241051
((Var*)firstarg)->varattno==prel->attnum)
10251052
{
1026-
handle_binary_opexpr(prel,result, (Var*)firstarg,(Const*)secondarg);
1053+
handle_binary_opexpr(prel,result, (Var*)firstarg,ExtractConst(wcxt,secondarg));
10271054
returnresult;
10281055
}
1029-
elseif (IsA(secondarg,Var)&&IsA(firstarg,Const)&&
1056+
elseif (IsA(secondarg,Var)&&IsConstValue(firstarg)&&
10301057
((Var*)secondarg)->varattno==prel->attnum)
10311058
{
1032-
handle_binary_opexpr(prel,result, (Var*)secondarg,(Const*)firstarg);
1059+
handle_binary_opexpr(prel,result, (Var*)secondarg,ExtractConst(wcxt,firstarg));
10331060
returnresult;
10341061
}
10351062
}
@@ -1042,7 +1069,7 @@ handle_opexpr(const OpExpr *expr, const PartRelationInfo *prel)
10421069
* Boolean expression handler
10431070
*/
10441071
staticWrapperNode*
1045-
handle_boolexpr(constBoolExpr*expr,constPartRelationInfo*prel)
1072+
handle_boolexpr(WalkerContext*wcxt,constBoolExpr*expr,constPartRelationInfo*prel)
10461073
{
10471074
WrapperNode*result= (WrapperNode*)palloc(sizeof(WrapperNode));
10481075
ListCell*lc;
@@ -1059,7 +1086,7 @@ handle_boolexpr(const BoolExpr *expr, const PartRelationInfo *prel)
10591086
{
10601087
WrapperNode*arg;
10611088

1062-
arg=walk_expr_tree((Expr*)lfirst(lc),prel);
1089+
arg=walk_expr_tree(wcxt,(Expr*)lfirst(lc),prel);
10631090
result->args=lappend(result->args,arg);
10641091
switch(expr->boolop)
10651092
{
@@ -1082,7 +1109,7 @@ handle_boolexpr(const BoolExpr *expr, const PartRelationInfo *prel)
10821109
* Scalar array expression
10831110
*/
10841111
staticWrapperNode*
1085-
handle_arrexpr(constScalarArrayOpExpr*expr,constPartRelationInfo*prel)
1112+
handle_arrexpr(WalkerContext*wcxt,constScalarArrayOpExpr*expr,constPartRelationInfo*prel)
10861113
{
10871114
WrapperNode*result= (WrapperNode*)palloc(sizeof(WrapperNode));
10881115
Node*varnode= (Node*)linitial(expr->args);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp