clauses.h 4.5 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * clauses.h
4
 *	  prototypes for clauses.c.
5 6
 *
 *
B
Bruce Momjian 已提交
7
 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * src/include/optimizer/clauses.h
11 12 13 14 15 16
 *
 *-------------------------------------------------------------------------
 */
#ifndef CLAUSES_H
#define CLAUSES_H

17
#include "nodes/relation.h"
18
#include "optimizer/walkers.h"
19

20

21 22 23
#define is_opclause(clause)		((clause) != NULL && IsA(clause, OpExpr))
#define is_funcclause(clause)	((clause) != NULL && IsA(clause, FuncExpr))

24

25 26 27 28 29
// max size of a folded constant when optimizing queries in Orca
// Note: this is to prevent OOM issues when trying to serialize very large constants
// Current limit: 100KB
#define GPOPT_MAX_FOLDED_CONSTANT_SIZE (100*1024)

30 31
typedef struct
{
32 33 34 35 36 37 38
	bool		hasOrderedAggs;	/* any ordered aggs? */
	int			numWindowFuncs; /* total number of WindowFuncs found */
	Index		maxWinRef;		/* windowFuncs[] is indexed 0 .. maxWinRef */
	List	  **windowFuncs;	/* lists of WindowFuncs for each winref */
} WindowFuncLists;


39 40 41 42 43 44 45 46 47 48 49 50
/*
 * Representing a canonicalized grouping sets.
 */
typedef struct CanonicalGroupingSets
{
	int num_distcols;   /* number of distinct grouping columns */
	int ngrpsets;   /* number of grouping sets */
	Bitmapset **grpsets;  /* one Bitmapset for each grouping set */
	int *grpset_counts;  /* one for each grouping set, representing the number of times that
						  * each grouping set appears
						  */
} CanonicalGroupingSets;
51 52

extern Expr *make_opclause(Oid opno, Oid opresulttype, bool opretset,
53 54
			  Expr *leftop, Expr *rightop,
			  Oid opcollid, Oid inputcollid);
55 56
extern Node *get_leftop(const Expr *clause);
extern Node *get_rightop(const Expr *clause);
57 58
extern Node *get_leftscalararrayop(const Expr *clause);
extern Node *get_rightscalararrayop(const Expr *clause);
59 60 61 62 63

extern bool not_clause(Node *clause);
extern Expr *make_notclause(Expr *notclause);
extern Expr *get_notclausearg(Expr *notclause);

64 65 66
extern bool or_clause(Node *clause);
extern Expr *make_orclause(List *orclauses);

67 68
extern bool and_clause(Node *clause);
extern Expr *make_andclause(List *andclauses);
69
extern Node *make_and_qual(Node *qual1, Node *qual2);
70
extern Expr *make_ands_explicit(List *andclauses);
71
extern List *make_ands_implicit(Expr *clause);
72

73
extern bool contain_agg_clause(Node *clause);
74
extern void count_agg_clauses(PlannerInfo *root, Node *clause,
B
Bruce Momjian 已提交
75
				  AggClauseCosts *costs);
76

77
extern bool contain_window_function(Node *clause);
78
extern WindowFuncLists *find_window_functions(Node *clause, Index maxWinRef);
79

80
extern double expression_returns_set_rows(Node *clause);
81
extern double tlist_returns_set_rows(List *tlist);
82

83
extern bool contain_subplans(Node *clause);
84

85 86
extern bool contain_mutable_functions(Node *clause);
extern bool contain_volatile_functions(Node *clause);
87
extern bool contain_nonstrict_functions(Node *clause);
88 89
extern bool contain_leaky_functions(Node *clause);

90
extern Relids find_nonnullable_rels(Node *clause);
91 92 93
extern List *find_nonnullable_vars(Node *clause);
extern List *find_forced_null_vars(Node *clause);
extern Var *find_forced_null_var(Node *clause);
94

95 96
extern char check_execute_on_functions(Node *clause);

97
extern bool is_pseudo_constant_clause(Node *clause);
98
extern bool is_pseudo_constant_clause_relids(Node *clause, Relids relids);
99

100
extern int	NumRelids(Node *clause);
101 102 103

extern void CommuteOpExpr(OpExpr *clause);
extern void CommuteRowCompareExpr(RowCompareExpr *clause);
104

105 106
extern Node *strip_implicit_coercions(Node *node);

107 108
extern Node *eval_const_expressions(PlannerInfo *root, Node *node);

R
Richard Guo 已提交
109
extern Query *fold_constants(PlannerInfo *root, Query *q, ParamListInfo boundParams, Size max_size);
110

111
extern Expr *transform_array_Const_to_ArrayExpr(Const *c, int *);
112

113 114
extern Node *estimate_expression_value(PlannerInfo *root, Node *node);

115
extern Query *inline_set_returning_function(PlannerInfo *root,
116
							  RangeTblEntry *rte);
117

A
Asim R P 已提交
118 119
extern Expr *evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod,
			  Oid result_collation);
120

121 122 123 124 125 126 127 128 129 130
extern bool is_grouping_extension(CanonicalGroupingSets *grpsets);
extern bool contain_extended_grouping(List *grp);

extern bool is_builtin_true_equality_between_same_type(int opno);
extern bool is_builtin_greenplum_hashable_equality_between_same_type(int opno);

extern bool subexpression_match(Expr *expr1, Expr *expr2);

// resolve the join alias varno/varattno information to its base varno/varattno information
extern Query *flatten_join_alias_var_optimizer(Query *query, int queryLevel);
131

132
#endif   /* CLAUSES_H */