CUBRID Engine  latest
xasl_cache.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  * XASL cache.
21  */
22 
23 #ifndef _XASL_CACHE_H_
24 #define _XASL_CACHE_H_
25 
26 #ident "$Id$"
27 
28 #if !defined (SERVER_MODE) && !defined (SA_MODE)
29 #error Belongs to server module
30 #endif /* !defined (SERVER_MODE) && !defined (SA_MODE) */
31 
32 #include "xasl.h"
33 
34 // forward definitions
35 struct compile_context;
36 struct xasl_unpack_info;
37 
38 /* Objects related to XASL cache entries. The information includes the object OID, the lock required to use the XASL
39  * cache entry and the heap file cardinality.
40  * Objects can be classes or serials. The heap file cardinality is only relevant for classes.
41  */
44 {
47  int tcard;
48 };
49 
51 {
52  XCACHE_CLEANUP_NONE, /* no cleanup is required */
55 };
57 
58 /* XASL cache clones - XASL nodes cached for fast usage.
59  *
60  */
61 typedef struct xasl_clone XASL_CLONE;
62 struct xasl_clone
63 {
66 };
67 #define XASL_CLONE_INITIALIZER { NULL, NULL }
68 #define XASL_CLONE_AS_ARGS(clone) (clone)->xasl, (clone)->xasl_buf
69 
70 /*
71  * EXECUTION_INFO: query strings: user text, hash string and dumped plan.
72  */
75 {
76  char *sql_hash_text; /* rewritten query string which is used as hash key */
77  char *sql_user_text; /* original query statement that user input */
78  char *sql_plan_text; /* plans for this query */
79 };
80 #define EXEINFO_HASH_TEXT_STRING(einfo) ((einfo)->sql_hash_text ? (einfo)->sql_hash_text : "UNKNOWN HASH TEXT")
81 #define EXEINFO_USER_TEXT_STRING(einfo) ((einfo)->sql_user_text ? (einfo)->sql_user_text : "UNKNOWN USER TEXT")
82 #define EXEINFO_PLAN_TEXT_STRING(einfo) ((einfo)->sql_plan_text ? (einfo)->sql_plan_text : "UNKNOWN PLAN TEXT")
83 
84 #define EXEINFO_AS_ARGS(einfo) \
85  EXEINFO_USER_TEXT_STRING(einfo), EXEINFO_PLAN_TEXT_STRING(einfo), EXEINFO_HASH_TEXT_STRING(einfo)
86 
87 /* This really belongs more to the query manager rather than query executor. */
88 /* XASL cache entry type definition */
91 {
92  XASL_ID xasl_id; /* XASL file identifier */
93  /* Not really a file identifier anymore. Maybe we should rename this to XASL_KEY? */
94  XASL_STREAM stream; /* XASL packed stream. */
95 
96  /* Latch-free stuff. */
97  XASL_CACHE_ENTRY *stack; /* used in freelist */
98  XASL_CACHE_ENTRY *next; /* used in hash table */
99  /* Mutex may be addex here (hopefully it is not necessary). */
100  UINT64 del_id; /* delete transaction ID (for lock free) */
101 
102 
103  EXECUTION_INFO sql_info; /* cache entry hash key, user input string & plan */
104  int xasl_header_flag; /* XASL header info */
105  XCACHE_RELATED_OBJECT *related_objects; /* List of objects referenced by XASL cache entry.
106  * Objects can be:
107  * 1. classes
108  * 2. serials
109  */
110  int n_related_objects; /* size of the related_objects */
111  struct timeval time_last_used; /* when this entry used lastly */
112  INT64 ref_count; /* how many times this entry used */
113  INT64 clr_count; /* how many times related qfile caches are clear */
114  int list_ht_no; /* memory hash table for query result(list file) cache generated by this XASL
115  * referencing by DB_VALUE parameters bound to the result */
116  bool free_data_on_uninit; /* set to free entry data on uninit. */
117 
118  /* Cache clones */
123  pthread_mutex_t cache_clones_mutex;
124 
125  /* RT check */
127 
129 
130  // *INDENT-OFF*
131  xasl_cache_ent ();
132  ~xasl_cache_ent ();
133 
134  void init_clone_cache ();
135  // *INDENT-ON*
136 };
137 
139 {
142 
144 };
146 
148 {
152 };
153 
154 extern int xcache_initialize (THREAD_ENTRY * thread_p);
155 extern void xcache_finalize (THREAD_ENTRY * thread_p);
156 
157 extern int xcache_find_sha1 (THREAD_ENTRY * thread_p, const SHA1Hash * sha1, const XASL_CACHE_SEARCH_MODE search_mode,
158  XASL_CACHE_ENTRY ** xcache_entry, xasl_cache_rt_check_result * rt_check);
159 extern int xcache_find_xasl_id_for_execute (THREAD_ENTRY * thread_p, const XASL_ID * xid,
160  XASL_CACHE_ENTRY ** xcache_entry, XASL_CLONE * xclone);
161 extern void xcache_unfix (THREAD_ENTRY * thread_p, XASL_CACHE_ENTRY * xcache_entry);
162 extern int xcache_insert (THREAD_ENTRY * thread_p, const compile_context * context, XASL_STREAM * stream,
163  int n_oid, const OID * class_oids, const int *class_locks,
164  const int *tcards, XASL_CACHE_ENTRY ** xcache_entry);
165 extern void xcache_remove_by_oid (THREAD_ENTRY * thread_p, const OID * oid);
166 extern void xcache_drop_all (THREAD_ENTRY * thread_p);
167 extern void xcache_dump (THREAD_ENTRY * thread_p, FILE * fp);
168 
169 extern bool xcache_can_entry_cache_list (XASL_CACHE_ENTRY * xcache_entry);
170 
171 extern void xcache_retire_clone (THREAD_ENTRY * thread_p, XASL_CACHE_ENTRY * xcache_entry, XASL_CLONE * xclone);
172 extern int xcache_get_entry_count (void);
173 extern bool xcache_uses_clones (void);
174 
175 extern int xcache_invalidate_qcaches (THREAD_ENTRY * thread_p, const OID * oid);
176 
177 #endif /* _XASL_CACHE_H_ */
Definition: sha1.h:50
bool xcache_uses_clones(void)
Definition: xasl_cache.c:2468
xcache_cleanup_reason
Definition: xasl_cache.h:50
XCACHE_RELATED_OBJECT * related_objects
Definition: xasl_cache.h:105
void xcache_drop_all(THREAD_ENTRY *thread_p)
Definition: xasl_cache.c:1890
char * sql_plan_text
Definition: xasl_cache.h:78
void xcache_retire_clone(THREAD_ENTRY *thread_p, XASL_CACHE_ENTRY *xcache_entry, XASL_CLONE *xclone)
Definition: xasl_cache.c:2040
XASL_CACHE_ENTRY * next
Definition: xasl_cache.h:98
int xcache_find_sha1(THREAD_ENTRY *thread_p, const SHA1Hash *sha1, const XASL_CACHE_SEARCH_MODE search_mode, XASL_CACHE_ENTRY **xcache_entry, xasl_cache_rt_check_result *rt_check)
Definition: xasl_cache.c:791
XASL_CACHE_ENTRY * stack
Definition: xasl_cache.h:97
xasl_cache_rt_check_result
Definition: xasl_cache.h:147
XASL_CLONE * cache_clones
Definition: xasl_cache.h:119
XASL_CLONE one_clone
Definition: xasl_cache.h:120
void xcache_remove_by_oid(THREAD_ENTRY *thread_p, const OID *oid)
Definition: xasl_cache.c:1869
int xcache_initialize(THREAD_ENTRY *thread_p)
Definition: xasl_cache.c:280
enum xcache_cleanup_reason XCACHE_CLEANUP_REASON
Definition: xasl_cache.h:56
int xcache_insert(THREAD_ENTRY *thread_p, const compile_context *context, XASL_STREAM *stream, int n_oid, const OID *class_oids, const int *class_locks, const int *tcards, XASL_CACHE_ENTRY **xcache_entry)
Definition: xasl_cache.c:1350
int xcache_find_xasl_id_for_execute(THREAD_ENTRY *thread_p, const XASL_ID *xid, XASL_CACHE_ENTRY **xcache_entry, XASL_CLONE *xclone)
Definition: xasl_cache.c:888
void THREAD_ENTRY
xasl_cache_search_mode
Definition: xasl_cache.h:138
XASL_NODE * xasl
Definition: xasl_cache.h:65
XASL_STREAM stream
Definition: xasl_cache.h:94
LOCK
int xasl_header_flag
Definition: xasl_cache.h:104
int xcache_get_entry_count(void)
Definition: xasl_cache.c:2457
int xcache_invalidate_qcaches(THREAD_ENTRY *thread_p, const OID *oid)
Definition: xasl_cache.c:1689
INT64 time_last_rt_check
Definition: xasl_cache.h:126
void xcache_dump(THREAD_ENTRY *thread_p, FILE *fp)
Definition: xasl_cache.c:1911
bool xcache_can_entry_cache_list(XASL_CACHE_ENTRY *xcache_entry)
Definition: xasl_cache.c:2004
bool free_data_on_uninit
Definition: xasl_cache.h:116
XASL_ID xasl_id
Definition: xasl_cache.h:92
EXECUTION_INFO sql_info
Definition: xasl_cache.h:103
int n_related_objects
Definition: xasl_cache.h:110
char * sql_hash_text
Definition: xasl_cache.h:76
enum xasl_cache_search_mode XASL_CACHE_SEARCH_MODE
Definition: xasl_cache.h:145
int cache_clones_capacity
Definition: xasl_cache.h:122
void xcache_finalize(THREAD_ENTRY *thread_p)
Definition: xasl_cache.c:344
xasl_unpack_info * xasl_buf
Definition: xasl_cache.h:64
char * sql_user_text
Definition: xasl_cache.h:77
pthread_mutex_t cache_clones_mutex
Definition: xasl_cache.h:123
void xcache_unfix(THREAD_ENTRY *thread_p, XASL_CACHE_ENTRY *xcache_entry)
Definition: xasl_cache.c:1083