CUBRID Engine  latest
regu_var.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * Regular variable - functionality encoded into XASL
21  */
22 
23 #ifndef _REGU_VAR_HPP_
24 #define _REGU_VAR_HPP_
25 
26 #include "heap_attrinfo.h"
27 #include "object_domain.h"
28 #include "query_list.h"
29 #include "string_opfunc.h"
30 #include "object_primitive.h"
31 
32 #include <functional>
33 
34 // forward definitions
35 struct xasl_node;
36 namespace cubxasl
37 {
38  struct aggregate_list_node;
39  struct pred_expr;
40 } // namespace cubxasl
41 
42 typedef enum
43 {
44  /* types used by both XASL interpreter and regulator */
45  TYPE_DBVAL, /* use dbval */
46  TYPE_CONSTANT, /* use varptr */
47  TYPE_ORDERBY_NUM, /* to be updated by orderby_num() in output list; act same as TYPE_CONSTANT */
48  TYPE_INARITH, /* use arithptr */
49  TYPE_OUTARITH, /* use arithptr */
50  TYPE_ATTR_ID, /* use attr_descr */
51  TYPE_CLASS_ATTR_ID, /* use attr_descr */
52  TYPE_SHARED_ATTR_ID, /* use attr_descr */
53  TYPE_POSITION, /* use pos_descr */
54  TYPE_LIST_ID, /* use srlist_id */
55  TYPE_POS_VALUE, /* use val_pos for host variable references */
56  TYPE_OID, /* does not have corresponding field use current object identifier value */
57  TYPE_CLASSOID, /* does not have corresponding field use current class identifier value */
58  TYPE_FUNC, /* use funcp */
59  TYPE_REGUVAL_LIST, /* use reguval_list */
60  TYPE_REGU_VAR_LIST /* use regu_variable_list for 'CUME_DIST' and 'PERCENT_RANK' */
62 
63 /* declare ahead REGU_VARIABLE */
65 typedef struct regu_variable_list_node *REGU_VARIABLE_LIST; /* TODO */
66 
67 /*
68  * CATALOG STRUCTURES
69  */
70 
71 typedef int CL_ATTR_ID;
72 
73 typedef struct attr_descr_node ATTR_DESCR;
75 {
76  CL_ATTR_ID id; /* Attribute identifier */
77  DB_TYPE type; /* Attribute data type */
78  HEAP_CACHE_ATTRINFO *cache_attrinfo; /* used to cache catalog info */
79  DB_VALUE *cache_dbvalp; /* cached value for particular attr */
80  /* in cache_attrinfo */
81 
82  void reset ()
83  {
84  id = -1;
85  type = DB_TYPE_NULL;
86  cache_dbvalp = NULL;
87  }
88 }; /* Attribute Descriptor */
89 
90 /************************************************************************/
91 /* Regu stuff */
92 /************************************************************************/
95 {
96  REGU_VARIABLE *value; /* REGU_VARIABLE */
97  REGU_VALUE_ITEM *next; /* next item */
98 
99  regu_value_item () = default;
100 };
101 
104 {
105  REGU_VALUE_ITEM *regu_list; /* list head */
106  REGU_VALUE_ITEM *current_value; /* current used item */
107  int count;
108 
109  regu_value_list () = default;
110 };
111 
115 {
116  REGU_VARIABLE_LIST valptrp; /* value pointer list */
117  int valptr_cnt; /* value count */
118 
119  valptr_list_node () = default;
120 };
121 
124 {
125  TP_DOMAIN *domain; /* resultant domain */
126  TP_DOMAIN *original_domain; /* original resultant domain, used at execution in case of XASL clones */
127  DB_VALUE *value; /* value of the subtree */
128  REGU_VARIABLE *leftptr; /* left operand */
129  REGU_VARIABLE *rightptr; /* right operand */
130  REGU_VARIABLE *thirdptr; /* third operand */
131  OPERATOR_TYPE opcode; /* operator value */
132  MISC_OPERAND misc_operand; /* currently used for trim qualifier and datetime extract field specifier */
133  cubxasl::pred_expr *pred; /* predicate expression */
134 
135  /* NOTE: The following member is only used on server internally. */
136  struct drand48_data *rand_seed; /* seed to be used to generate pseudo-random sequence */
137 };
138 
141 {
142  DB_VALUE *value; /* value of the function */
143  REGU_VARIABLE_LIST operand; /* operands */
144  FUNC_TYPE ftype; /* function to call */
145  mutable union function_tmp_obj *tmp_obj;
146 };
147 
148 // NOTE: The following union is used when a function needs to store any object temporary in query execution
149 // please don't forget to deallocate it, refering regu_variable_node::clear_xasl_local() and qexec_clear_regu_var()
151 {
152  cub_compiled_regex *compiled_regex;
153 };
154 
155 /* regular variable flags */
156 const int REGU_VARIABLE_HIDDEN_COLUMN = 0x01; /* does not go to list file */
157 const int REGU_VARIABLE_FIELD_COMPARE = 0x02; /* for FIELD function, marks the bottom of regu tree */
158 const int REGU_VARIABLE_FIELD_NESTED = 0x04; /* for FIELD function, reguvar is child in T_FIELD tree */
159 const int REGU_VARIABLE_APPLY_COLLATION = 0x08; /* Apply collation from domain; flag used in context of COLLATE
160  * modifier */
161 const int REGU_VARIABLE_ANALYTIC_WINDOW = 0x10; /* for analytic window func */
162 const int REGU_VARIABLE_INFER_COLLATION = 0x20; /* infer collation for default parameter */
163 const int REGU_VARIABLE_FETCH_ALL_CONST = 0x40; /* is all constant */
164 const int REGU_VARIABLE_FETCH_NOT_CONST = 0x80; /* is not constant */
165 const int REGU_VARIABLE_CLEAR_AT_CLONE_DECACHE = 0x100; /* clears regu variable at clone decache */
166 const int REGU_VARIABLE_UPD_INS_LIST = 0x200; /* for update or insert query */
167 const int REGU_VARIABLE_STRICT_TYPE_CAST = 0x400;/* for update or insert query */
168 
170 {
171  public:
173 
174  int flags; /* flags */
175  TP_DOMAIN *domain; /* domain of the value in this regu variable */
176  TP_DOMAIN *original_domain; /* original domain, used at execution in case of XASL clones */
177  DB_VALUE *vfetch_to; /* src db_value to fetch into in qp_fetchvlist */
178  xasl_node *xasl; /* query xasl pointer */
180  {
181  /* fields used by both XASL interpreter and regulator */
182  DB_VALUE dbval; /* for DB_VALUE values */
183  DB_VALUE *dbvalptr; /* for constant values */
184  ARITH_TYPE *arithptr; /* arithmetic expression */
185  cubxasl::aggregate_list_node *aggptr; /* aggregate expression */
186  ATTR_DESCR attr_descr; /* attribute information */
187  QFILE_TUPLE_VALUE_POSITION pos_descr; /* list file columns */
188  QFILE_SORTED_LIST_ID *srlist_id; /* sorted list identifier for subquery results */
189  int val_pos; /* host variable references */
190  struct function_node *funcp; /* function */
191  REGU_VALUE_LIST *reguval_list; /* for "values" query */
192  REGU_VARIABLE_LIST regu_var_list; /* for CUME_DIST and PERCENT_RANK */
193  } value;
194 
195  regu_variable_node () = default;
196 
197  using map_regu_func_type = std::function<void (regu_variable_node &regu, bool &stop)>;
198  using map_xasl_func_type = std::function<void (xasl_node &xasl, bool &stop)>;
199  // map_regu - recursive "walker" of regu variable tree applying function argument
200  //
201  // NOTE:
202  // stop argument may be used for interrupting mapper
203  //
204  // !!! implementation is not mature; only arithmetic and function children are mapped.
205  void map_regu (const map_regu_func_type &func);
206  // map_regu_and_xasl - map regu variable and nested XASL's
207  void map_regu_and_xasl (const map_regu_func_type &regu_func, const map_xasl_func_type &xasl_func);
208 
209  // free dynamically allocated memory from this node and all its children
210  void clear_xasl ();
211 
212  private:
213  void map_regu (const map_regu_func_type &func, bool &stop);
214 
215  // clear dynamically allocated memory from this node
216  void clear_xasl_local ();
217 };
218 
220 {
221  REGU_VARIABLE_LIST next; /* Next node */
222  REGU_VARIABLE value; /* Regulator variable */
223 };
224 
225 typedef struct regu_varlist_list_node *REGU_VARLIST_LIST; /* TODO */
227 {
228  REGU_VARLIST_LIST next; /* Next mode */
229  REGU_VARIABLE_LIST list; /* Pointer of regular variable list */
230 
231  regu_varlist_list_node () = default;
232 };
233 
234 typedef struct regu_ptr_list_node *REGU_PTR_LIST; /* TODO */
236 {
237  REGU_PTR_LIST next; /* Next node */
238  REGU_VARIABLE *var_p; /* Regulator variable pointer */
239 };
240 
241 // regular variable flag functions
242 // note - uppercase names are used because they used to be macros.
243 inline bool REGU_VARIABLE_IS_FLAGED (const regu_variable_node *regu, int flag);
244 inline void REGU_VARIABLE_SET_FLAG (regu_variable_node *regu, int flag);
245 inline void REGU_VARIABLE_CLEAR_FLAG (regu_variable_node *regu, int flag);
247 
249 // inline/template implementation
251 
252 bool
254 {
255  return (regu->flags & flag) != 0;
256 }
257 
258 void
260 {
261  regu->flags |= flag;
262 }
263 
264 void
266 {
267  regu->flags &= ~flag;
268 }
269 
270 DB_TYPE
272 {
273  if (regu)
274  {
275  return TP_DOMAIN_TYPE (regu->domain);
276  }
277  return DB_TYPE_UNKNOWN;
278 }
279 #endif /* _REGU_VAR_HPP_ */
void REGU_VARIABLE_SET_FLAG(regu_variable_node *regu, int flag)
Definition: regu_var.hpp:259
REGU_VALUE_ITEM * regu_list
Definition: regu_var.hpp:105
DB_TYPE REGU_VARIABLE_GET_TYPE(const regu_variable_node *regu)
Definition: regu_var.hpp:271
const int REGU_VARIABLE_ANALYTIC_WINDOW
Definition: regu_var.hpp:161
REGU_VARIABLE_LIST operand
Definition: regu_var.hpp:143
REGU_DATATYPE type
Definition: regu_var.hpp:172
REGU_VARIABLE * rightptr
Definition: regu_var.hpp:129
REGU_VARIABLE * value
Definition: regu_var.hpp:96
DB_TYPE
Definition: dbtype_def.h:670
REGU_VARIABLE_LIST next
Definition: regu_var.hpp:221
const int REGU_VARIABLE_HIDDEN_COLUMN
Definition: regu_var.hpp:156
const int REGU_VARIABLE_FIELD_NESTED
Definition: regu_var.hpp:158
REGU_VARIABLE * leftptr
Definition: regu_var.hpp:128
cubxasl::aggregate_list_node * aggptr
Definition: regu_var.hpp:185
FUNC_TYPE
CL_ATTR_ID id
Definition: regu_var.hpp:76
bool REGU_VARIABLE_IS_FLAGED(const regu_variable_node *regu, int flag)
Definition: regu_var.hpp:253
cub_compiled_regex * compiled_regex
Definition: regu_var.hpp:152
const int REGU_VARIABLE_FETCH_NOT_CONST
Definition: regu_var.hpp:164
TP_DOMAIN * original_domain
Definition: regu_var.hpp:126
OPERATOR_TYPE opcode
Definition: regu_var.hpp:131
DB_VALUE * vfetch_to
Definition: regu_var.hpp:177
DB_VALUE * cache_dbvalp
Definition: regu_var.hpp:79
const int REGU_VARIABLE_UPD_INS_LIST
Definition: regu_var.hpp:166
cubxasl::pred_expr * pred
Definition: regu_var.hpp:133
MISC_OPERAND misc_operand
Definition: regu_var.hpp:132
QFILE_SORTED_LIST_ID * srlist_id
Definition: regu_var.hpp:188
OPERATOR_TYPE
const int REGU_VARIABLE_FIELD_COMPARE
Definition: regu_var.hpp:157
REGU_VARIABLE value
Definition: regu_var.hpp:222
const int REGU_VARIABLE_CLEAR_AT_CLONE_DECACHE
Definition: regu_var.hpp:165
struct function_node * funcp
Definition: regu_var.hpp:190
struct drand48_data * rand_seed
Definition: regu_var.hpp:136
struct regu_varlist_list_node * REGU_VARLIST_LIST
Definition: regu_var.hpp:225
REGU_VALUE_ITEM * next
Definition: regu_var.hpp:97
#define TP_DOMAIN_TYPE(dom)
xasl_node * xasl
Definition: regu_var.hpp:178
#define NULL
Definition: freelistheap.h:34
FUNC_TYPE ftype
Definition: regu_var.hpp:144
TP_DOMAIN * original_domain
Definition: regu_var.hpp:176
REGU_DATATYPE
Definition: regu_var.hpp:42
DB_VALUE * value
Definition: regu_var.hpp:127
REGU_VALUE_ITEM * current_value
Definition: regu_var.hpp:106
DB_TYPE type
Definition: regu_var.hpp:77
const int REGU_VARIABLE_APPLY_COLLATION
Definition: regu_var.hpp:159
struct regu_ptr_list_node * REGU_PTR_LIST
Definition: regu_var.hpp:234
struct regu_variable_list_node * REGU_VARIABLE_LIST
Definition: regu_var.hpp:65
const int REGU_VARIABLE_STRICT_TYPE_CAST
Definition: regu_var.hpp:167
const int REGU_VARIABLE_INFER_COLLATION
Definition: regu_var.hpp:162
void REGU_VARIABLE_CLEAR_FLAG(regu_variable_node *regu, int flag)
Definition: regu_var.hpp:265
int CL_ATTR_ID
Definition: regu_var.hpp:71
REGU_VARIABLE_LIST list
Definition: regu_var.hpp:229
HEAP_CACHE_ATTRINFO * cache_attrinfo
Definition: regu_var.hpp:78
std::function< void(regu_variable_node &regu, bool &stop)> map_regu_func_type
Definition: regu_var.hpp:197
class regu_variable_node REGU_VARIABLE
Definition: regu_var.hpp:64
REGU_VARIABLE * var_p
Definition: regu_var.hpp:238
REGU_VARIABLE_LIST regu_var_list
Definition: regu_var.hpp:192
const int REGU_VARIABLE_FETCH_ALL_CONST
Definition: regu_var.hpp:163
REGU_VARIABLE * thirdptr
Definition: regu_var.hpp:130
union function_tmp_obj * tmp_obj
Definition: regu_var.hpp:145
REGU_VARLIST_LIST next
Definition: regu_var.hpp:228
std::function< void(xasl_node &xasl, bool &stop)> map_xasl_func_type
Definition: regu_var.hpp:198
TP_DOMAIN * domain
Definition: regu_var.hpp:175
REGU_VARIABLE_LIST valptrp
Definition: regu_var.hpp:116
MISC_OPERAND
QFILE_TUPLE_VALUE_POSITION pos_descr
Definition: regu_var.hpp:187
DB_VALUE * value
Definition: regu_var.hpp:142
REGU_PTR_LIST next
Definition: regu_var.hpp:237
TP_DOMAIN * domain
Definition: regu_var.hpp:125