diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-03-24 11:47:41 -0400 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-03-24 11:47:41 -0400 |
| commit | 0bd7af082ace135581bb13a6bd2d88e68c66a3e0 (patch) | |
| tree | 412ad873ef762b761baaab0577cb4d36b6c0a240 /src/backend/optimizer/path | |
| parent | a47651447f01562dac2e007db03733e750d45b6b (diff) | |
Invent recursive_worktable_factor GUC to replace hard-wired constant.
Up to now, the planner estimated the size of a recursive query's
worktable as 10 times the size of the non-recursive term. It's hard
to see how to do significantly better than that automatically, but
we can give users control over the multiplier to allow tuning for
specific use-cases. The default behavior remains the same.
Simon Riggs
Discussion: https://postgr.es/m/CANbhV-EuaLm4H3g0+BSTYHEGxJj3Kht0R+rJ8vT57Dejnh=_nA@mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/path')
| -rw-r--r-- | src/backend/optimizer/path/costsize.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 4d9f3b4bb6b..1b07ea392d9 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -123,6 +123,7 @@ double cpu_index_tuple_cost = DEFAULT_CPU_INDEX_TUPLE_COST; double cpu_operator_cost = DEFAULT_CPU_OPERATOR_COST; double parallel_tuple_cost = DEFAULT_PARALLEL_TUPLE_COST; double parallel_setup_cost = DEFAULT_PARALLEL_SETUP_COST; +double recursive_worktable_factor = DEFAULT_RECURSIVE_WORKTABLE_FACTOR; int effective_cache_size = DEFAULT_EFFECTIVE_CACHE_SIZE; @@ -5665,10 +5666,11 @@ set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows) if (rte->self_reference) { /* - * In a self-reference, arbitrarily assume the average worktable size - * is about 10 times the nonrecursive term's size. + * In a self-reference, we assume the average worktable size is a + * multiple of the nonrecursive term's size. The best multiplier will + * vary depending on query "fan-out", so make its value adjustable. */ - rel->tuples = 10 * cte_rows; + rel->tuples = clamp_row_est(recursive_worktable_factor * cte_rows); } else { |
