CUBRID Engine  latest
object_representation_sr.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  * object_representation_sr.h - Definitions for the server side functions
22  * that extract class information from disk representations
23  */
24 
25 #ifndef _OBJECT_REPRESENTATION_SR_H_
26 #define _OBJECT_REPRESENTATION_SR_H_
27 
28 #ident "$Id$"
29 
30 #if !defined (SERVER_MODE) && !defined (SA_MODE)
31 #error Belongs to server module
32 #endif /* !defined (SERVER_MODE) && !defined (SA_MODE) */
33 
34 #if !defined (__cplusplus)
35 #error C++ required
36 #endif // C++ required
37 
38 #include "dbtype_def.h"
39 #include "log_lsa.hpp"
40 #include "mvcc.h"
41 #include "storage_common.h"
42 #include "system_catalog.h"
43 
44 #include <atomic>
45 
46 #define OR_ATT_BTID_PREALLOC 8
47 
48 /* We can't have an attribute with default expression and default value simultaneously. */
51 {
52  /* could this be converted to a server side DB_VALUE ? */
53  void *value; /* default value */
54  int val_length; /* default value length */
55  DB_DEFAULT_EXPR default_expr; /* default expression */
56 };
57 
58 /*
59  * OR_ATTRIBUTE
60  *
61  * Server side memory representation of an attribute definition.
62  * Built from the disk representation of a class.
63  * Part of the OR_CLASSREP structure hierarchy.
64  */
65 // *INDENT-OFF*
66 // work-around for windows compile error:
67 // error C2338: You've instantiated std::atomic<T> with sizeof(T) equal to 2/4/8 and alignof(T) < sizeof(T)
68 //
69 // it may be removed if support for VS versions older than 2015 is dropped.
71 {
72  std::int64_t dummy_for_alignemnt;
74 
75  or_aligned_oid () noexcept = default;
76 
77  or_aligned_oid (const OID & arg_oid)
78  : oid (arg_oid)
79  {
80  }
81 };
82 
84 {
85  std::atomic<or_aligned_oid> serial_obj;
86 };
87 // *INDENT-ON*
88 
89 typedef struct or_attribute OR_ATTRIBUTE;
91 {
92  OR_ATTRIBUTE *next; /* obsolete : use array for accessing elements */
93 
94  int id; /* unique id */
95  DB_TYPE type; /* basic type */
96  int def_order; /* order of attributes in class */
97  int location; /* fixed offset or variable table index */
98  int position; /* storage position (list index) */
99  OID classoid; /* source class object id */
100 
101  DB_DEFAULT_EXPR_TYPE on_update_expr; /* on update default expr type */
102  OR_DEFAULT_VALUE default_value; /* default value */
104  BTID *btids; /* B-tree ID's for indexes and constraints */
105  TP_DOMAIN *domain; /* full domain of this attribute */
106 
108 
109  int n_btids; /* Number of ID's in the btids array */
110  BTID index; /* btree id if indexed */
111 
112  /* local array of btid's to use if possible */
113  int max_btids; /* Size of the btids array */
115 
116  unsigned is_fixed:1; /* non-zero if this is a fixed width attribute */
117  unsigned is_autoincrement:1; /* non-zero if att is auto increment att */
118  unsigned is_notnull:1; /* non-zero if has not null constraint */
119 };
120 
123 {
124  OR_FOREIGN_KEY *next; /* for pk */
125  char *fkname; /* foreign key name */
132 };
133 
134 typedef struct or_predicate OR_PREDICATE;
136 {
137  char *pred_string;
138  char *pred_stream; /* CREATE INDEX ... WHERE filter_predicate */
140 };
141 
144 {
145  char *expr_string;
146  char *expr_stream;
148  int col_id; /* the position at which the function is placed */
149  int attr_index_start; /* the index from where the attributes involved in a function are placed in OR_INDEX
150  * atts member */
151 };
152 
153 typedef enum
154 {
159 
168 
169 typedef struct or_index OR_INDEX;
170 struct or_index
171 {
172  OR_INDEX *next; /* obsolete : use array for accessing elements */
173  OR_ATTRIBUTE **atts; /* Array of associated attributes */
174  int *asc_desc; /* array of ascending / descending */
175  int *attrs_prefix_length; /* prefix length */
176  char *btname; /* index( or constraint) name */
177  OR_PREDICATE *filter_predicate; /* CREATE INDEX idx ON tbl(col, ...) WHERE filter_predicate */
178  OR_FUNCTION_INDEX *func_index_info; /* function index information */
180  BTREE_TYPE type; /* btree type */
181  int n_atts; /* Number of associated attributes */
182  BTID btid; /* btree ID */
184 };
185 
186 typedef struct or_partition OR_PARTITION;
188 {
189  OID class_oid; /* class OID */
190  HFID class_hfid; /* class HFID */
191  int partition_type; /* partition type (range, list, hash) */
192  REPR_ID rep_id; /* class representation id */
193  DB_SEQ *values; /* values for range and list partition types */
194 };
195 
196 typedef struct or_classrep OR_CLASSREP;
198 {
199  OR_CLASSREP *next; /* obsolete : use array for accessing elements */
200 
201  OR_ATTRIBUTE *attributes; /* list of attributes */
202  OR_ATTRIBUTE *shared_attrs; /* list of shared attributes */
203  OR_ATTRIBUTE *class_attrs; /* list of class attributes */
204  OR_INDEX *indexes; /* list of BTIDs for this class */
205 
206  REPR_ID id; /* representation id */
207 
208  int fixed_length; /* total size of the fixed width attributes */
209  int n_attributes; /* size of attribute array */
210  int n_variable; /* number of variable width attributes */
211  int n_shared_attrs; /* number of shared attributes */
212  int n_class_attrs; /* number of class attributes */
213  int n_indexes; /* number of indexes */
214 
215  unsigned needs_indexes:1; /* flag indicating if indexes were not loaded */
216  unsigned has_partition_info:1; /* flag indicating if class has partition info */
217 };
218 
219 typedef struct or_class OR_CLASS;
220 struct or_class
221 {
226 
228  OID statistics; /* object containing statistics */
229 };
230 
231 extern void or_class_rep_dir (RECDES * record, OID * rep_dir_p);
232 extern void or_class_hfid (RECDES * record, HFID * hfid);
233 extern void or_class_tde_algorithm (RECDES * record, TDE_ALGORITHM * tde_algo);
234 #if defined (ENABLE_UNUSED_FUNCTION)
235 extern void or_class_statistics (RECDES * record, OID * oid);
236 extern int or_class_subclasses (RECDES * record, int *array_size, OID ** array_ptr);
237 extern int or_classrep_needs_indexes (OR_CLASSREP * rep);
238 #endif
239 extern int or_get_unique_hierarchy (THREAD_ENTRY * thread_p, RECDES * record, int attrid, BTID * btid,
240  OID ** class_oids, HFID ** hfids, int *num_heaps, int *partition_local_index);
241 extern OR_CLASSREP *or_get_classrep (RECDES * record, int repid);
242 extern OR_CLASSREP *or_get_classrep_noindex (RECDES * record, int repid);
243 extern OR_CLASSREP *or_classrep_load_indexes (OR_CLASSREP * rep, RECDES * record);
244 extern int or_class_get_partition_info (RECDES * record, OR_PARTITION * partition_info, REPR_ID * repr_id,
245  int *has_partition_info);
246 const char *or_get_constraint_comment (RECDES * record, const char *constraint_name);
247 extern void or_free_classrep (OR_CLASSREP * rep);
248 extern int or_get_attrname (RECDES * record, int attrid, char **string, int *alloced_string);
249 extern int or_get_attrcomment (RECDES * record, int attrid, char **string, int *alloced_string);
250 
251 /* OLD STYLE INTERFACE */
252 #if defined (ENABLE_UNUSED_FUNCTION)
253 extern void orc_class_rep_dir (RECDES * record, OID * rep_dir_p);
254 extern void orc_class_hfid_from_record (RECDES * record, HFID * hfid);
255 #endif
256 extern DISK_REPR *orc_diskrep_from_record (THREAD_ENTRY * thread_p, RECDES * record);
257 extern void orc_free_diskrep (DISK_REPR * rep);
258 extern CLS_INFO *orc_class_info_from_record (RECDES * record);
259 extern void orc_free_class_info (CLS_INFO * info);
260 extern int orc_subclasses_from_record (RECDES * record, int *array_size, OID ** array_ptr);
261 extern int orc_superclasses_from_record (RECDES * record, int *array_size, OID ** array_ptr);
262 extern OR_CLASSREP **or_get_all_representation (RECDES * record, bool do_indexes, int *count);
263 
264 extern int or_replace_rep_id (RECDES * record, int repid);
265 
268 extern int or_mvcc_add_header (RECDES * record, MVCC_REC_HEADER * mvcc_rec_header, int bound_bit,
269  int variable_offset_size);
270 extern int or_mvcc_set_log_lsa_to_record (RECDES * record, LOG_LSA * lsa);
271 #endif /* _OBJECT_REPRESENTATION_SR_H_ */
OR_ATTRIBUTE * shared_attrs
OR_FUNCTION_INDEX * func_index_info
CLS_INFO * orc_class_info_from_record(RECDES *record)
OR_CLASSREP * or_get_classrep_noindex(RECDES *record, int repid)
DB_TYPE
Definition: dbtype_def.h:670
OR_ATTRIBUTE * class_attrs
void or_class_hfid(RECDES *record, HFID *hfid)
BTREE_TYPE
int or_class_get_partition_info(RECDES *record, OR_PARTITION *partition_info, REPR_ID *repr_id, int *has_partition_info)
const char * or_get_constraint_comment(RECDES *record, const char *constraint_name)
int orc_subclasses_from_record(RECDES *record, int *array_size, OID **array_ptr)
#define OR_ATT_BTID_PREALLOC
void orc_free_diskrep(DISK_REPR *rep)
int or_get_attrcomment(RECDES *record, int attrid, char **string, int *alloced_string)
void THREAD_ENTRY
or_auto_increment auto_increment
OR_FOREIGN_KEY * fk
DB_DEFAULT_EXPR_TYPE on_update_expr
int or_mvcc_add_header(RECDES *record, MVCC_REC_HEADER *mvcc_rec_header, int bound_bit, int variable_offset_size)
Definition: db_set.h:35
TDE_ALGORITHM
Definition: tde.h:71
OR_DEFAULT_VALUE default_value
std::atomic< or_aligned_oid > serial_obj
int or_get_unique_hierarchy(THREAD_ENTRY *thread_p, RECDES *record, int attrid, BTID *btid, OID **class_oids, HFID **hfids, int *num_heaps, int *partition_local_index)
int orc_superclasses_from_record(RECDES *record, int *array_size, OID **array_ptr)
OR_PREDICATE * filter_predicate
int or_mvcc_set_header(RECDES *record, MVCC_REC_HEADER *mvcc_rec_header)
void or_class_rep_dir(RECDES *record, OID *rep_dir_p)
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
std::int64_t dummy_for_alignemnt
void or_free_classrep(OR_CLASSREP *rep)
void or_class_tde_algorithm(RECDES *record, TDE_ALGORITHM *tde_algo)
int or_mvcc_get_header(RECDES *record, MVCC_REC_HEADER *mvcc_rec_header)
void orc_free_class_info(CLS_INFO *info)
#define const
Definition: cnvlex.c:77
int or_get_attrname(RECDES *record, int attrid, char **string, int *alloced_string)
OR_CLASSREP * or_get_classrep(RECDES *record, int repid)
int or_mvcc_set_log_lsa_to_record(RECDES *record, LOG_LSA *lsa)
int REPR_ID
OR_DEFAULT_VALUE current_default_value
OR_CLASSREP * or_classrep_load_indexes(OR_CLASSREP *rep, RECDES *record)
OR_INDEX_STATUS index_status
OR_ATTRIBUTE * attributes
OR_CLASSREP * representations
DB_DEFAULT_EXPR default_expr
DISK_REPR * orc_diskrep_from_record(THREAD_ENTRY *thread_p, RECDES *record)
OR_ATTRIBUTE ** atts
DB_DEFAULT_EXPR_TYPE
Definition: dbtype_def.h:1181
OR_CLASSREP ** or_get_all_representation(RECDES *record, bool do_indexes, int *count)
int or_replace_rep_id(RECDES *record, int repid)