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

Commit4a4cbbf

Browse files
committed
pathman: guc-variable (by Dmitry Ivanov) and some fixes
1 parentc6df8b2 commit4a4cbbf

File tree

4 files changed

+73
-61
lines changed

4 files changed

+73
-61
lines changed

‎contrib/pg_pathman/expected/pg_pathman.out

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -488,17 +488,17 @@ WHERE j1.dt < '2015-03-01' AND j2.dt >= '2015-02-01' ORDER BY j2.dt;
488488
-> Index Scan using num_range_rel_4_pkey on num_range_rel_4 j3_3
489489
-> Materialize
490490
-> Merge Join
491-
Merge Cond: (j1.id =j2.id)
491+
Merge Cond: (j2.id =j1.id)
492492
-> Merge Append
493-
Sort Key: j1.id
494-
-> Index Scan using range_rel_1_pkey on range_rel_1 j1
495-
-> Index Scan using range_rel_2_pkey on range_rel_2 j1_1
493+
Sort Key: j2.id
494+
-> Index Scan using range_rel_2_pkey on range_rel_2 j2
495+
-> Index Scan using range_rel_3_pkey on range_rel_3 j2_1
496+
-> Index Scan using range_rel_4_pkey on range_rel_4 j2_2
496497
-> Materialize
497498
-> Merge Append
498-
Sort Key: j2.id
499-
-> Index Scan using range_rel_2_pkey on range_rel_2 j2
500-
-> Index Scan using range_rel_3_pkey on range_rel_3 j2_1
501-
-> Index Scan using range_rel_4_pkey on range_rel_4 j2_2
499+
Sort Key: j1.id
500+
-> Index Scan using range_rel_1_pkey on range_rel_1 j1
501+
-> Index Scan using range_rel_2_pkey on range_rel_2 j1_1
502502
(22 rows)
503503

504504
SET enable_hashjoin = ON;
@@ -508,28 +508,28 @@ SELECT * FROM test.range_rel j1
508508
JOIN test.range_rel j2 on j2.id = j1.id
509509
JOIN test.num_range_rel j3 on j3.id = j1.id
510510
WHERE j1.dt < '2015-03-01' AND j2.dt >= '2015-02-01' ORDER BY j2.dt;
511-
QUERY PLAN
512-
---------------------------------------------------------------------------------------
511+
QUERY PLAN
512+
-------------------------------------------------------------------------------------------
513513
Sort
514514
Sort Key: j2.dt
515515
-> Hash Join
516-
Hash Cond: (j1.id = j2.id)
517-
-> Hash Join
518-
Hash Cond: (j3.id = j1.id)
519-
-> Append
520-
-> Index Scan using num_range_rel_1_pkey on num_range_rel_1 j3
521-
-> Index Scan using num_range_rel_2_pkey on num_range_rel_2 j3_1
522-
-> Index Scan using num_range_rel_3_pkey on num_range_rel_3 j3_2
523-
-> Index Scan using num_range_rel_4_pkey on num_range_rel_4 j3_3
524-
-> Hash
525-
-> Append
526-
-> Index Scan using range_rel_1_pkey on range_rel_1 j1
527-
-> Index Scan using range_rel_2_pkey on range_rel_2 j1_1
516+
Hash Cond: (j3.id = j2.id)
517+
-> Append
518+
-> Index Scan using num_range_rel_1_pkey on num_range_rel_1 j3
519+
-> Index Scan using num_range_rel_2_pkey on num_range_rel_2 j3_1
520+
-> Index Scan using num_range_rel_3_pkey on num_range_rel_3 j3_2
521+
-> Index Scan using num_range_rel_4_pkey on num_range_rel_4 j3_3
528522
-> Hash
529-
-> Append
530-
-> Index Scan using range_rel_2_dt_idx on range_rel_2 j2
531-
-> Index Scan using range_rel_3_dt_idx on range_rel_3 j2_1
532-
-> Index Scan using range_rel_4_dt_idx on range_rel_4 j2_2
523+
-> Hash Join
524+
Hash Cond: (j2.id = j1.id)
525+
-> Append
526+
-> Index Scan using range_rel_2_dt_idx on range_rel_2 j2
527+
-> Index Scan using range_rel_3_dt_idx on range_rel_3 j2_1
528+
-> Index Scan using range_rel_4_dt_idx on range_rel_4 j2_2
529+
-> Hash
530+
-> Append
531+
-> Index Scan using range_rel_1_pkey on range_rel_1 j1
532+
-> Index Scan using range_rel_2_pkey on range_rel_2 j1_1
533533
(20 rows)
534534

535535
/*

‎contrib/pg_pathman/hash.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ DECLARE
2121
v_typeTEXT;
2222
BEGIN
2323
relation := @extschema@.validate_relname(relation);
24+
attribute :=lower(attribute);
2425
PERFORM @extschema@.common_relation_checks(relation, attribute);
2526

2627
v_type := @extschema@.get_attribute_type_name(relation, attribute);

‎contrib/pg_pathman/pathman.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ typedef struct PathmanState
121121
DsmArraydatabases;
122122
}PathmanState;
123123

124-
PathmanState*pmstate;
124+
externboolpg_pathman_enable;
125+
externPathmanState*pmstate;
125126

126127
#definePATHMAN_GET_DATUM(value,by_val) ( (by_val) ? (value) : PointerGetDatum(&value) )
127128

‎contrib/pg_pathman/pg_pathman.c

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include"utils/date.h"
3434
#include"utils/typcache.h"
3535
#include"utils/lsyscache.h"
36+
#include"utils/guc.h"
3637
#include"access/heapam.h"
3738
#include"access/nbtree.h"
3839
#include"storage/ipc.h"
@@ -55,6 +56,9 @@ typedef struct
5556
List*rangeset;
5657
}WrapperNode;
5758

59+
boolpg_pathman_enable;
60+
PathmanState*pmstate;
61+
5862
/* Original hooks */
5963
staticset_rel_pathlist_hook_typeset_rel_pathlist_hook_original=NULL;
6064
staticshmem_startup_hook_typeshmem_startup_hook_original=NULL;
@@ -166,6 +170,17 @@ _PG_init(void)
166170
post_parse_analyze_hook=pathman_post_parse_analysis_hook;
167171
planner_hook_original=planner_hook;
168172
planner_hook=pathman_planner_hook;
173+
174+
DefineCustomBoolVariable("pg_pathman.enable",
175+
"Enables pg_pathman's optimizations during the planner stage",
176+
NULL,
177+
&pg_pathman_enable,
178+
true,
179+
PGC_USERSET,
180+
0,
181+
NULL,
182+
NULL,
183+
NULL);
169184
}
170185

171186
void
@@ -241,27 +256,30 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
241256
PlannedStmt*result;
242257
ListCell*lc;
243258

244-
inheritance_disabled= false;
245-
switch(parse->commandType)
259+
if (pg_pathman_enable)
246260
{
247-
caseCMD_SELECT:
248-
disable_inheritance(parse);
249-
break;
250-
caseCMD_UPDATE:
251-
caseCMD_DELETE:
252-
handle_modification_query(parse);
253-
break;
254-
default:
255-
break;
256-
}
261+
inheritance_disabled= false;
262+
switch(parse->commandType)
263+
{
264+
caseCMD_SELECT:
265+
disable_inheritance(parse);
266+
break;
267+
caseCMD_UPDATE:
268+
caseCMD_DELETE:
269+
handle_modification_query(parse);
270+
break;
271+
default:
272+
break;
273+
}
257274

258-
/* If query contains CTE (WITH statement) then handle subqueries too */
259-
foreach(lc,parse->cteList)
260-
{
261-
CommonTableExpr*cte= (CommonTableExpr*)lfirst(lc);
275+
/* If query contains CTE (WITH statement) then handle subqueries too */
276+
foreach(lc,parse->cteList)
277+
{
278+
CommonTableExpr*cte= (CommonTableExpr*)lfirst(lc);
262279

263-
if (IsA(cte->ctequery,Query))
264-
disable_inheritance((Query*)cte->ctequery);
280+
if (IsA(cte->ctequery,Query))
281+
disable_inheritance((Query*)cte->ctequery);
282+
}
265283
}
266284

267285
/* Invoke original hook */
@@ -325,8 +343,7 @@ static void
325343
handle_modification_query(Query*parse)
326344
{
327345
PartRelationInfo*prel;
328-
List*ranges,
329-
*wrappers=NIL;
346+
List*ranges;
330347
RangeTblEntry*rte;
331348
WrapperNode*wrap;
332349
Expr*expr;
@@ -350,7 +367,6 @@ handle_modification_query(Query *parse)
350367

351368
/* Parse syntax tree and extract partition ranges */
352369
wrap=walk_expr_tree(expr,prel);
353-
wrappers=lappend(wrappers,wrap);
354370
ranges=irange_list_intersect(ranges,wrap->rangeset);
355371

356372
/* If only one partition is affected then substitute parent table with partition */
@@ -398,6 +414,9 @@ pathman_set_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, Ran
398414
boolfound;
399415
intfirst_child_relid=0;
400416

417+
if (!pg_pathman_enable)
418+
return;
419+
401420
/* This works only for SELECT queries */
402421
if (root->parse->commandType!=CMD_SELECT|| !inheritance_disabled)
403422
return;
@@ -521,15 +540,6 @@ pathman_set_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, Ran
521540
/* Clear old path list */
522541
list_free(rel->pathlist);
523542

524-
/* Set apropriate varnos */
525-
if (first_child_relid)
526-
{
527-
change_varnos((Node*)root->canon_pathkeys,rti,first_child_relid);
528-
change_varnos((Node*)root->eq_classes,rti,first_child_relid);
529-
change_varnos((Node*)root->parse->targetList,rti,first_child_relid);
530-
change_varnos((Node*)rel->reltargetlist,rti,first_child_relid);
531-
}
532-
533543
rel->pathlist=NIL;
534544
set_append_rel_pathlist(root,rel,rti,rte,pathkeyAsc,pathkeyDesc);
535545
set_append_rel_size(root,rel,rti,rte);
@@ -1033,29 +1043,29 @@ handle_binary_opexpr(const PartRelationInfo *prel, WrapperNode *result,
10331043

10341044
if ((cmp_min<0&&
10351045
(strategy==BTLessEqualStrategyNumber||
1036-
strategy==BTEqualStrategyNumber))||
1046+
strategy==BTEqualStrategyNumber))||
10371047
(cmp_min <=0&&strategy==BTLessStrategyNumber))
10381048
{
10391049
result->rangeset=NIL;
10401050
return;
10411051
}
10421052

1043-
if (cmp_max >=0&& (strategy==BTGreaterEqualStrategyNumber||
1053+
if (cmp_max >=0&& (strategy==BTGreaterEqualStrategyNumber||
10441054
strategy==BTGreaterStrategyNumber||
10451055
strategy==BTEqualStrategyNumber))
10461056
{
10471057
result->rangeset=NIL;
10481058
return;
10491059
}
10501060

1051-
if ((cmp_min<0&&strategy==BTGreaterStrategyNumber)||
1061+
if ((cmp_min<0&&strategy==BTGreaterStrategyNumber)||
10521062
(cmp_min <=0&&strategy==BTGreaterEqualStrategyNumber))
10531063
{
10541064
result->rangeset=list_make1_irange(make_irange(startidx,endidx, false));
10551065
return;
10561066
}
10571067

1058-
if (cmp_max >=0&& (strategy==BTLessEqualStrategyNumber||
1068+
if (cmp_max >=0&& (strategy==BTLessEqualStrategyNumber||
10591069
strategy==BTLessStrategyNumber))
10601070
{
10611071
result->rangeset=list_make1_irange(make_irange(startidx,endidx, false));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp