MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pars0sym.cc
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #include "pars0sym.h"
27 
28 #ifdef UNIV_NONINL
29 #include "pars0sym.ic"
30 #endif
31 
32 #include "mem0mem.h"
33 #include "data0type.h"
34 #include "data0data.h"
35 #include "pars0grm.h"
36 #include "pars0pars.h"
37 #include "que0que.h"
38 #include "eval0eval.h"
39 #include "row0sel.h"
40 
41 /******************************************************************/
44 UNIV_INTERN
45 sym_tab_t*
47 /*===========*/
48  mem_heap_t* heap)
49 {
50  sym_tab_t* sym_tab;
51 
52  sym_tab = static_cast<sym_tab_t*>(
53  mem_heap_alloc(heap, sizeof(sym_tab_t)));
54 
55  UT_LIST_INIT(sym_tab->sym_list);
56  UT_LIST_INIT(sym_tab->func_node_list);
57 
58  sym_tab->heap = heap;
59 
60  return(sym_tab);
61 }
62 
63 
64 /******************************************************************/
68 UNIV_INTERN
69 void
71 /*=================*/
72  sym_tab_t* sym_tab)
73 {
74  sym_node_t* sym;
75  func_node_t* func;
76 
77  ut_ad(mutex_own(&dict_sys->mutex));
78 
79  for (sym = UT_LIST_GET_FIRST(sym_tab->sym_list);
80  sym != NULL;
81  sym = UT_LIST_GET_NEXT(sym_list, sym)) {
82 
83  /* Close the tables opened in pars_retrieve_table_def(). */
84 
85  if (sym->token_type == SYM_TABLE_REF_COUNTED) {
86 
87  dict_table_close(sym->table, TRUE, FALSE);
88 
89  sym->table = NULL;
90  sym->resolved = FALSE;
91  sym->token_type = SYM_UNSET;
92  }
93 
95 
96  if (sym->prefetch_buf) {
98  }
99 
100  if (sym->cursor_def) {
102  }
103  }
104 
105  for (func = UT_LIST_GET_FIRST(sym_tab->func_node_list);
106  func != NULL;
107  func = UT_LIST_GET_NEXT(func_node_list, func)) {
108 
110  }
111 }
112 
113 /******************************************************************/
116 UNIV_INTERN
117 sym_node_t*
119 /*================*/
120  sym_tab_t* sym_tab,
121  ulint val)
122 {
123  sym_node_t* node;
124  byte* data;
125 
126  node = static_cast<sym_node_t*>(
127  mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
128 
129  node->common.type = QUE_NODE_SYMBOL;
130 
131  node->table = NULL;
132  node->resolved = TRUE;
133  node->token_type = SYM_LIT;
134 
135  node->indirection = NULL;
136 
137  dtype_set(dfield_get_type(&node->common.val), DATA_INT, 0, 4);
138 
139  data = static_cast<byte*>(mem_heap_alloc(sym_tab->heap, 4));
140  mach_write_to_4(data, val);
141 
142  dfield_set_data(&(node->common.val), data, 4);
143 
144  node->common.val_buf_size = 0;
145  node->prefetch_buf = NULL;
146  node->cursor_def = NULL;
147 
148  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
149 
150  node->like_node = NULL;
151 
152  node->sym_table = sym_tab;
153 
154  return(node);
155 }
156 
157 /******************************************************************/
160 UNIV_INTERN
161 sym_node_t*
163 /*================*/
164  sym_tab_t* sym_tab,
165  const byte* str,
167  ulint len)
168 {
169  sym_node_t* node;
170  byte* data;
171 
172  node = static_cast<sym_node_t*>(
173  mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
174 
175  node->common.type = QUE_NODE_SYMBOL;
176 
177  node->table = NULL;
178  node->resolved = TRUE;
179  node->token_type = SYM_LIT;
180 
181  node->indirection = NULL;
182 
183  dtype_set(dfield_get_type(&node->common.val),
184  DATA_VARCHAR, DATA_ENGLISH, 0);
185 
186  data = (len) ? static_cast<byte*>(mem_heap_dup(sym_tab->heap, str, len))
187  : NULL;
188 
189  dfield_set_data(&(node->common.val), data, len);
190 
191  node->common.val_buf_size = 0;
192  node->prefetch_buf = NULL;
193  node->cursor_def = NULL;
194 
195  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
196 
197  node->like_node = NULL;
198 
199  node->sym_table = sym_tab;
200 
201  return(node);
202 }
203 
204 /******************************************************************/
207 UNIV_INTERN
208 sym_node_t*
210 /*==================*/
211  sym_tab_t* sym_tab,
212  const char* name,
213  ulint* lit_type)
214 {
215  sym_node_t* node;
216  pars_bound_lit_t* blit;
217  ulint len = 0;
218 
219  blit = pars_info_get_bound_lit(sym_tab->info, name);
220  ut_a(blit);
221 
222  node = static_cast<sym_node_t*>(
223  mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
224 
225  node->common.type = QUE_NODE_SYMBOL;
226  node->common.brother = node->common.parent = NULL;
227 
228  node->table = NULL;
229  node->resolved = TRUE;
230  node->token_type = SYM_LIT;
231 
232  node->indirection = NULL;
233 
234  switch (blit->type) {
235  case DATA_FIXBINARY:
236  len = blit->length;
237  *lit_type = PARS_FIXBINARY_LIT;
238  break;
239 
240  case DATA_BLOB:
241  *lit_type = PARS_BLOB_LIT;
242  break;
243 
244  case DATA_VARCHAR:
245  *lit_type = PARS_STR_LIT;
246  break;
247 
248  case DATA_CHAR:
249  ut_a(blit->length > 0);
250 
251  len = blit->length;
252  *lit_type = PARS_STR_LIT;
253  break;
254 
255  case DATA_INT:
256  ut_a(blit->length > 0);
257  ut_a(blit->length <= 8);
258 
259  len = blit->length;
260  *lit_type = PARS_INT_LIT;
261  break;
262 
263  default:
264  ut_error;
265  }
266 
267  dtype_set(dfield_get_type(&node->common.val),
268  blit->type, blit->prtype, len);
269 
270  dfield_set_data(&(node->common.val), blit->address, blit->length);
271 
272  node->common.val_buf_size = 0;
273  node->prefetch_buf = NULL;
274  node->cursor_def = NULL;
275 
276  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
277 
278  blit->node = node;
279  node->like_node = NULL;
280  node->sym_table = sym_tab;
281 
282  return(node);
283 }
284 
285 /**********************************************************************
286 Rebind literal to a node in the symbol table. */
287 
288 sym_node_t*
289 sym_tab_rebind_lit(
290 /*===============*/
291  /* out: symbol table node */
292  sym_node_t* node, /* in: node that is bound to literal*/
293  const void* address, /* in: pointer to data */
294  ulint length) /* in: length of data */
295 {
296  dfield_t* dfield = que_node_get_val(node);
297  dtype_t* dtype = dfield_get_type(dfield);
298 
299  ut_a(node->token_type == SYM_LIT);
300 
301  dfield_set_data(&node->common.val, address, length);
302 
303  if (node->like_node) {
304 
305  ut_a(dtype_get_mtype(dtype) == DATA_CHAR
306  || dtype_get_mtype(dtype) == DATA_VARCHAR);
307 
308  /* Don't force [FALSE] creation of sub-nodes (for LIKE) */
309  pars_like_rebind(
310  node,static_cast<const byte*>(address), length);
311  }
312 
313  /* FIXME: What's this ? */
314  node->common.val_buf_size = 0;
315 
316  if (node->prefetch_buf) {
318  node->prefetch_buf = NULL;
319  }
320 
321  if (node->cursor_def) {
323  node->cursor_def = NULL;
324  }
325 
326  return(node);
327 }
328 
329 /******************************************************************/
332 UNIV_INTERN
333 sym_node_t*
335 /*=================*/
336  sym_tab_t* sym_tab)
337 {
338  sym_node_t* node;
339 
340  node = static_cast<sym_node_t*>(
341  mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
342 
343  node->common.type = QUE_NODE_SYMBOL;
344 
345  node->table = NULL;
346  node->resolved = TRUE;
347  node->token_type = SYM_LIT;
348 
349  node->indirection = NULL;
350 
351  dfield_get_type(&node->common.val)->mtype = DATA_ERROR;
352 
353  dfield_set_null(&node->common.val);
354 
355  node->common.val_buf_size = 0;
356  node->prefetch_buf = NULL;
357  node->cursor_def = NULL;
358 
359  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
360 
361  node->like_node = NULL;
362 
363  node->sym_table = sym_tab;
364 
365  return(node);
366 }
367 
368 /******************************************************************/
371 UNIV_INTERN
372 sym_node_t*
374 /*===========*/
375  sym_tab_t* sym_tab,
376  byte* name,
377  ulint len)
378 {
379  sym_node_t* node;
380 
381  node = static_cast<sym_node_t*>(
382  mem_heap_zalloc(sym_tab->heap, sizeof(*node)));
383 
384  node->common.type = QUE_NODE_SYMBOL;
385 
386  node->name = mem_heap_strdupl(sym_tab->heap, (char*) name, len);
387  node->name_len = len;
388 
389  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
390 
391  dfield_set_null(&node->common.val);
392 
393  node->sym_table = sym_tab;
394 
395  return(node);
396 }
397 
398 /******************************************************************/
401 UNIV_INTERN
402 sym_node_t*
404 /*=================*/
405  sym_tab_t* sym_tab,
406  const char* name)
407 {
408  sym_node_t* node;
409  pars_bound_id_t* bid;
410 
411  bid = pars_info_get_bound_id(sym_tab->info, name);
412  ut_a(bid);
413 
414  node = static_cast<sym_node_t*>(
415  mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
416 
417  node->common.type = QUE_NODE_SYMBOL;
418 
419  node->table = NULL;
420  node->resolved = FALSE;
421  node->token_type = SYM_UNSET;
422  node->indirection = NULL;
423 
424  node->name = mem_heap_strdup(sym_tab->heap, bid->id);
425  node->name_len = strlen(node->name);
426 
427  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
428 
429  dfield_set_null(&node->common.val);
430 
431  node->common.val_buf_size = 0;
432  node->prefetch_buf = NULL;
433  node->cursor_def = NULL;
434 
435  node->like_node = NULL;
436 
437  node->sym_table = sym_tab;
438 
439  return(node);
440 }