CUBRID Engine  latest
storage_common.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  * storage_common.h - Definitions and data types of disk related stuffs
22  * such as pages, file structures, and so on.
23  */
24 
25 #ifndef _STORAGE_COMMON_H_
26 #define _STORAGE_COMMON_H_
27 
28 #ident "$Id$"
29 
30 #include "config.h"
31 
32 #include <limits.h>
33 #include <time.h>
34 #include <stdio.h>
35 #include <assert.h>
36 
37 #include "porting.h"
38 #include "porting_inline.hpp"
39 #include "dbtype_def.h"
40 #include "sha1.h"
41 #include "cache_time.h"
42 
43  /* LIMITS AND NULL VALUES ON DISK RELATED DATATYPES */
44 
45 #define NULL_VOLID (-1) /* Value of an invalid volume identifier */
46 #define NULL_SECTID (-1) /* Value of an invalid sector identifier */
47 #define NULL_PAGEID (-1) /* Value of an invalid page identifier */
48 #define NULL_SLOTID (-1) /* Value of an invalid slot identifier */
49 #define NULL_OFFSET (-1) /* Value of an invalid offset */
50 #define NULL_FILEID (-1) /* Value of an invalid file identifier */
51 
52 #define VOLID_MAX SHRT_MAX
53 #define PAGEID_MAX INT_MAX
54 #define SECTID_MAX INT_MAX
55 #define PGLENGTH_MAX SHRT_MAX
56 #define VOL_MAX_NPAGES(page_size) \
57  ((sizeof(off_t) == 4) ? (INT_MAX / (page_size)) : INT_MAX)
58 
59 #define LOGPAGEID_MAX 0x7fffffffffffLL /* 6 bytes length */
60 
61 /* NULL_CHN is a special value for an unspecified cache coherency number.
62  * It should only be used in error conditions. This should never be
63  * found as a stored chn in a disk or memory object.
64  */
65 enum
67 
68 /* Type definitions related to disk information */
69 
70 typedef INT16 VOLID; /* Volume identifier */
71 typedef VOLID DKNVOLS; /* Number of volumes */
72 
73 typedef INT32 PAGEID; /* Data page identifier */
74 typedef PAGEID DKNPAGES; /* Number of disk pages */
75 
76 typedef INT64 LOG_PAGEID; /* Log page identifier */
77 typedef PAGEID LOG_PHY_PAGEID; /* physical log page identifier */
78 
79 typedef INT32 SECTID;
80 typedef SECTID DKNSECTS;
81 
82 typedef INT16 PGSLOTID; /* Page slot identifier */
83 typedef PGSLOTID PGNSLOTS; /* Number of slots on a page */
84 typedef INT16 PGLENGTH; /* Page length */
85 
86 typedef PAGEID FILEID; /* File identifier */
87 typedef INT32 LOLENGTH; /* Length for a large object */
88 
89 /* BOTH IO_PAGESIZE AND DB_PAGESIZE MUST BE MULTIPLE OF sizeof(int) */
90 
91 #define IO_DEFAULT_PAGE_SIZE (16 * ONE_K)
92 #define IO_MIN_PAGE_SIZE (4 * ONE_K)
93 #define IO_MAX_PAGE_SIZE (16 * ONE_K)
94 
95 #define LOG_PAGESIZE (db_log_page_size())
96 #define IO_PAGESIZE (db_io_page_size())
97 #define DB_PAGESIZE (db_page_size())
98 
99 #define IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
100 
101 /*
102  * Sector
103  */
104 /* Number of pages in a sector. Careful about changing this size. The whole file manager depends on this size. */
105 #define DISK_SECTOR_NPAGES 64
106 #define IO_SECTORSIZE (DISK_SECTOR_NPAGES * IO_PAGESIZE)
107 #define DB_SECTORSIZE (DISK_SECTOR_NPAGES * DB_PAGESIZE)
108 
109 #define VOL_MAX_NSECTS(page_size) (VOL_MAX_NPAGES(page_size) / DISK_SECTOR_NPAGES)
110 
111 #define SECTOR_FIRST_PAGEID(sid) ((sid) * DISK_SECTOR_NPAGES)
112 #define SECTOR_LAST_PAGEID(sid) ((((sid) + 1) * DISK_SECTOR_NPAGES) - 1)
113 #define SECTOR_FROM_PAGEID(pageid) ((pageid) / DISK_SECTOR_NPAGES)
114 
115 #define VSID_FROM_VPID(vsid, vpid) (vsid)->volid = (vpid)->volid; (vsid)->sectid = SECTOR_FROM_PAGEID ((vpid)->pageid)
116 #define VSID_IS_SECTOR_OF_VPID(vsid, vpid) \
117  ((vsid)->volid == (vpid)->volid && (vsid)->sectid == SECTOR_FROM_PAGEID ((vpid)->pageid))
118 
119 #define DB_MAX_PATH_LENGTH PATH_MAX
120 
121 #define DISK_VFID_SIZE (OR_INT_SIZE + OR_SHORT_SIZE)
122 #define DISK_VPID_SIZE (OR_INT_SIZE + OR_SHORT_SIZE)
123 
124 #define DISK_VFID_ALIGNED_SIZE (DISK_VFID_SIZE + OR_SHORT_SIZE)
125 #define DISK_VPID_ALIGNED_SIZE (DISK_VPID_SIZE + OR_SHORT_SIZE)
126 
127 /* BTREE definitions */
128 
129 /* Non_Leaf Node Record Size */
130 #define NON_LEAF_RECORD_SIZE (DISK_VPID_ALIGNED_SIZE)
131 /* Leaf Node Record Size */
132 #define LEAF_RECORD_SIZE (0)
133 #define SPLIT_INFO_SIZE (OR_FLOAT_SIZE + OR_INT_SIZE)
134 
137 {
138  float pivot; /* pivot = split_slot_id / num_keys */
139  int index; /* number of key insert after node split */
140 };
141 
142 typedef char *PAGE_PTR; /* Pointer to a page */
143 
144 /* TODO - PAGE_TYPE is used for debugging */
145 typedef enum
146 {
147  PAGE_UNKNOWN = 0, /* used for initialized page */
148  PAGE_FTAB, /* file allocset table page */
149  PAGE_HEAP, /* heap page */
150  PAGE_VOLHEADER, /* volume header page */
151  PAGE_VOLBITMAP, /* volume bitmap page */
152  PAGE_QRESULT, /* query result page */
153  PAGE_EHASH, /* ehash bucket/dir page */
154  PAGE_OVERFLOW, /* overflow page (with ovf_keyval) */
155  PAGE_AREA, /* area page */
156  PAGE_CATALOG, /* catalog page */
157  PAGE_BTREE, /* b+tree index page (with ovf_OIDs) */
158  PAGE_LOG, /* NONE - log page (unused) */
159  PAGE_DROPPED_FILES, /* Dropped files page. */
160  PAGE_VACUUM_DATA, /* Vacuum data. */
162 } PAGE_TYPE;
163 
164 /* Index scan OID buffer size as set by system parameter. */
165 #define ISCAN_OID_BUFFER_SIZE \
166  ((((int) (IO_PAGESIZE * prm_get_float_value (PRM_ID_BT_OID_NBUFFERS))) \
167  / OR_OID_SIZE) \
168  * OR_OID_SIZE)
169 #define ISCAN_OID_BUFFER_COUNT \
170  (ISCAN_OID_BUFFER_SIZE / OR_OID_SIZE)
171 /* Minimum capacity of OID buffer.
172  * It should include at least one overflow page and on b-tree leaf record.
173  * It was set to roughly two pages.
174  */
175 #define ISCAN_OID_BUFFER_MIN_CAPACITY (2 * DB_PAGESIZE)
176 /* OID buffer capacity. It is the maximum value between the size set by
177  * system parameter and the minimum required capacity.
178  */
179 #define ISCAN_OID_BUFFER_CAPACITY \
180  (MAX (ISCAN_OID_BUFFER_MIN_CAPACITY, ISCAN_OID_BUFFER_SIZE))
181 
182 typedef UINT64 MVCCID; /* MVCC ID */
183 
184 
185 
186 /* File structure identifiers */
187 
188 typedef struct hfid HFID; /* FILE HEAP IDENTIFIER */
189 struct hfid
190 {
191  VFID vfid; /* Volume and file identifier */
192  INT32 hpgid; /* First page identifier (the header page) */
193 };
194 #define HFID_INITIALIZER \
195  { VFID_INITIALIZER, NULL_PAGEID }
196 #define HFID_AS_ARGS(hfid) (hfid)->hpgid, VFID_AS_ARGS (&(hfid)->vfid)
197 
198 typedef struct btid BTID; /* B+tree identifier */
199 struct btid
200 {
201  VFID vfid; /* B+tree index volume identifier */
202  INT32 root_pageid; /* Root page identifier */
203 };
204 #define BTID_INITIALIZER \
205  { VFID_INITIALIZER, NULL_PAGEID }
206 #define BTID_AS_ARGS(btid) (btid)->root_pageid, VFID_AS_ARGS (&(btid)->vfid)
207 
208 typedef struct ehid EHID; /* EXTENDIBLE HASHING IDENTIFIER */
209 struct ehid
210 {
211  VFID vfid; /* Volume and Directory file identifier */
212  INT32 pageid; /* The first (root) page of the directory */
213 };
214 
215 typedef struct recdes RECDES; /* RECORD DESCRIPTOR */
216 struct recdes
217 {
218  int area_size; /* Length of the allocated area. It includes only the data field. The value is negative
219  * if data is inside buffer. For example, peeking in a slotted page. */
220  int length; /* Length of the data. Does not include the length and type fields */
221  INT16 type; /* Type of record */
222  char *data; /* The data */
223 };
224 /* Replace existing data in record at offset_to_data and size old_data_size
225  * with new_data of size new_data_size.
226  */
227 #define RECORD_REPLACE_DATA(record, offset_to_data, old_data_size, \
228  new_data_size, new_data) \
229  do \
230  { \
231  assert ((record) != NULL); \
232  assert ((record)->data != NULL); \
233  assert ((offset_to_data) >= 0 && (offset_to_data) <= (record)->length); \
234  assert ((old_data_size) >= 0 && (new_data_size) >= 0); \
235  assert ((offset_to_data) + (old_data_size) <= (record)->length); \
236  if ((old_data_size) != (new_data_size)) \
237  { \
238  /* We may need to move data inside record. */ \
239  if ((offset_to_data) + (old_data_size) < (record)->length) \
240  { \
241  /* Move data inside record. */ \
242  memmove ((record)->data + (offset_to_data) + (new_data_size), \
243  (record)->data + (offset_to_data) + (old_data_size), \
244  (record)->length - (offset_to_data) - (old_data_size)); \
245  } \
246  /* Update record length. */ \
247  (record)->length += (new_data_size) - (old_data_size); \
248  } \
249  /* Copy new data (if any). */ \
250  if ((new_data_size) > 0) \
251  { \
252  memcpy ((record)->data + (offset_to_data), new_data, new_data_size); \
253  } \
254  } \
255  while (false)
256 /* Move the data inside a record */
257 #define RECORD_MOVE_DATA(rec, dest_offset, src_offset) \
258  do { \
259  assert ((rec) != NULL && (dest_offset) >= 0 && (src_offset) >= 0); \
260  assert (((rec)->length - (src_offset)) >= 0); \
261  assert (((rec)->area_size <= 0) || ((rec)->area_size >= (rec)->length)); \
262  assert (((rec)->area_size <= 0) \
263  || (((rec)->length + ((dest_offset) - (src_offset))) \
264  <= (rec)->area_size)); \
265  if ((dest_offset) != (src_offset)) \
266  { \
267  if ((rec)->length != (src_offset)) \
268  { \
269  memmove ((rec)->data + (dest_offset), (rec)->data + (src_offset), \
270  (rec)->length - (src_offset)); \
271  (rec)->length = (rec)->length + ((dest_offset) - (src_offset)); \
272  } \
273  else \
274  { \
275  (rec)->length = (dest_offset); \
276  } \
277  } \
278  } while (false)
279 
280 typedef struct lorecdes LORECDES; /* Work area descriptor */
281 struct lorecdes
282 {
283  LOLENGTH length; /* The length of data in the area */
284  LOLENGTH area_size; /* The size of the area */
285  char *data; /* Pointer to the beginning of the area */
286 };
287 
288 #define RECDES_INITIALIZER { 0, -1, REC_UNKNOWN, NULL }
289 
290 #define HFID_SET_NULL(hfid) \
291  do { \
292  (hfid)->vfid.fileid = NULL_FILEID; \
293  (hfid)->hpgid = NULL_PAGEID; \
294  } while(0)
295 
296 #define HFID_COPY(hfid_ptr1, hfid_ptr2) *(hfid_ptr1) = *(hfid_ptr2)
297 
298 #define HFID_IS_NULL(hfid) (((hfid)->vfid.fileid == NULL_FILEID) ? 1 : 0)
299 
300 #define BTID_SET_NULL(btid) \
301  do { \
302  (btid)->vfid.fileid = NULL_FILEID; \
303  (btid)->vfid.volid = NULL_VOLID; \
304  (btid)->root_pageid = NULL_PAGEID; \
305  } while(0)
306 
307 #define BTID_COPY(btid_ptr1, btid_ptr2) *(btid_ptr1) = *(btid_ptr2)
308 
309 #define BTID_IS_NULL(btid) (((btid)->vfid.fileid == NULL_FILEID) ? 1 : 0)
310 
311 #define BTID_IS_EQUAL(b1,b2) \
312  (((b1)->vfid.fileid == (b2)->vfid.fileid) && \
313  ((b1)->vfid.volid == (b2)->vfid.volid))
314 
315 #define DISK_VOLPURPOSE DB_VOLPURPOSE
316 
317 /* Types and defines of transaction management */
318 
319 typedef int TRANID; /* Transaction identifier */
320 
321 #define NULL_TRANID (-1)
322 #define NULL_TRAN_INDEX (-1)
323 #define MVCCID_NULL (0)
324 
325 #define MVCCID_ALL_VISIBLE ((MVCCID) 3) /* visible for all transactions */
326 #define MVCCID_FIRST ((MVCCID) 4)
327 
328 /* is MVCC ID valid? */
329 #define MVCCID_IS_VALID(id) ((id) != MVCCID_NULL)
330 /* is MVCC ID normal? */
331 #define MVCCID_IS_NORMAL(id) ((id) >= MVCCID_FIRST)
332 /* are MVCC IDs equal? */
333 #define MVCCID_IS_EQUAL(id1,id2) ((id1) == (id2))
334 /* are MVCC IDs valid, not all visible? */
335 #define MVCCID_IS_NOT_ALL_VISIBLE(id) \
336  (MVCCID_IS_VALID (id) && ((id) != MVCCID_ALL_VISIBLE))
337 
338 /* advance MVCC ID */
339 #define MVCCID_FORWARD(id) \
340  do \
341  { \
342  (id)++; \
343  if ((id) < MVCCID_FIRST) \
344  (id) = MVCCID_FIRST; \
345  } \
346  while (0)
347 
348 /* back up MVCC ID */
349 #define MVCCID_BACKWARD(id) \
350  do \
351  { \
352  (id)--; \
353  } \
354  while ((id) < MVCCID_FIRST)
355 
356 
357 #define COMPOSITE_LOCK(scan_op_type) (scan_op_type != S_SELECT)
358 #define READONLY_SCAN(scan_op_type) (scan_op_type == S_SELECT)
359 
360 typedef enum
361 {
366 
367 typedef enum
368 {
369  /* Don't change the initialization since they reflect the elements of lock_Conv and lock_Comp */
370  NA_LOCK = 0, /* N/A lock */
371  INCON_NON_TWO_PHASE_LOCK = 1, /* Incompatible 2 phase lock. */
372  NULL_LOCK = 2, /* NULL LOCK */
373  SCH_S_LOCK = 3, /* Schema Stability Lock */
374  IS_LOCK = 4, /* Intention Shared lock */
375  S_LOCK = 5, /* Shared lock */
376  IX_LOCK = 6, /* Intention exclusive lock */
377  BU_LOCK = 7, /* Bulk Update Lock */
378  SIX_LOCK = 8, /* Shared and intention exclusive lock */
379  U_LOCK = 9, /* Update lock */
380  X_LOCK = 10, /* Exclusive lock */
381  SCH_M_LOCK = 11 /* Schema Modification Lock */
382 } LOCK;
383 
384 extern LOCK lock_Conv[12][12];
385 
386 #define LOCK_TO_LOCKMODE_STRING(lock) \
387  (((lock) == NULL_LOCK) ? " NULL_LOCK" : \
388  ((lock) == IS_LOCK) ? " IS_LOCK" : \
389  ((lock) == S_LOCK) ? " S_LOCK" : \
390  ((lock) == IX_LOCK) ? " IX_LOCK" : \
391  ((lock) == SIX_LOCK) ? " SIX_LOCK" : \
392  ((lock) == U_LOCK) ? " U_LOCK" : \
393  ((lock) == BU_LOCK) ? " BU_LOCK" : \
394  ((lock) == SCH_S_LOCK) ? " SCH_S_LOCK" : \
395  ((lock) == SCH_M_LOCK) ? " SCH_M_LOCK" : \
396  ((lock) == X_LOCK) ? " X_LOCK" : "UNKNOWN")
397 
398 /* CLASSNAME TO OID RETURN VALUES */
399 
400 typedef enum
401 {
409 
410 #define LC_EXIST 1
411 #define LC_DOESNOT_EXIST 2
412 #define LC_ERROR 3
413 
414 /* Enumeration type for the result of ehash_search function */
415 typedef enum
416 {
420 } EH_SEARCH;
421 
422 /* BTREE_SEARCH - Result for b-tree key or OID search. */
423 typedef enum
424 {
425  BTREE_KEY_FOUND, /* Found key (one visible or dirty version). */
426  BTREE_KEY_NOTFOUND, /* Key was not found (or no usable version found in key). */
427  BTREE_ERROR_OCCURRED, /* Error while searching key/OID. */
428  BTREE_ACTIVE_KEY_FOUND, /* Found key but the version inserter/deleter did not commit/abort. */
429  BTREE_KEY_SMALLER, /* Key was not found and it is smaller than all the keys it was compared to. */
430  BTREE_KEY_BIGGER, /* Key was not found and it is bigger than all the keys it was compared to. */
431  BTREE_KEY_BETWEEN /* Key was not found and it's value is between the smallest and the biggest keys it was
432  * compared to. */
433 } BTREE_SEARCH;
434 
435 
436 
437 /* Magic default values */
438 #define CUBRID_MAGIC_MAX_LENGTH 25
439 #define CUBRID_MAGIC_PREFIX "CUBRID/"
440 #define CUBRID_MAGIC_DATABASE_VOLUME "CUBRID/Volume"
441 #define CUBRID_MAGIC_LOG_ACTIVE "CUBRID/LogActive"
442 #define CUBRID_MAGIC_LOG_ARCHIVE "CUBRID/LogArchive"
443 #define CUBRID_MAGIC_LOG_INFO "CUBRID/LogInfo"
444 #define CUBRID_MAGIC_DATABASE_BACKUP "CUBRID/Backup_v2"
445 #define CUBRID_MAGIC_DATABASE_BACKUP_OLD "CUBRID/Backup"
446 #define CUBRID_MAGIC_KEYS "CUBRID/Keys"
447 
448 /*
449  * Typedefs related to the scan data structures
450  */
451 
452 typedef enum
453 {
454  S_OPENED = 1,
458 } SCAN_STATUS;
459 
460 typedef enum
461 {
465 
466 typedef enum
467 {
468  S_BEFORE = 1,
471 } SCAN_POSITION;
472 
473 typedef enum
474 {
475  S_ERROR = -1,
476  S_END = 0,
478  S_SUCCESS_CHN_UPTODATE, /* only for slotted page */
479  S_DOESNT_FIT, /* only for slotted page */
480  S_DOESNT_EXIST, /* only for slotted page */
482 } SCAN_CODE;
483 
484 typedef enum
485 {
486  S_SELECT, /* By default MVCC requires no locks for select operations. */
487  S_SELECT_WITH_LOCK, /* Read operation that doesn't plan to modify the object, but has to know the exact
488  * fate of last version. Can be used for foreign key and unique constraint checks. */
489  S_DELETE, /* Delete object operation. */
490  S_UPDATE /* Update object operation. */
492 
493 #define IS_WRITE_EXCLUSIVE_LOCK(lock) ((lock) == X_LOCK || (lock) == SCH_M_LOCK)
494 
495 
496 typedef enum
497 {
511 
512  /* leave this last */
514 
517 
518 typedef enum
519 {
533 
534  /* leave this last */
536 
539 
540 typedef enum
541 {
551 
552  /* leave this last */
555 
556 typedef enum
557 {
565 
566  /* leave this last */
569 
570 typedef enum
571 {
572  LOG_ERROR_IF_DELETED, /* set error when locking deleted objects */
573  LOG_WARNING_IF_DELETED /* set warning when locking deleted objects - the case when it is expected and
574  * accepted to find a deleted object; for example when er_clear() is used afterwards if
575  * ER_HEAP_UNKNOWN_OBJECT is set in er_errid */
577 
578 /************************************************************************/
579 /* spacedb */
580 /************************************************************************/
581 
582 /* database space info */
583 typedef enum
584 {
588 
592 
593 typedef struct spacedb_all SPACEDB_ALL;
595 {
599 };
600 
603 {
609  char name[DB_MAX_PATH_LENGTH];
610 };
611 
612 /* files */
613 typedef enum
614 {
619 
623 
626 {
627  int nfile;
631 };
632 
633 /************************************************************************/
634 /* client & catalog common */
635 /************************************************************************/
636 
637 typedef int REPR_ID; /* representation identifier */
638 typedef int ATTR_ID; /* attribute identifier */
639 
640 #define NULL_REPRID -1 /* Null Representation Identifier */
641 #define NULL_ATTRID -1 /* Null Attribute Identifier */
642 
643 /************************************************************************/
644 /* b-tree common */
645 /************************************************************************/
646 
647 typedef enum
648 {
652 
653 typedef enum
654 {
661 } BTREE_TYPE;
662 
663 /************************************************************************/
664 /* storage common functions */
665 /************************************************************************/
666 extern INT16 db_page_size (void);
667 extern INT16 db_io_page_size (void);
668 extern INT16 db_log_page_size (void);
669 extern int db_set_page_size (INT16 io_page_size, INT16 log_page_size);
670 extern INT16 db_network_page_size (void);
671 extern void db_print_data (DB_TYPE type, DB_DATA * data, FILE * fd);
672 
673 extern int recdes_allocate_data_area (RECDES * rec, int size);
674 extern void recdes_free_data_area (RECDES * rec);
675 extern void recdes_set_data_area (RECDES * rec, char *data, int size);
676 
677 extern char *oid_to_string (char *buf, int buf_size, OID * oid);
678 extern char *vpid_to_string (char *buf, int buf_size, VPID * vpid);
679 extern char *vfid_to_string (char *buf, int buf_size, VFID * vfid);
680 extern char *hfid_to_string (char *buf, int buf_size, HFID * hfid);
681 extern char *btid_to_string (char *buf, int buf_size, BTID * btid);
682 
683 /************************************************************************/
684 /* next has nothing to do with storage. however, we lack a clear place */
685 /* for global stuff that affect everything. this is closest... */
686 /************************************************************************/
687 
688 typedef enum
689 {
889 } OPERATOR_TYPE; /* arithmetic operator types */
890 
891 typedef enum
892 {
893  /* aggregate functions */
909  /* only aggregate functions should be below PT_TOP_AGG_FUNC */
910 
911  /* analytic only functions */
913 
914  /* foreign functions */
916 
917  /* from here down are function code common to parser and xasl */
918  /* "table" functions argument(s) are tables */
922 
923  /* "normal" functions, arguments are values */
929 
931 
933 
934  /* only for FIRST_VALUE. LAST_VALUE, NTH_VALUE analytic functions */
936  /* aggregate and analytic functions */
942 } FUNC_TYPE;
943 
944 #ifdef __cplusplus
945 extern "C"
946 {
947 #endif // c++
948  const char *fcode_get_lowercase_name (FUNC_TYPE ftype);
949  const char *fcode_get_uppercase_name (FUNC_TYPE ftype);
950 #ifdef __cplusplus
951 }
952 #endif // c++
953 
954 /************************************************************************/
955 /* QUERY */
956 /************************************************************************/
957 
958 #define CACHE_TIME_AS_ARGS(ct) (ct)->sec, (ct)->usec
959 
960 #define CACHE_TIME_EQ(T1, T2) \
961  (((T1)->sec != 0) && ((T1)->sec == (T2)->sec) && ((T1)->usec == (T2)->usec))
962 
963 #define CACHE_TIME_RESET(T) \
964  do \
965  { \
966  (T)->sec = 0; \
967  (T)->usec = 0; \
968  } \
969  while (0)
970 
971 #define CACHE_TIME_MAKE(CT, TV) \
972  do \
973  { \
974  (CT)->sec = (TV)->tv_sec; \
975  (CT)->usec = (TV)->tv_usec; \
976  } \
977  while (0)
978 
979 #define OR_CACHE_TIME_SIZE (OR_INT_SIZE * 2)
980 
981 #define OR_PACK_CACHE_TIME(PTR, T) \
982  do \
983  { \
984  if ((CACHE_TIME *) (T) != NULL) \
985  { \
986  PTR = or_pack_int (PTR, (T)->sec); \
987  PTR = or_pack_int (PTR, (T)->usec); \
988  } \
989  else \
990  { \
991  PTR = or_pack_int (PTR, 0); \
992  PTR = or_pack_int (PTR, 0); \
993  } \
994  } \
995  while (0)
996 
997 #define OR_UNPACK_CACHE_TIME(PTR, T) \
998  do \
999  { \
1000  if ((CACHE_TIME *) (T) != NULL) \
1001  { \
1002  PTR = or_unpack_int (PTR, &((T)->sec)); \
1003  PTR = or_unpack_int (PTR, &((T)->usec)); \
1004  } \
1005  } \
1006  while (0)
1007 
1008 /* XASL identifier */
1009 typedef struct xasl_id XASL_ID;
1010 struct xasl_id
1011 {
1012  SHA1Hash sha1; /* SHA-1 hash generated from query string. */
1013  INT32 cache_flag;
1014  /* Multiple-purpose field used to handle XASL cache. */
1015  CACHE_TIME time_stored; /* when this XASL plan stored */
1016 }; /* XASL plan file identifier */
1017 
1018 typedef enum
1019 {
1020  Q_DISTINCT, /* no duplicate values */
1021  Q_ALL /* all values */
1022 } QUERY_OPTIONS;
1023 
1024 typedef enum
1025 {
1026  R_KEY = 1, /* key value search */
1027  R_RANGE, /* range search with the two key values and range spec */
1028  R_KEYLIST, /* a list of key value searches */
1029  R_RANGELIST /* a list of range searches */
1030 } RANGE_TYPE;
1031 
1032 typedef enum
1033 {
1057 
1058  /* append the new show statement types in here */
1059 
1061 } SHOWSTMT_TYPE;
1062 
1063 #define NUM_F_GENERIC_ARGS 32
1064 #define NUM_F_INSERT_SUBSTRING_ARGS 4
1065 
1066 extern const int SM_MAX_STRING_LENGTH;
1067 
1068 /*
1069  * These are the names for the system defined properties on classes,
1070  * attributes and methods. For the built in properties, try
1071  * to use short names. User properties if they are ever allowed
1072  * should have more descriptive names.
1073  *
1074  * Lets adopt the convention that names beginning with a '*' are
1075  * reserved for system properties.
1076  */
1077 #define SM_PROPERTY_UNIQUE "*U"
1078 #define SM_PROPERTY_INDEX "*I"
1079 #define SM_PROPERTY_NOT_NULL "*N"
1080 #define SM_PROPERTY_REVERSE_UNIQUE "*RU"
1081 #define SM_PROPERTY_REVERSE_INDEX "*RI"
1082 #define SM_PROPERTY_VID_KEY "*V_KY"
1083 #define SM_PROPERTY_PRIMARY_KEY "*P"
1084 #define SM_PROPERTY_FOREIGN_KEY "*FK"
1085 
1086 #define SM_PROPERTY_NUM_INDEX_FAMILY 6
1087 
1088 #define SM_FILTER_INDEX_ID "*FP*"
1089 #define SM_FUNCTION_INDEX_ID "*FI*"
1090 #define SM_PREFIX_INDEX_ID "*PLID*"
1091 
1092 /*
1093  * Bit field identifiers for attribute flags. These could be defined
1094  * with individual unsigned bit fields but this makes it easier
1095  * to save them as a single integer.
1096  * The "new" flag is used only at run time and shouldn't be here.
1097  * Need to re-design the template functions to operate from a different
1098  * memory structure during flattening.
1099  */
1100 typedef enum
1101 {
1103  SM_ATTFLAG_INDEX = 1, /* attribute has an index 0x01 */
1104  SM_ATTFLAG_UNIQUE = 2, /* attribute has UNIQUE constraint 0x02 */
1105  SM_ATTFLAG_NON_NULL = 4, /* attribute has NON_NULL constraint 0x04 */
1106  SM_ATTFLAG_VID = 8, /* attribute is part of virtual object id 0x08 */
1107  SM_ATTFLAG_NEW = 16, /* is a new attribute 0x10 */
1108  SM_ATTFLAG_REVERSE_INDEX = 32, /* attribute has a reverse index 0x20 */
1109  SM_ATTFLAG_REVERSE_UNIQUE = 64, /* attribute has a reverse unique 0x40 */
1110  SM_ATTFLAG_PRIMARY_KEY = 128, /* attribute has a primary key 0x80 */
1111  SM_ATTFLAG_AUTO_INCREMENT = 256, /* auto increment attribute 0x0100 */
1112  SM_ATTFLAG_FOREIGN_KEY = 512, /* attribute has a primary key 0x200 */
1113  SM_ATTFLAG_PARTITION_KEY = 1024 /* attribute is the partitioning key for the class 0x400 */
1115 
1116 /* delete or update action type for foreign key */
1117 typedef enum
1118 {
1124 
1125 /*
1126  * These identify "namespaces" for class components like attributes
1127  * and methods. A name_space identifier is frequently used
1128  * in conjunction with a name so the correct component can be found
1129  * in a class definition. Since the namespaces for classes and
1130  * instances can overlap, a name alone is not enough to uniquely
1131  * identify a component.
1132  */
1133 typedef enum
1134 {
1140  ID_INSTANCE, /* attributes/shared attributes/methods */
1141  ID_CLASS, /* class methods/class attributes */
1143 } SM_NAME_SPACE;
1144 
1145 /*
1146  * This constant defines the maximum size in bytes of a class name,
1147  * attribute name, method name, or any other named entity in the schema.
1148  */
1149 #define SM_MAX_IDENTIFIER_LENGTH 255
1150 
1151 #define SERIAL_ATTR_NAME "name"
1152 #define SERIAL_ATTR_OWNER "owner"
1153 #define SERIAL_ATTR_CURRENT_VAL "current_val"
1154 #define SERIAL_ATTR_INCREMENT_VAL "increment_val"
1155 #define SERIAL_ATTR_MAX_VAL "max_val"
1156 #define SERIAL_ATTR_MIN_VAL "min_val"
1157 #define SERIAL_ATTR_CYCLIC "cyclic"
1158 #define SERIAL_ATTR_STARTED "started"
1159 #define SERIAL_ATTR_CLASS_NAME "class_name"
1160 #define SERIAL_ATTR_ATT_NAME "att_name"
1161 #define SERIAL_ATTR_CACHED_NUM "cached_num"
1162 #define SERIAL_ATTR_COMMENT "comment"
1163 
1164 static const bool PEEK = true; /* Peek for a slotted record */
1165 static const bool COPY = false; /* Don't peek, but copy a slotted record */
1166 
1167 enum
1168 {
1169 /* Unknown record type */
1171 
1172 /* Record without content, just the address */
1174 
1175 /* Home of record */
1177 
1178 /* No the original home of record. part of relocation process */
1180 
1181 /* Record describe new home of record */
1183 
1184 /* Record describe location of big record */
1186 
1187 /* Slot does not describe any record.
1188  * A record was stored in this slot. Slot cannot be reused.
1189  */
1191 
1192 /* Slot does not describe any record.
1193  * A record was stored in this slot. Slot will be reused.
1194  */
1196 
1197 /* unused reserved record type */
1206 /* 4bit record type max */
1209 };
1210 
1213 {
1214  const char *path; /* Directory where the volume extension is created. If NULL, is given, it defaults to
1215  * the system parameter. */
1216  const char *name; /* Name of the volume extension If NULL, system generates one like "db".ext"volid"
1217  * where "db" is the database name and "volid" is the volume identifier to be assigned
1218  * to the volume extension. */
1219  const char *comments; /* Comments which are included in the volume extension header. */
1220  int max_npages; /* Maximum pages of this volume */
1221  int extend_npages; /* Number of pages to extend - used for generic volume only */
1222  INT32 nsect_total; /* DKNSECTS type, number of sectors for volume extension */
1223  INT32 nsect_max; /* DKNSECTS type, maximum number of sectors for volume extension */
1224  int max_writesize_in_sec; /* the amount of volume written per second */
1225  DB_VOLPURPOSE purpose; /* The purpose of the volume extension. One of the following: -
1226  * DB_PERMANENT_DATA_PURPOSE, DB_TEMPORARY_DATA_PURPOSE */
1227  DB_VOLTYPE voltype; /* Permanent of temporary volume type */
1229 };
1230 
1231 #define SERVER_SESSION_KEY_SIZE 8
1232 
1233 typedef enum
1234 {
1239 
1240 typedef enum
1241 {
1246 
1247 // TODO: move me in a proper place
1248 typedef enum
1249 {
1252 } KILLSTMT_TYPE;
1253 
1254 // query module
1255 typedef enum
1256 {
1257  HS_NONE = 0, /* no hash aggregation */
1258  HS_ACCEPT_ALL, /* accept tuples in hash table */
1259  HS_REJECT_ALL /* reject tuples, use normal sort-based aggregation */
1261 
1262 #endif /* _STORAGE_COMMON_H_ */
char * PAGE_PTR
Definition: sha1.h:50
char * vpid_to_string(char *buf, int buf_size, VPID *vpid)
int area_size
SCAN_CODE
INT32 pageid
int TRANID
RANGE_TYPE
SHA1Hash sha1
PAGEID FILEID
INT32 LOLENGTH
PAGEID DKNPAGES
INT32 SECTID
DB_TYPE
Definition: dbtype_def.h:670
BTREE_TYPE
SM_FOREIGN_KEY_ACTION
DKNPAGES npage_used
PAGEID LOG_PHY_PAGEID
FUNC_TYPE
INT16 VOLID
SM_NAME_SPACE
KILLSTMT_TYPE
char * data
INT32 root_pageid
void recdes_set_data_area(RECDES *rec, char *data, int size)
INT32 hpgid
INT16 db_log_page_size(void)
void recdes_free_data_area(RECDES *rec)
PAGE_TYPE
SHOWSTMT_TYPE
static const bool PEEK
INT16 db_page_size(void)
const int SM_MAX_STRING_LENGTH
Definition: class_object.c:69
SM_ATTRIBUTE_FLAG
VOLID DKNVOLS
int ATTR_ID
LOCK
BTREE_NODE_INFO_ID
char * vfid_to_string(char *buf, int buf_size, VFID *vfid)
NON_EXISTENT_HANDLING
const char * fcode_get_lowercase_name(FUNC_TYPE ftype)
SCAN_STATUS
HEAP_PAGE_INFO_ID
INT16 db_io_page_size(void)
OPERATOR_TYPE
int db_set_page_size(INT16 io_page_size, INT16 log_page_size)
CACHE_TIME time_stored
char * hfid_to_string(char *buf, int buf_size, HFID *hfid)
PGSLOTID PGNSLOTS
LOLENGTH length
const char * fcode_get_uppercase_name(FUNC_TYPE ftype)
BTREE_SEARCH
SPACEDB_ALL_TYPE
char * data
DB_VOLTYPE type
DKNPAGES npage_used
#define DB_MAX_PATH_LENGTH
VFID vfid
AGGREGATE_HASH_STATE
INT64 LOG_PAGEID
UINT64 MVCCID
VFID vfid
DKNPAGES npage_user
SCAN_POSITION
LC_FIND_CLASSNAME
char * oid_to_string(char *buf, int buf_size, OID *oid)
BTREE_CONSTRAINT_TYPE
SCAN_OPERATION_TYPE
VFID vfid
LOCK_COMPATIBILITY
DB_PARTITION_TYPE
DB_VOLPURPOSE
Definition: dbtype_def.h:185
EH_SEARCH
static const bool COPY
BTREE_KEY_INFO_ID
DB_VOLTYPE
Definition: dbtype_def.h:192
INT16 PGLENGTH
DKNPAGES npage_reserved
INT16 PGSLOTID
HEAP_RECORD_INFO_ID
int recdes_allocate_data_area(RECDES *rec, int size)
DKNPAGES npage_free
INT32 cache_flag
LOCK lock_Conv[12][12]
Definition: lock_table.c:179
void db_print_data(DB_TYPE type, DB_DATA *data, FILE *fd)
int REPR_ID
INT16 db_network_page_size(void)
DKNPAGES npage_ftab
INT16 type
const char * comments
DKNPAGES npage_free
INT32 PAGEID
DB_VOLPURPOSE purpose
SPACEDB_FILE_TYPE
LOLENGTH area_size
SECTID DKNSECTS
SCAN_DIRECTION
char * btid_to_string(char *buf, int buf_size, BTID *btid)
DB_CLASS_PARTITION_TYPE
DB_VOLPURPOSE purpose
QUERY_OPTIONS