From ce74c6fc6d3886bfba15ff3fa4e083f85aab4e85 Mon Sep 17 00:00:00 2001 From: Alexandre Felipe Date: Thu, 16 Jul 2026 10:08:17 +0100 Subject: [PATCH-v10 6/8] SLOPE: documentation --- doc/src/sgml/config.sgml | 35 ++++++++++++++ doc/src/sgml/xfunc.sgml | 98 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 226e2d263e3..7520d7a7464 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -6176,6 +6176,41 @@ ANY num_sync ( + enable_slope (boolean) + + enable_slope configuration parameter + + + + + Enables or disable query planner's slope analysis. The slope analysis + gives the query executor the ability to use an index when the data + order is implied but not direct. Consider the following example + + +CREATE TABLE (created_at timestamp, ...); +CREATE INDEX ON orders(created_at); +SELECT created_at::date, count(1) +FROM orders GROUP BY 1 +ORDER BY 1 +LIMIT 5; + + + + The table has an index on created_at of + type timestamp. Grouping take advantage of the order on + timestamp, as a data series ordered by timestamp will cluster + all the rows per day in contiguous blocks. Without that knowledge + the entire table must be read. + + + + Default is on. + + + + enable_sort (boolean) diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 2b8a11e7ad0..90228ce100b 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -4134,10 +4134,10 @@ extern PgStat_Kind pgstat_register_kind(PgStat_Kind kind, Function Optimization Information - - optimization information - for functions - + + optimization information + for functions + By default, a function is just a black box that the @@ -4193,6 +4193,12 @@ supportfn(internal) returns internal so more things might be possible in future versions. + + Simplification + + optimization information + for simplification + Some function calls can be simplified during planning based on properties specific to the function. For example, @@ -4240,6 +4246,11 @@ supportfn(internal) returns internal function's responsibility that the replacement Query be equivalent to normal execution of the target function. + + + + + Selectivity For target functions that return boolean, it is often useful to estimate @@ -4247,21 +4258,42 @@ supportfn(internal) returns internal function. This can be done by a support function that implements the SupportRequestSelectivity request type. + + + Variable Cost + + optimization information + for functions with variable cost + If the target function's run time is highly dependent on its inputs, it may be useful to provide a non-constant cost estimate for it. This can be done by a support function that implements the SupportRequestCost request type. + + + Rows + + optimization information + for functions returning sets + For target functions that return sets, it is often useful to provide a non-constant estimate for the number of rows that will be returned. This can be done by a support function that implements the SupportRequestRows request type. + + + Index condition + + optimization information + for functions in index condition + For target functions that return boolean, it may be possible to convert a function call appearing in WHERE into an indexable operator @@ -4275,4 +4307,62 @@ supportfn(internal) returns internal To create such conditions, the support function must implement the SupportRequestIndexCondition request type. + + + + Monotonic functions + + optimization information + for monotonic functions + + + For target functions f(x) for which + f(x1) > f(x2, y2) and x1 > x2 are defined, + SupportRequestMonotonic can be used to specify how + the order of f(x) can be inferred from the order of + x. For function with multiple parameters it can + specify how the function varies with respect to any number of parameters. + The function can depending on each parameter: + + + + + MONOTONICFUNC_INCREASING: x1 > x2 + implies f(x1) >= f(x2) + + + + + MONOTONICFUNC_DECREASING: x1 > x2 + implies f(x1) >= f(x2) + + + + + MONOTONICFUNC_BOTH: both + MONOTONICFUNC_DECREASING and + MONOTONICFUNC_DECREASING, so + f(x1) = f(x2) for any valid + x1 and x1. + + + + + MONOTONICFUNC_BOTH: the order of f(x) + cannot be infeered from the order of x + + + + + A plan using a monotonic function on clauses such as + DISTINCT, + GROUP BY, ORDER BY, + PARTITION BY + can derive plans based on the order of one function argument + + + + See also . + + -- 2.53.0