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

Commit91ab602

Browse files
committed
Bugfix. inherent number of rows from parallel path , not from RelOptInfo.
1 parent11be868 commit91ab602

File tree

3 files changed

+104
-13
lines changed

3 files changed

+104
-13
lines changed

‎contrib/tempscan/expected/basic.out

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,87 @@ SELECT count(*) FROM parallel_test;
3131
-- Should also utilise parallel workers like scanning of a plain table
3232
EXPLAIN (COSTS OFF)
3333
SELECT count(*) FROM parallel_test_tmp;
34-
QUERY PLAN
35-
----------------------------------------------------------
36-
Aggregate
34+
QUERY PLAN
35+
----------------------------------------------------------------
36+
FinalizeAggregate
3737
-> Gather
3838
Workers Planned: 1
39-
-> Custom Scan (nodeCustomTempScan)
40-
-> Parallel Seq Scan on parallel_test_tmp
41-
(5 rows)
39+
-> Partial Aggregate
40+
-> Custom Scan (nodeCustomTempScan)
41+
-> Parallel Seq Scan on parallel_test_tmp
42+
(6 rows)
43+
44+
-- Want to see here partial aggregate over parallel join
45+
EXPLAIN (COSTS OFF)
46+
SELECT count(*) FROM parallel_test t1 NATURAL JOIN parallel_test t2;
47+
QUERY PLAN
48+
---------------------------------------------------------------------
49+
Finalize Aggregate
50+
-> Gather
51+
Workers Planned: 1
52+
-> Partial Aggregate
53+
-> Parallel Hash Join
54+
Hash Cond: (t1.x = t2.x)
55+
-> Parallel Seq Scan on parallel_test t1
56+
-> Parallel Hash
57+
-> Parallel Seq Scan on parallel_test t2
58+
(9 rows)
59+
60+
EXPLAIN (COSTS OFF)
61+
SELECT count(*) FROM parallel_test_tmp t1 NATURAL JOIN parallel_test t2;
62+
QUERY PLAN
63+
-------------------------------------------------------------------------
64+
Finalize Aggregate
65+
-> Gather
66+
Workers Planned: 1
67+
-> Partial Aggregate
68+
-> Parallel Hash Join
69+
Hash Cond: (t1.x = t2.x)
70+
-> Custom Scan (nodeCustomTempScan)
71+
-> Parallel Seq Scan on parallel_test_tmp t1
72+
-> Parallel Hash
73+
-> Parallel Seq Scan on parallel_test t2
74+
(10 rows)
75+
76+
-- Just see how merge join manages custom parallel scan path
77+
SET enable_hashjoin = 'off';
78+
EXPLAIN (COSTS OFF)
79+
SELECT count(*) FROM parallel_test t1 NATURAL JOIN parallel_test t2;
80+
QUERY PLAN
81+
---------------------------------------------------------------------
82+
Finalize Aggregate
83+
-> Gather
84+
Workers Planned: 1
85+
-> Partial Aggregate
86+
-> Merge Join
87+
Merge Cond: (t1.x = t2.x)
88+
-> Sort
89+
Sort Key: t1.x
90+
-> Parallel Seq Scan on parallel_test t1
91+
-> Sort
92+
Sort Key: t2.x
93+
-> Seq Scan on parallel_test t2
94+
(12 rows)
95+
96+
EXPLAIN (COSTS OFF)
97+
SELECT count(*) FROM parallel_test_tmp t1 NATURAL JOIN parallel_test t2;
98+
QUERY PLAN
99+
-------------------------------------------------------------------------------
100+
Finalize Aggregate
101+
-> Gather
102+
Workers Planned: 1
103+
-> Partial Aggregate
104+
-> Merge Join
105+
Merge Cond: (t1.x = t2.x)
106+
-> Sort
107+
Sort Key: t1.x
108+
-> Custom Scan (nodeCustomTempScan)
109+
-> Parallel Seq Scan on parallel_test_tmp t1
110+
-> Sort
111+
Sort Key: t2.x
112+
-> Seq Scan on parallel_test t2
113+
(13 rows)
42114

115+
RESET enable_hashjoin;
43116
RESET tempscan.enable;
44117
DROP TABLE parallel_test, parallel_test_tmp;

‎contrib/tempscan/nodeCustomTempScan.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include"postgres.h"
1515

1616
#include"nodes/extensible.h"
17+
#include"optimizer/clauses.h"
1718
#include"optimizer/cost.h"
1819
#include"optimizer/pathnode.h"
1920
#include"optimizer/paths.h"
@@ -70,6 +71,7 @@ static CustomExecMethods exec_methods =
7071
};
7172

7273
staticset_rel_pathlist_hook_typeset_rel_pathlist_hook_next=NULL;
74+
7375
staticbooltempscan_enable= false;
7476

7577
void_PG_init(void);
@@ -90,7 +92,7 @@ create_partial_tempscan_path(PlannerInfo *root, RelOptInfo *rel,
9092
pathnode->pathtype=T_CustomScan;
9193
pathnode->parent=rel;
9294
pathnode->pathtarget=rel->reltarget;
93-
pathnode->rows=rel->rows;
95+
pathnode->rows=path->rows;/* Don't use rel->rows! Remember semantics of this field in the parallel case */
9496

9597
/* XXX: Just for now */
9698
pathnode->param_info=NULL;
@@ -100,8 +102,8 @@ create_partial_tempscan_path(PlannerInfo *root, RelOptInfo *rel,
100102
pathnode->parallel_workers=path->parallel_workers;
101103

102104
/* DEBUGGING purposes only */
103-
pathnode->startup_cost=path->startup_cost /disable_cost;
104-
pathnode->total_cost=path->total_cost /disable_cost;
105+
pathnode->startup_cost=path->startup_cost/*/ disable_cost*/;
106+
pathnode->total_cost=path->total_cost/*/ disable_cost*/;
105107

106108
cpath->custom_paths=list_make1(path);
107109
cpath->custom_private=NIL;
@@ -213,21 +215,25 @@ try_partial_tempscan(PlannerInfo *root, RelOptInfo *rel, Index rti,
213215
if (set_rel_pathlist_hook_next)
214216
(*set_rel_pathlist_hook_next)(root,rel,rti,rte);
215217

216-
if (rel->consider_parallel)
218+
if (!tempscan_enable||rel->consider_parallel)
217219
return;
218220

219221
if (rte->rtekind!=RTE_RELATION||
220222
get_rel_persistence(rte->relid)!=RELPERSISTENCE_TEMP)
221223
return;
222224

225+
/* HACK */
226+
if (!is_parallel_safe(root, (Node*)rel->baserestrictinfo)||
227+
!is_parallel_safe(root, (Node*)rel->reltarget->exprs))
228+
return;
229+
223230
parallel_workers=compute_parallel_worker(rel,rel->pages,-1,
224231
max_parallel_workers_per_gather);
225232

226233
/* If any limit was set to zero, the user doesn't want a parallel scan. */
227234
if (parallel_workers <=0)
228235
return;
229236

230-
/* HACK */
231237
rel->consider_parallel= true;
232238

233239
path=create_seqscan_path(root,rel,NULL,parallel_workers);
@@ -238,8 +244,6 @@ try_partial_tempscan(PlannerInfo *root, RelOptInfo *rel, Index rti,
238244
create_partial_tempscan_path(root,rel,path));
239245
}
240246

241-
if (!bms_equal(rel->relids,root->all_query_rels))
242-
rel->consider_parallel= false;
243247
Assert(IsA(linitial(rel->partial_pathlist),CustomPath));
244248
}
245249

‎contrib/tempscan/sql/basic.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,19 @@ SELECT count(*) FROM parallel_test;
2929
EXPLAIN (COSTS OFF)
3030
SELECTcount(*)FROM parallel_test_tmp;
3131

32+
-- Want to see here partial aggregate over parallel join
33+
EXPLAIN (COSTS OFF)
34+
SELECTcount(*)FROM parallel_test t1NATURAL JOIN parallel_test t2;
35+
EXPLAIN (COSTS OFF)
36+
SELECTcount(*)FROM parallel_test_tmp t1NATURAL JOIN parallel_test t2;
37+
38+
-- Just see how merge join manages custom parallel scan path
39+
SET enable_hashjoin='off';
40+
EXPLAIN (COSTS OFF)
41+
SELECTcount(*)FROM parallel_test t1NATURAL JOIN parallel_test t2;
42+
EXPLAIN (COSTS OFF)
43+
SELECTcount(*)FROM parallel_test_tmp t1NATURAL JOIN parallel_test t2;
44+
45+
RESET enable_hashjoin;
3246
RESETtempscan.enable;
3347
DROPTABLE parallel_test, parallel_test_tmp;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp