Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1e731ed

Browse files
committed
Fix incorrect row estimates used for Memoize costing
In order to estimate the cache hit ratio of a Memoize node, one of the inputs we require is the estimated number of times the Memoize node will be rescanned. The higher this number, the large the cache hit ratio is likely to become. Unfortunately, the value being passed as the number of "calls" to the Memoize was incorrectly using the Nested Loop's outer_path->parent->rows instead of outer_path->rows. This failed to account for the fact that the outer_path might be parameterized by some upper-level Nested Loop. This problem could lead to Memoize plans appearing more favorable than they might actually be. It could also lead to extended executor startup times when work_mem values were large due to the planner setting overly large MemoizePath->est_entries resulting in the Memoize hash table being initially made much larger than might be required. Fix this simply by passing outer_path->rows rather than outer_path->parent->rows. Also, adjust the expected regression test output for a plan change. Reported-by: Pavel Stehule Author: David Rowley Discussion: https://postgr.es/m/CAFj8pRAMp%3DQsMi6sPQJ4W3hczoFJRvyXHJV3AZAZaMyTVM312Q%40mail.gmail.com Backpatch-through: 14, where Memoize was introduced
1 parent 5bcc4d0 commit 1e731ed

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/backend/optimizer/path/joinpath.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ get_memoize_path(PlannerInfo *root, RelOptInfo *innerrel,
610610
hash_operators,
611611
extra->inner_unique,
612612
binary_mode,
613-
outer_path->parent->rows);
613+
outer_path->rows);
614614
}
615615

616616
return NULL;

src/test/regress/expected/join.out

+10-16
Original file line numberDiff line numberDiff line change
@@ -3673,8 +3673,8 @@ select * from tenk1 t1 left join
36733673
(tenk1 t2 join tenk1 t3 on t2.thousand = t3.unique2)
36743674
on t1.hundred = t2.hundred and t1.ten = t3.ten
36753675
where t1.unique1 = 1;
3676-
QUERY PLAN
3677-
--------------------------------------------------------------
3676+
QUERY PLAN
3677+
--------------------------------------------------------
36783678
Nested Loop Left Join
36793679
-> Index Scan using tenk1_unique1 on tenk1 t1
36803680
Index Cond: (unique1 = 1)
@@ -3684,20 +3684,17 @@ where t1.unique1 = 1;
36843684
Recheck Cond: (t1.hundred = hundred)
36853685
-> Bitmap Index Scan on tenk1_hundred
36863686
Index Cond: (hundred = t1.hundred)
3687-
-> Memoize
3688-
Cache Key: t2.thousand
3689-
Cache Mode: logical
3690-
-> Index Scan using tenk1_unique2 on tenk1 t3
3691-
Index Cond: (unique2 = t2.thousand)
3692-
(14 rows)
3687+
-> Index Scan using tenk1_unique2 on tenk1 t3
3688+
Index Cond: (unique2 = t2.thousand)
3689+
(11 rows)
36933690

36943691
explain (costs off)
36953692
select * from tenk1 t1 left join
36963693
(tenk1 t2 join tenk1 t3 on t2.thousand = t3.unique2)
36973694
on t1.hundred = t2.hundred and t1.ten + t2.ten = t3.ten
36983695
where t1.unique1 = 1;
3699-
QUERY PLAN
3700-
--------------------------------------------------------------
3696+
QUERY PLAN
3697+
--------------------------------------------------------
37013698
Nested Loop Left Join
37023699
-> Index Scan using tenk1_unique1 on tenk1 t1
37033700
Index Cond: (unique1 = 1)
@@ -3707,12 +3704,9 @@ where t1.unique1 = 1;
37073704
Recheck Cond: (t1.hundred = hundred)
37083705
-> Bitmap Index Scan on tenk1_hundred
37093706
Index Cond: (hundred = t1.hundred)
3710-
-> Memoize
3711-
Cache Key: t2.thousand
3712-
Cache Mode: logical
3713-
-> Index Scan using tenk1_unique2 on tenk1 t3
3714-
Index Cond: (unique2 = t2.thousand)
3715-
(14 rows)
3707+
-> Index Scan using tenk1_unique2 on tenk1 t3
3708+
Index Cond: (unique2 = t2.thousand)
3709+
(11 rows)
37163710

37173711
explain (costs off)
37183712
select count(*) from

0 commit comments

Comments
 (0)