CUBRID Engine  latest
statistics.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  * STATISTICS.h -
22  */
23 
24 #ifndef _STATISTICS_H_
25 #define _STATISTICS_H_
26 
27 #ident "$Id$"
28 
29 #include <stdio.h>
30 #include "dbtype_def.h"
31 #include "storage_common.h"
32 #include "object_domain.h"
33 
34 #define STATS_WITH_FULLSCAN true
35 #define STATS_WITH_SAMPLING false
36 
37 #define STATS_SAMPLING_THRESHOLD 50 /* sampling trial count */
38 #define STATS_SAMPLING_LEAFS_MAX 8 /* sampling leaf pages */
39 
40 /* disk-resident elements of pkeys[] field */
41 #define BTREE_STATS_PKEYS_NUM 8
42 #define BTREE_STATS_RESERVED_NUM 4
43 
44 #define STATS_MIN_MAX_SIZE sizeof(DB_DATA)
45 
46 /* free_and_init routine */
47 #define stats_free_statistics_and_init(stats) \
48  do \
49  { \
50  stats_free_statistics ((stats)); \
51  (stats) = NULL; \
52  } \
53  while (0)
54 
55 /* B+tree statistical information */
56 typedef struct btree_stats BTREE_STATS;
58 {
60  int leafs; /* number of leaf pages including overflow pages */
61  int pages; /* number of total pages */
62  int height; /* the height of the B+tree */
63  int keys; /* number of keys */
64  int has_function; /* is a function index */
65  TP_DOMAIN *key_type; /* The key type for the B+tree */
66  int pkeys_size; /* pkeys array size */
67  int *pkeys; /* partial keys info for example: index (a, b, ..., x) pkeys[0] -> # of {a} pkeys[1] ->
68  * # of {a, b} ... pkeys[pkeys_size-1] -> # of {a, b, ..., x} */
69 #if 0 /* reserved for future use */
70  int reserved[BTREE_STATS_RESERVED_NUM];
71 #endif
72 };
73 
74 /* Statistical Information about the attribute */
75 typedef struct attr_stats ATTR_STATS;
76 struct attr_stats
77 {
78  int id;
80  int n_btstats; /* number of B+tree statistics information */
81  BTREE_STATS *bt_stats; /* pointer to array of BTREE_STATS[n_btstats] */
82 };
83 
84 /* Statistical Information about the class */
85 typedef struct class_stats CLASS_STATS;
87 {
88  unsigned int time_stamp; /* the time stamped when the stat info updated; used to get up-to-date stat info */
89  int heap_num_objects; /* cardinality of the class; number of instances the class has */
90  int heap_num_pages; /* number of pages the class occupy */
91  int n_attrs; /* number of attributes; size of the attr_stats[] */
92  ATTR_STATS *attr_stats; /* pointer to the array of attribute statistics */
93 };
94 
95 #if !defined(SERVER_MODE)
96 extern int stats_get_statistics (OID * classoid, unsigned int timestamp, CLASS_STATS ** stats_p);
97 extern void stats_free_statistics (CLASS_STATS * stats);
98 extern void stats_dump (const char *classname, FILE * fp);
99 #endif /* !SERVER_MODE */
100 
101 #endif /* _STATISTICS_H_ */
#define BTREE_STATS_RESERVED_NUM
Definition: statistics.h:42
DB_TYPE
Definition: dbtype_def.h:670
int n_btstats
Definition: statistics.h:80
int pkeys_size
Definition: statistics.h:66
TP_DOMAIN * key_type
Definition: statistics.h:65
void stats_dump(const char *classname, FILE *fp)
int * pkeys
Definition: statistics.h:67
void stats_free_statistics(CLASS_STATS *stats)
int stats_get_statistics(OID *classoid, unsigned int timestamp, CLASS_STATS **stats_p)
Definition: statistics_cl.c:54
unsigned int time_stamp
Definition: statistics.h:88
BTREE_STATS * bt_stats
Definition: statistics.h:81
int has_function
Definition: statistics.h:64
int heap_num_pages
Definition: statistics.h:90
int heap_num_objects
Definition: statistics.h:89
ATTR_STATS * attr_stats
Definition: statistics.h:92
DB_TYPE type
Definition: statistics.h:79