1 | /* |
2 | * This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
5 | * |
6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
7 | */ |
8 | |
9 | #ifndef _REL_REL_H_ |
10 | #define _REL_REL_H_ |
11 | |
12 | #include "sql_mvc.h" |
13 | #include "sql_relation.h" |
14 | #include "sql_semantic.h" |
15 | |
16 | #define sql_from 1 |
17 | #define sql_where 2 |
18 | #define sql_sel 4 |
19 | #define sql_having 8 |
20 | #define sql_orderby 16 |
21 | #define sql_groupby 32 //ORed |
22 | #define sql_aggr 64 //ORed |
23 | #define sql_farg 128 //ORed |
24 | #define sql_window 256 //ORed |
25 | #define sql_join 512 //ORed |
26 | #define sql_outer 1024 //ORed |
27 | |
28 | #define is_sql_from(X) ((X & sql_from) == sql_from) |
29 | #define is_sql_where(X) ((X & sql_where) == sql_where) |
30 | #define is_sql_sel(X) ((X & sql_sel) == sql_sel) |
31 | #define is_sql_having(X) ((X & sql_having) == sql_having) |
32 | #define is_sql_orderby(X) ((X & sql_orderby) == sql_orderby) |
33 | #define is_sql_groupby(X) ((X & sql_groupby) == sql_groupby) |
34 | #define is_sql_aggr(X) ((X & sql_aggr) == sql_aggr) |
35 | #define is_sql_farg(X) ((X & sql_farg) == sql_farg) |
36 | #define is_sql_window(X) ((X & sql_window) == sql_window) |
37 | #define is_sql_join(X) ((X & sql_join) == sql_join) |
38 | #define is_sql_outer(X) ((X & sql_outer) == sql_outer) |
39 | |
40 | #define rel_groupby_gbe(m,r,e) rel_groupby(m, r, append(new_exp_list(m->sa), e)) |
41 | #define new_rel_list(sa) sa_list(sa) |
42 | |
43 | #define is_updateble(rel) \ |
44 | (rel->op == op_basetable || \ |
45 | (rel->op == op_ddl && (rel->flag == ddl_create_table || rel->flag == ddl_alter_table))) |
46 | |
47 | extern const char *rel_name( sql_rel *r ); |
48 | extern sql_rel *rel_distinct(sql_rel *l); |
49 | |
50 | extern sql_rel *rel_dup(sql_rel *r); |
51 | extern void rel_destroy(sql_rel *rel); |
52 | extern sql_rel *rel_create(sql_allocator *sa); |
53 | extern sql_rel *rel_copy(mvc *sql, sql_rel *r, int deep); |
54 | extern sql_rel *rel_select_copy(sql_allocator *sa, sql_rel *l, list *exps); |
55 | |
56 | extern sql_exp *rel_bind_column( mvc *sql, sql_rel *rel, const char *cname, int f ); |
57 | extern sql_exp *rel_bind_column2( mvc *sql, sql_rel *rel, const char *tname, const char *cname, int f ); |
58 | extern sql_exp *rel_first_column(mvc *sql, sql_rel *rel); |
59 | |
60 | extern sql_rel *rel_inplace_setop(sql_rel *rel, sql_rel *l, sql_rel *r, operator_type setop, list *exps); |
61 | extern sql_rel *rel_inplace_project(sql_allocator *sa, sql_rel *rel, sql_rel *l, list *e); |
62 | extern sql_rel *rel_inplace_groupby(sql_rel *rel, sql_rel *l, list *groupbyexps, list *exps ); |
63 | |
64 | extern int rel_convert_types(mvc *sql, sql_rel *ll, sql_rel *rr, sql_exp **L, sql_exp **R, int scale_fixing, check_type tpe); |
65 | extern sql_rel *rel_setop(sql_allocator *sa, sql_rel *l, sql_rel *r, operator_type setop); |
66 | extern sql_rel *rel_setop_check_types(mvc *sql, sql_rel *l, sql_rel *r, list *ls, list *rs, operator_type op); |
67 | extern sql_rel *rel_crossproduct(sql_allocator *sa, sql_rel *l, sql_rel *r, operator_type join); |
68 | |
69 | /* in case e is an constant and rel is a simple project of only e, free rel */ |
70 | extern sql_exp *rel_is_constant(sql_rel **rel, sql_exp *e); |
71 | |
72 | extern sql_rel *rel_topn(sql_allocator *sa, sql_rel *l, list *exps ); |
73 | extern sql_rel *rel_sample(sql_allocator *sa, sql_rel *l, list *exps ); |
74 | |
75 | extern sql_rel *rel_label( mvc *sql, sql_rel *r, int all); |
76 | extern sql_exp *rel_project_add_exp( mvc *sql, sql_rel *rel, sql_exp *e); |
77 | extern sql_rel *rel_select_add_exp(sql_allocator *sa, sql_rel *l, sql_exp *e); |
78 | extern void rel_join_add_exp(sql_allocator *sa, sql_rel *rel, sql_exp *e); |
79 | extern sql_exp *rel_groupby_add_aggr(mvc *sql, sql_rel *rel, sql_exp *e); |
80 | |
81 | extern sql_rel *rel_select(sql_allocator *sa, sql_rel *l, sql_exp *e); |
82 | extern sql_rel *rel_basetable(mvc *sql, sql_table *t, const char *tname); |
83 | extern sql_rel *rel_groupby(mvc *sql, sql_rel *l, list *groupbyexps ); |
84 | extern sql_rel *rel_project(sql_allocator *sa, sql_rel *l, list *e); |
85 | extern sql_rel *rel_project_exp(sql_allocator *sa, sql_exp *e); |
86 | extern sql_rel *rel_exception(sql_allocator *sa, sql_rel *l, sql_rel *r, list *exps); |
87 | |
88 | extern sql_rel *rel_relational_func(sql_allocator *sa, sql_rel *l, list *exps); |
89 | extern sql_rel *rel_table_func(sql_allocator *sa, sql_rel *l, sql_exp *f, list *exps, int kind); |
90 | |
91 | extern list *_rel_projections(mvc *sql, sql_rel *rel, const char *tname, int settname , int intern, int basecol); |
92 | extern list *rel_projections(mvc *sql, sql_rel *rel, const char *tname, int settname , int intern); |
93 | extern sql_rel *rel_safe_project(mvc *sql, sql_rel *rel); |
94 | |
95 | extern sql_rel *rel_push_select(mvc *sql, sql_rel *rel, sql_exp *ls, sql_exp *e); |
96 | extern sql_rel *rel_push_join(mvc *sql, sql_rel *rel, sql_exp *ls, sql_exp *rs, sql_exp *rs2, sql_exp *e); |
97 | extern sql_rel *rel_or(mvc *sql, sql_rel *rel, sql_rel *l, sql_rel *r, list *oexps, list *lexps, list *rexps); |
98 | |
99 | extern sql_table *rel_ddl_table_get(sql_rel *r); |
100 | |
101 | extern sql_rel *rel_add_identity(mvc *sql, sql_rel *rel, sql_exp **exp); |
102 | extern sql_rel *rel_add_identity2(mvc *sql, sql_rel *rel, sql_exp **exp); |
103 | extern sql_exp * rel_find_column( sql_allocator *sa, sql_rel *rel, const char *tname, const char *cname ); |
104 | |
105 | extern int rel_in_rel(sql_rel *super, sql_rel *sub); |
106 | |
107 | extern list *rel_dependencies(mvc *sql, sql_rel *r); |
108 | extern sql_exp * exps_find_match_exp(list *l, sql_exp *e); |
109 | |
110 | typedef sql_exp *(*exp_rewrite_fptr)(mvc *sql, sql_rel *rel, sql_exp *e, int depth /* depth of the nested expression */ ); |
111 | extern sql_rel *rel_exp_visitor(mvc *sql, sql_rel *rel, exp_rewrite_fptr exp_rewriter); |
112 | |
113 | typedef sql_rel *(*rel_rewrite_fptr)(mvc *sql, sql_rel *rel); |
114 | extern sql_rel *rel_visitor(mvc *sql, sql_rel *rel, rel_rewrite_fptr rel_rewriter); |
115 | |
116 | #endif /* _REL_REL_H_ */ |
117 | |