CUBRID Engine  latest
query_evaluator.h
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 /*
21  * Predicate evaluation
22  */
23 
24 #ifndef _QUERY_EVALUATOR_H_
25 #define _QUERY_EVALUATOR_H_
26 
27 #ident "$Id$"
28 
29 #if !defined (SERVER_MODE) && !defined (SA_MODE)
30 #error Belongs to server module
31 #endif /* !defined (SERVER_MODE) && !defined (SA_MODE) */
32 
33 #include "heap_file.h"
34 #if defined(WINDOWS)
35 #include "porting.h"
36 #endif /* ! WINDOWS */
37 #include "thread_compat.hpp"
38 
39 #include <assert.h>
40 #if !defined (WINDOWS)
41 #include <stdlib.h>
42 #endif // not WINDOWS
43 
44 // forward definitions
46 class regu_variable_node;
47 struct val_descr;
48 typedef struct val_descr VAL_DESCR;
49 struct val_list_node;
50 
51 // *INDENT-OFF*
52 namespace cubxasl
53 {
54  struct pred_expr;
55 }
57 // *INDENT-ON*
58 
59 typedef DB_LOGICAL (*PR_EVAL_FNC) (THREAD_ENTRY * thread_p, const PRED_EXPR *, val_descr *, OID *);
60 
61 typedef enum
62 {
63  QPROC_QUALIFIED = 0, /* fetch a qualified item; default */
64  QPROC_NOT_QUALIFIED, /* fetch a not-qualified item */
65  QPROC_QUALIFIED_OR_NOT /* fetch either a qualified or not-qualified item */
67 
68 #define QPROC_ANALYTIC_IS_OFFSET_FUNCTION(func_p) \
69  (((func_p) != NULL) \
70  && (((func_p)->function == PT_LEAD) \
71  || ((func_p)->function == PT_LAG) \
72  || ((func_p)->function == PT_NTH_VALUE)))
73 
74 #define ANALYTIC_ADVANCE_RANK 1 /* advance rank */
75 #define ANALYTIC_KEEP_RANK 2 /* keep current rank */
76 
77 #define ANALYTIC_FUNC_IS_FLAGED(x, f) ((x)->flag & (int) (f))
78 #define ANALYTIC_FUNC_SET_FLAG(x, f) (x)->flag |= (int) (f)
79 #define ANALYTIC_FUNC_CLEAR_FLAG(x, f) (x)->flag &= (int) ~(f)
80 
81 /*
82  * typedefs related to the predicate expression structure
83  */
84 
85 #ifdef V_FALSE
86 #undef V_FALSE
87 #endif
88 #ifdef V_TRUE
89 #undef V_TRUE
90 #endif
91 
92 /* predicates information of scan */
93 typedef struct scan_pred SCAN_PRED;
94 struct scan_pred
95 {
96  regu_variable_list_node *regu_list; /* regu list for predicates (or filters) */
97  PRED_EXPR *pred_expr; /* predicate expressions */
98  PR_EVAL_FNC pr_eval_fnc; /* predicate evaluation function */
99 };
100 
101 /* attributes information of scan */
102 typedef struct scan_attrs SCAN_ATTRS;
104 {
105  ATTR_ID *attr_ids; /* array of attributes id */
106  heap_cache_attrinfo *attr_cache; /* attributes access cache */
107  int num_attrs; /* number of attributes */
108 };
109 
110 /* informations that are need for applying filter (predicate) */
111 typedef struct filter_info FILTER_INFO;
113 {
114  /* filter information */
115  SCAN_PRED *scan_pred; /* predicates of the filter */
116  SCAN_ATTRS *scan_attrs; /* attributes scanning info */
117  val_list_node *val_list; /* value list */
118  VAL_DESCR *val_descr; /* value descriptor */
119 
120  /* class information */
121  OID *class_oid; /* class OID */
122 
123  /* index information */
124  ATTR_ID *btree_attr_ids; /* attribute id array of the index key */
125  int *num_vstr_ptr; /* number pointer of variable string attrs */
126  ATTR_ID *vstr_ids; /* attribute id array of variable string */
127  int btree_num_attrs; /* number of attributes of the index key */
128  int func_idx_col_id; /* function expression column position, if this is a function index */
129 
130  // *INDENT-OFF*
131  filter_info () = default;
132  // *INDENT-ON*
133 };
134 
135 extern DB_LOGICAL eval_pred (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, val_descr * vd, OID * obj_oid);
136 extern DB_LOGICAL eval_pred_comp0 (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, val_descr * vd, OID * obj_oid);
137 extern DB_LOGICAL eval_pred_comp1 (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, val_descr * vd, OID * obj_oid);
138 extern DB_LOGICAL eval_pred_comp2 (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, val_descr * vd, OID * obj_oid);
139 extern DB_LOGICAL eval_pred_comp3 (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, val_descr * vd, OID * obj_oid);
140 extern DB_LOGICAL eval_pred_alsm4 (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, val_descr * vd, OID * obj_oid);
141 extern DB_LOGICAL eval_pred_alsm5 (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, val_descr * vd, OID * obj_oid);
142 extern DB_LOGICAL eval_pred_like6 (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, val_descr * vd, OID * obj_oid);
143 extern DB_LOGICAL eval_pred_rlike7 (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, val_descr * vd, OID * obj_oid);
144 extern PR_EVAL_FNC eval_fnc (THREAD_ENTRY * thread_p, const PRED_EXPR * pr, DB_TYPE * single_node_type);
145 extern DB_LOGICAL eval_data_filter (THREAD_ENTRY * thread_p, OID * oid, RECDES * recdes, HEAP_SCANCACHE * scan_cache,
146  FILTER_INFO * filter);
147 extern DB_LOGICAL eval_key_filter (THREAD_ENTRY * thread_p, DB_VALUE * value, FILTER_INFO * filter);
148 extern DB_LOGICAL update_logical_result (THREAD_ENTRY * thread_p, DB_LOGICAL ev_res, int *qualification);
149 
150 #endif /* _QUERY_EVALUATOR_H_ */
ATTR_ID * btree_attr_ids
ATTR_ID * attr_ids
SCAN_PRED * scan_pred
DB_TYPE
Definition: dbtype_def.h:670
DB_LOGICAL eval_pred_alsm4(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
DB_LOGICAL(* PR_EVAL_FNC)(THREAD_ENTRY *thread_p, const PRED_EXPR *, val_descr *, OID *)
DB_LOGICAL update_logical_result(THREAD_ENTRY *thread_p, DB_LOGICAL ev_res, int *qualification)
ATTR_ID * vstr_ids
DB_LOGICAL eval_pred(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
void THREAD_ENTRY
int ATTR_ID
DB_LOGICAL eval_pred_rlike7(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
regu_variable_list_node * regu_list
DB_LOGICAL eval_pred_comp3(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
PRED_EXPR * pred_expr
DB_LOGICAL eval_pred_alsm5(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
DB_LOGICAL eval_pred_comp1(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
SCAN_ATTRS * scan_attrs
val_list_node * val_list
DB_LOGICAL eval_pred_comp2(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
DB_LOGICAL eval_pred_comp0(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
PR_EVAL_FNC pr_eval_fnc
QPROC_QUALIFICATION
PR_EVAL_FNC eval_fnc(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, DB_TYPE *single_node_type)
DB_LOGICAL
Definition: dbtype_def.h:1218
DB_LOGICAL eval_pred_like6(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
heap_cache_attrinfo * attr_cache
DB_LOGICAL eval_key_filter(THREAD_ENTRY *thread_p, DB_VALUE *value, FILTER_INFO *filter)
DB_LOGICAL eval_data_filter(THREAD_ENTRY *thread_p, OID *oid, RECDES *recdes, HEAP_SCANCACHE *scan_cache, FILTER_INFO *filter)
VAL_DESCR * val_descr