1996-07-09 02:22:35 -04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
1999-02-13 18:22:53 -05:00
|
|
|
* plancat.h
|
1996-07-09 02:22:35 -04:00
|
|
|
* prototypes for plancat.c.
|
|
|
|
|
*
|
|
|
|
|
*
|
2026-01-01 13:24:10 -05:00
|
|
|
* Portions Copyright (c) 1996-2026, 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/plancat.h
|
1996-07-09 02:22:35 -04:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#ifndef PLANCAT_H
|
|
|
|
|
#define PLANCAT_H
|
|
|
|
|
|
2019-01-29 16:49:25 -05:00
|
|
|
#include "nodes/pathnodes.h"
|
2008-06-18 20:46:06 -04:00
|
|
|
#include "utils/relcache.h"
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2007-05-25 13:54:25 -04:00
|
|
|
/* Hook for plugins to get control in get_relation_info() */
|
|
|
|
|
typedef void (*get_relation_info_hook_type) (PlannerInfo *root,
|
|
|
|
|
Oid relationObjectId,
|
|
|
|
|
bool inhparent,
|
|
|
|
|
RelOptInfo *rel);
|
2007-07-25 08:22:54 -04:00
|
|
|
extern PGDLLIMPORT get_relation_info_hook_type get_relation_info_hook;
|
2007-05-25 13:54:25 -04:00
|
|
|
|
1999-11-21 18:25:47 -05:00
|
|
|
|
2006-09-19 18:49:53 -04:00
|
|
|
extern void get_relation_info(PlannerInfo *root, Oid relationObjectId,
|
|
|
|
|
bool inhparent, RelOptInfo *rel);
|
1996-07-09 02:22:35 -04:00
|
|
|
|
Reduce "Var IS [NOT] NULL" quals during constant folding
In commit b262ad440, we introduced an optimization that reduces an IS
[NOT] NULL qual on a NOT NULL column to constant true or constant
false, provided we can prove that the input expression of the NullTest
is not nullable by any outer joins or grouping sets. This deduction
happens quite late in the planner, during the distribution of quals to
rels in query_planner. However, this approach has some drawbacks: we
can't perform any further folding with the constant, and it turns out
to be prone to bugs.
Ideally, this deduction should happen during constant folding.
However, the per-relation information about which columns are defined
as NOT NULL is not available at that point. This information is
currently collected from catalogs when building RelOptInfos for base
or "other" relations.
This patch moves the collection of NOT NULL attribute information for
relations before pull_up_sublinks, storing it in a hash table keyed by
relation OID. It then uses this information to perform the NullTest
deduction for Vars during constant folding. This also makes it
possible to leverage this information to pull up NOT IN subqueries.
Note that this patch does not get rid of restriction_is_always_true
and restriction_is_always_false. Removing them would prevent us from
reducing some IS [NOT] NULL quals that we were previously able to
reduce, because (a) the self-join elimination may introduce new IS NOT
NULL quals after constant folding, and (b) if some outer joins are
converted to inner joins, previously irreducible NullTest quals may
become reducible.
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAMbWs4-bFJ1At4btk5wqbezdu8PLtQ3zv-aiaY3ry9Ymm=jgFQ@mail.gmail.com
2025-07-21 22:21:36 -04:00
|
|
|
extern void get_relation_notnullatts(PlannerInfo *root, Relation relation);
|
|
|
|
|
|
2025-09-11 22:12:19 -04:00
|
|
|
extern Bitmapset *find_relation_notnullatts(PlannerInfo *root, Oid relid);
|
Reduce "Var IS [NOT] NULL" quals during constant folding
In commit b262ad440, we introduced an optimization that reduces an IS
[NOT] NULL qual on a NOT NULL column to constant true or constant
false, provided we can prove that the input expression of the NullTest
is not nullable by any outer joins or grouping sets. This deduction
happens quite late in the planner, during the distribution of quals to
rels in query_planner. However, this approach has some drawbacks: we
can't perform any further folding with the constant, and it turns out
to be prone to bugs.
Ideally, this deduction should happen during constant folding.
However, the per-relation information about which columns are defined
as NOT NULL is not available at that point. This information is
currently collected from catalogs when building RelOptInfos for base
or "other" relations.
This patch moves the collection of NOT NULL attribute information for
relations before pull_up_sublinks, storing it in a hash table keyed by
relation OID. It then uses this information to perform the NullTest
deduction for Vars during constant folding. This also makes it
possible to leverage this information to pull up NOT IN subqueries.
Note that this patch does not get rid of restriction_is_always_true
and restriction_is_always_false. Removing them would prevent us from
reducing some IS [NOT] NULL quals that we were previously able to
reduce, because (a) the self-join elimination may introduce new IS NOT
NULL quals after constant folding, and (b) if some outer joins are
converted to inner joins, previously irreducible NullTest quals may
become reducible.
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAMbWs4-bFJ1At4btk5wqbezdu8PLtQ3zv-aiaY3ry9Ymm=jgFQ@mail.gmail.com
2025-07-21 22:21:36 -04:00
|
|
|
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-07 23:31:36 -04:00
|
|
|
extern List *infer_arbiter_indexes(PlannerInfo *root);
|
|
|
|
|
|
2008-03-15 16:46:31 -04:00
|
|
|
extern void estimate_rel_size(Relation rel, int32 *attr_widths,
|
2011-10-14 17:23:01 -04:00
|
|
|
BlockNumber *pages, double *tuples, double *allvisfrac);
|
2008-03-15 16:46:31 -04:00
|
|
|
|
2019-03-30 19:40:33 -04:00
|
|
|
extern int32 get_rel_data_width(Relation rel, int32 *attr_widths);
|
2010-11-19 17:31:50 -05:00
|
|
|
extern int32 get_relation_data_width(Oid relid, int32 *attr_widths);
|
2010-10-07 20:00:28 -04:00
|
|
|
|
2008-03-31 20:48:33 -04:00
|
|
|
extern bool relation_excluded_by_constraints(PlannerInfo *root,
|
|
|
|
|
RelOptInfo *rel, RangeTblEntry *rte);
|
2005-07-23 17:05:48 -04:00
|
|
|
|
2005-06-05 18:32:58 -04:00
|
|
|
extern List *build_physical_tlist(PlannerInfo *root, RelOptInfo *rel);
|
2003-06-29 19:05:05 -04:00
|
|
|
|
2001-05-20 16:28:20 -04:00
|
|
|
extern bool has_unique_index(RelOptInfo *rel, AttrNumber attno);
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2005-06-05 18:32:58 -04:00
|
|
|
extern Selectivity restriction_selectivity(PlannerInfo *root,
|
2009-07-16 02:33:46 -04:00
|
|
|
Oid operatorid,
|
2001-05-20 16:28:20 -04:00
|
|
|
List *args,
|
2012-07-08 23:51:08 -04:00
|
|
|
Oid inputcollid,
|
2001-05-20 16:28:20 -04:00
|
|
|
int varRelid);
|
|
|
|
|
|
2005-06-05 18:32:58 -04:00
|
|
|
extern Selectivity join_selectivity(PlannerInfo *root,
|
2009-07-16 02:33:46 -04:00
|
|
|
Oid operatorid,
|
2003-01-28 17:13:41 -05:00
|
|
|
List *args,
|
2012-07-08 23:51:08 -04:00
|
|
|
Oid inputcollid,
|
2008-08-15 20:01:38 -04:00
|
|
|
JoinType jointype,
|
|
|
|
|
SpecialJoinInfo *sjinfo);
|
2001-10-28 01:26:15 -05:00
|
|
|
|
2019-02-09 18:32:23 -05:00
|
|
|
extern Selectivity function_selectivity(PlannerInfo *root,
|
|
|
|
|
Oid funcid,
|
|
|
|
|
List *args,
|
|
|
|
|
Oid inputcollid,
|
|
|
|
|
bool is_join,
|
|
|
|
|
int varRelid,
|
|
|
|
|
JoinType jointype,
|
|
|
|
|
SpecialJoinInfo *sjinfo);
|
|
|
|
|
|
|
|
|
|
extern void add_function_cost(PlannerInfo *root, Oid funcid, Node *node,
|
|
|
|
|
QualCost *cost);
|
|
|
|
|
|
|
|
|
|
extern double get_function_rows(PlannerInfo *root, Oid funcid, Node *node);
|
|
|
|
|
|
2016-03-18 13:48:58 -04:00
|
|
|
extern bool has_row_triggers(PlannerInfo *root, Index rti, CmdType event);
|
|
|
|
|
|
2025-08-07 21:50:00 -04:00
|
|
|
extern bool has_transition_tables(PlannerInfo *root, Index rti, CmdType event);
|
|
|
|
|
|
2019-03-30 03:13:09 -04:00
|
|
|
extern bool has_stored_generated_columns(PlannerInfo *root, Index rti);
|
|
|
|
|
|
2023-01-05 14:12:17 -05:00
|
|
|
extern Bitmapset *get_dependent_generated_columns(PlannerInfo *root, Index rti,
|
|
|
|
|
Bitmapset *target_cols);
|
|
|
|
|
|
1996-07-09 02:22:35 -04:00
|
|
|
#endif /* PLANCAT_H */
|