mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Fix a couple of planner bugs introduced by the new ability to discard
ORDER BY <constant> as redundant. One is that this means query_planner() has to canonicalize pathkeys even when the query jointree is empty; the canonicalization was always a no-op in such cases before, but no more. Also, we have to guard against thinking that a set-returning function is "constant" for this purpose. Add a couple of regression tests for these evidently under-tested cases. Per report from Greg Stark and subsequent experimentation.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.2 2007/01/22 20:00:39 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.3 2007/07/07 20:46:45 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -328,8 +328,8 @@ add_eq_member(EquivalenceClass *ec, Expr *expr, Relids relids,
|
||||
/*
|
||||
* No Vars, assume it's a pseudoconstant. This is correct for
|
||||
* entries generated from process_equivalence(), because a WHERE
|
||||
* clause can't contain aggregates and non-volatility was checked
|
||||
* before process_equivalence() ever got called. But
|
||||
* clause can't contain aggregates or SRFs, and non-volatility was
|
||||
* checked before process_equivalence() ever got called. But
|
||||
* get_eclass_for_sort_expr() has to work harder. We put the tests
|
||||
* there not here to save cycles in the equivalence case.
|
||||
*/
|
||||
@@ -428,13 +428,15 @@ get_eclass_for_sort_expr(PlannerInfo *root,
|
||||
false, expr_datatype);
|
||||
|
||||
/*
|
||||
* add_eq_member doesn't check for volatile functions or aggregates,
|
||||
* but such could appear in sort expressions, so we have to check
|
||||
* whether its const-marking was correct.
|
||||
* add_eq_member doesn't check for volatile functions, set-returning
|
||||
* functions, or aggregates, but such could appear in sort expressions;
|
||||
* so we have to check whether its const-marking was correct.
|
||||
*/
|
||||
if (newec->ec_has_const)
|
||||
{
|
||||
if (newec->ec_has_volatile || contain_agg_clause((Node *) expr))
|
||||
if (newec->ec_has_volatile ||
|
||||
expression_returns_set((Node *) expr) ||
|
||||
contain_agg_clause((Node *) expr))
|
||||
{
|
||||
newec->ec_has_const = false;
|
||||
newem->em_is_const = false;
|
||||
|
Reference in New Issue
Block a user