pgsql: Allow planner to use expression-index stats for function calls i

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Allow planner to use expression-index stats for function calls i
Дата
Msg-id E1ZfF7T-0001d2-O7@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Allow planner to use expression-index stats for function calls in WHERE.

Previously, a function call appearing at the top level of WHERE had a
hard-wired selectivity estimate of 0.3333333, a kludge conveniently dated
in the source code itself to July 1992.  The expectation at the time was
that somebody would soon implement estimator support functions analogous
to those for operators; but no such code has appeared, nor does it seem
likely to in the near future.  We do have an alternative solution though,
at least for immutable functions on single relations: creating an
expression index on the function call will allow ANALYZE to gather stats
about the function's selectivity.  But the code in clause_selectivity()
failed to make use of such data even if it exists.

Refactor so that that will happen.  I chose to make it try this technique
for any clause type for which clause_selectivity() doesn't have a special
case, not just functions.  To avoid adding unnecessary overhead in the
common case where we don't learn anything new, make selfuncs.c provide an
API that hooks directly to examine_variable() and then var_eq_const(),
rather than the previous coding which laboriously constructed an OpExpr
only so that it could be expensively deconstructed again.

I preserved the behavior that the default estimate for a function call
is 0.3333333.  (For any other expression node type, it's 0.5, as before.)
I had originally thought to make the default be 0.5 across the board, but
changing a default estimate that's survived for twenty-three years seems
like something not to do without a lot more testing than I care to put
into it right now.

Per a complaint from Jehan-Guillaume de Rorthais.  Back-patch into 9.5,
but not further, at least for the moment.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/39df0f150ca69fac1c89537065ddc97af18921b8

Modified Files
--------------
src/backend/optimizer/path/clausesel.c |   45 +++++++++-----------------------
src/backend/utils/adt/selfuncs.c       |   45 ++++++++++++++++++++++++++++++++
src/include/utils/selfuncs.h           |    1 +
3 files changed, 59 insertions(+), 32 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Allow planner to use expression-index stats for function calls i
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix psql's code for locale-aware formatting of numeric output.