1996-07-09 02:22:35 -04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
1999-02-13 18:22:53 -05:00
|
|
|
* prep.h
|
1999-09-12 14:08:17 -04:00
|
|
|
* prototypes for files in optimizer/prep/
|
1996-07-09 02:22:35 -04:00
|
|
|
*
|
|
|
|
|
*
|
2013-01-01 17:15:01 -05:00
|
|
|
* Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
|
2000-01-26 00:58:53 -05:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 02:22:35 -04:00
|
|
|
*
|
2010-09-20 16:08:53 -04:00
|
|
|
* src/include/optimizer/prep.h
|
1996-07-09 02:22:35 -04:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#ifndef PREP_H
|
1997-09-07 01:04:48 -04:00
|
|
|
#define PREP_H
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1999-07-16 13:07:40 -04:00
|
|
|
#include "nodes/plannodes.h"
|
2003-02-08 15:20:55 -05:00
|
|
|
#include "nodes/relation.h"
|
|
|
|
|
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2003-01-20 13:55:07 -05:00
|
|
|
/*
|
|
|
|
|
* prototypes for prepjointree.c
|
|
|
|
|
*/
|
2008-08-16 21:20:00 -04:00
|
|
|
extern void pull_up_sublinks(PlannerInfo *root);
|
2008-03-18 18:04:14 -04:00
|
|
|
extern void inline_set_returning_functions(PlannerInfo *root);
|
2012-08-12 16:01:26 -04:00
|
|
|
extern Node *pull_up_subqueries(PlannerInfo *root, Node *jtnode);
|
2010-11-08 15:15:02 -05:00
|
|
|
extern void flatten_simple_union_all(PlannerInfo *root);
|
2005-06-05 18:32:58 -04:00
|
|
|
extern void reduce_outer_joins(PlannerInfo *root);
|
2008-08-16 21:20:00 -04:00
|
|
|
extern Relids get_relids_in_jointree(Node *jtnode, bool include_joins);
|
2005-06-05 18:32:58 -04:00
|
|
|
extern Relids get_relids_for_join(PlannerInfo *root, int joinrelid);
|
2003-01-20 13:55:07 -05:00
|
|
|
|
1996-07-09 02:22:35 -04:00
|
|
|
/*
|
1999-06-06 13:38:11 -04:00
|
|
|
* prototypes for prepqual.c
|
1996-07-09 02:22:35 -04:00
|
|
|
*/
|
2010-10-10 23:19:50 -04:00
|
|
|
extern Node *negate_clause(Node *node);
|
2003-12-28 16:57:37 -05:00
|
|
|
extern Expr *canonicalize_qual(Expr *qual);
|
Fix improper uses of canonicalize_qual().
One of the things canonicalize_qual() does is to remove constant-NULL
subexpressions of top-level AND/OR clauses. It does that on the assumption
that what it's given is a top-level WHERE clause, so that NULL can be
treated like FALSE. Although this is documented down inside a subroutine
of canonicalize_qual(), it wasn't mentioned in the documentation of that
function itself, and some callers hadn't gotten that memo.
Notably, commit d007a9505 caused get_relation_constraints() to apply
canonicalize_qual() to CHECK constraints. That allowed constraint
exclusion to misoptimize situations in which a CHECK constraint had a
provably-NULL subclause, as seen in the regression test case added here,
in which a child table that should be scanned is not. (Although this
thinko is ancient, the test case doesn't fail before 9.2, for reasons
I've not bothered to track down in detail. There may be related cases
that do fail before that.)
More recently, commit f0e44751d added an independent bug by applying
canonicalize_qual() to index expressions, which is even sillier since
those might not even be boolean. If they are, though, I think this
could lead to making incorrect index entries for affected index
expressions in v10. I haven't attempted to prove that though.
To fix, add an "is_check" parameter to canonicalize_qual() to specify
whether it should assume WHERE or CHECK semantics, and make it perform
NULL-elimination accordingly. Adjust the callers to apply the right
semantics, or remove the call entirely in cases where it's not known
that the expression has one or the other semantics. I also removed
the call in some cases involving partition expressions, where it should
be a no-op because such expressions should be canonical already ...
and was a no-op, independently of whether it could in principle have
done something, because it was being handed the qual in implicit-AND
format which isn't what it expects. In HEAD, add an Assert to catch
that type of mistake in future.
This represents an API break for external callers of canonicalize_qual().
While that's intentional in HEAD to make such callers think about which
case applies to them, it seems like something we probably wouldn't be
thanked for in released branches. Hence, in released branches, the
extra parameter is added to a new function canonicalize_qual_ext(),
and canonicalize_qual() is a wrapper that retains its old behavior.
Patch by me with suggestions from Dean Rasheed. Back-patch to all
supported branches.
Discussion: https://postgr.es/m/24475.1520635069@sss.pgh.pa.us
2018-03-11 18:10:43 -04:00
|
|
|
extern Expr *canonicalize_qual_ext(Expr *qual, bool is_check);
|
1996-07-09 02:22:35 -04:00
|
|
|
|
|
|
|
|
/*
|
1999-06-06 13:38:11 -04:00
|
|
|
* prototypes for preptlist.c
|
1996-07-09 02:22:35 -04:00
|
|
|
*/
|
2005-06-05 18:32:58 -04:00
|
|
|
extern List *preprocess_targetlist(PlannerInfo *root, List *tlist);
|
1996-07-09 02:22:35 -04:00
|
|
|
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-25 22:26:45 -04:00
|
|
|
extern PlanRowMark *get_plan_rowmark(List *rowmarks, Index rtindex);
|
|
|
|
|
|
1999-06-06 13:38:11 -04:00
|
|
|
/*
|
|
|
|
|
* prototypes for prepunion.c
|
|
|
|
|
*/
|
2005-06-09 22:21:05 -04:00
|
|
|
extern Plan *plan_set_operations(PlannerInfo *root, double tuple_fraction,
|
2005-10-14 22:49:52 -04:00
|
|
|
List **sortClauses);
|
2000-11-11 19:37:02 -05:00
|
|
|
|
2006-01-31 16:39:25 -05:00
|
|
|
extern void expand_inherited_tables(PlannerInfo *root);
|
2000-11-11 19:37:02 -05:00
|
|
|
|
2012-02-14 17:34:19 -05:00
|
|
|
extern Node *adjust_appendrel_attrs(PlannerInfo *root, Node *node,
|
2012-06-10 15:20:04 -04:00
|
|
|
AppendRelInfo *appinfo);
|
2006-01-31 16:39:25 -05:00
|
|
|
|
Fix some more problems with nested append relations.
As of commit a87c72915 (which later got backpatched as far as 9.1),
we're explicitly supporting the notion that append relations can be
nested; this can occur when UNION ALL constructs are nested, or when
a UNION ALL contains a table with inheritance children.
Bug #11457 from Nelson Page, as well as an earlier report from Elvis
Pranskevichus, showed that there were still nasty bugs associated with such
cases: in particular the EquivalenceClass mechanism could try to generate
"join" clauses connecting an appendrel child to some grandparent appendrel,
which would result in assertion failures or bogus plans.
Upon investigation I concluded that all current callers of
find_childrel_appendrelinfo() need to be fixed to explicitly consider
multiple levels of parent appendrels. The most complex fix was in
processing of "broken" EquivalenceClasses, which are ECs for which we have
been unable to generate all the derived equality clauses we would like to
because of missing cross-type equality operators in the underlying btree
operator family. That code path is more or less entirely untested by
the regression tests to date, because no standard opfamilies have such
holes in them. So I wrote a new regression test script to try to exercise
it a bit, which turned out to be quite a worthwhile activity as it exposed
existing bugs in all supported branches.
The present patch is essentially the same as far back as 9.2, which is
where parameterized paths were introduced. In 9.0 and 9.1, we only need
to back-patch a small fragment of commit 5b7b5518d, which fixes failure to
propagate out the original WHERE clauses when a broken EC contains constant
members. (The regression test case results show that these older branches
are noticeably stupider than 9.2+ in terms of the quality of the plans
generated; but we don't really care about plan quality in such cases,
only that the plan not be outright wrong. A more invasive fix in the
older branches would not be a good idea anyway from a plan-stability
standpoint.)
2014-10-01 19:30:30 -04:00
|
|
|
extern Node *adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node,
|
|
|
|
|
RelOptInfo *child_rel);
|
|
|
|
|
|
2001-11-05 12:46:40 -05:00
|
|
|
#endif /* PREP_H */
|