mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
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
This commit is contained in:
@ -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
|
||||
{
|
||||
|
@ -3740,6 +3740,18 @@ static struct config_real ConfigureNamesReal[] =
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"recursive_worktable_factor", PGC_USERSET, QUERY_TUNING_OTHER,
|
||||
gettext_noop("Sets the planner's estimate of the average size "
|
||||
"of a recursive query's working table."),
|
||||
NULL,
|
||||
GUC_EXPLAIN
|
||||
},
|
||||
&recursive_worktable_factor,
|
||||
DEFAULT_RECURSIVE_WORKTABLE_FACTOR, 0.001, 1000000.0,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
|
||||
gettext_noop("GEQO: selective pressure within the population."),
|
||||
|
@ -426,6 +426,7 @@
|
||||
# JOIN clauses
|
||||
#plan_cache_mode = auto # auto, force_generic_plan or
|
||||
# force_custom_plan
|
||||
#recursive_worktable_factor = 10.0 # range 0.001-1000000
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
@ -29,6 +29,8 @@
|
||||
#define DEFAULT_PARALLEL_TUPLE_COST 0.1
|
||||
#define DEFAULT_PARALLEL_SETUP_COST 1000.0
|
||||
|
||||
/* defaults for non-Cost parameters */
|
||||
#define DEFAULT_RECURSIVE_WORKTABLE_FACTOR 10.0
|
||||
#define DEFAULT_EFFECTIVE_CACHE_SIZE 524288 /* measured in pages */
|
||||
|
||||
typedef enum
|
||||
|
@ -91,6 +91,7 @@ extern PGDLLIMPORT double cpu_index_tuple_cost;
|
||||
extern PGDLLIMPORT double cpu_operator_cost;
|
||||
extern PGDLLIMPORT double parallel_tuple_cost;
|
||||
extern PGDLLIMPORT double parallel_setup_cost;
|
||||
extern PGDLLIMPORT double recursive_worktable_factor;
|
||||
extern PGDLLIMPORT int effective_cache_size;
|
||||
|
||||
extern double clamp_row_est(double nrows);
|
||||
|
Reference in New Issue
Block a user