~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/eval/eval0eval.c

  • Committer: Jay Pipes
  • Date: 2009-01-30 04:01:12 UTC
  • mto: This revision was merged to the branch mainline in revision 830.
  • Revision ID: jpipes@serialcoder-20090130040112-svbn774guj98pwi4
To remain in compatibility with MySQL, added ability to interpret
decimal arguments as datetime strings for temporal functions.

Fixed YEAR(), MONTH(), DAYOFMONTH(), DAYOFYEAR(), HOUR(), MINUTE(), SECOND(), and MICROSECOND()
to accept decimal parameters and interpret them the same way as MySQL.

Fixed an issue with the TemporalFormat::matches() method which was 
incorrectly assuming all microsecond arguments were specified as 6 digits.
Added power of 10 multiplier to usecond calculation. This fixes issues with
failures in type_date and func_sapdb test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1997, 2009, Innobase Oy. 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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file eval/eval0eval.c
 
1
/******************************************************
21
2
SQL evaluator: evaluates simple data structures, like expressions, in
22
3
a query graph
23
4
 
 
5
(c) 1997 Innobase Oy
 
6
 
24
7
Created 12/29/1997 Heikki Tuuri
25
8
*******************************************************/
26
9
 
33
16
#include "data0data.h"
34
17
#include "row0sel.h"
35
18
 
36
 
/** The RND function seed */
 
19
/* The RND function seed */
37
20
static ulint    eval_rnd        = 128367121;
38
21
 
39
 
/** Dummy adress used when we should allocate a buffer of size 0 in
40
 
eval_node_alloc_val_buf */
 
22
/* Dummy adress used when we should allocate a buffer of size 0 in
 
23
the function below */
41
24
 
42
25
static byte     eval_dummy;
43
26
 
44
 
/*****************************************************************//**
 
27
/*********************************************************************
45
28
Allocate a buffer from global dynamic memory for a value of a que_node.
46
29
NOTE that this memory must be explicitly freed when the query graph is
47
30
freed. If the node already has an allocated buffer, that buffer is freed
48
31
here. NOTE that this is the only function where dynamic memory should be
49
 
allocated for a query node val field.
50
 
@return pointer to allocated buffer */
 
32
allocated for a query node val field. */
51
33
UNIV_INTERN
52
34
byte*
53
35
eval_node_alloc_val_buf(
54
36
/*====================*/
55
 
        que_node_t*     node,   /*!< in: query graph node; sets the val field
 
37
                                /* out: pointer to allocated buffer */
 
38
        que_node_t*     node,   /* in: query graph node; sets the val field
56
39
                                data field to point to the new buffer, and
57
40
                                len field equal to size */
58
 
        ulint           size)   /*!< in: buffer size */
 
41
        ulint           size)   /* in: buffer size */
59
42
{
60
43
        dfield_t*       dfield;
61
44
        byte*           data;
84
67
        return(data);
85
68
}
86
69
 
87
 
/*****************************************************************//**
 
70
/*********************************************************************
88
71
Free the buffer from global dynamic memory for a value of a que_node,
89
72
if it has been allocated in the above function. The freeing for pushed
90
73
column values is done in sel_col_prefetch_buf_free. */
92
75
void
93
76
eval_node_free_val_buf(
94
77
/*===================*/
95
 
        que_node_t*     node)   /*!< in: query graph node */
 
78
        que_node_t*     node)   /* in: query graph node */
96
79
{
97
80
        dfield_t*       dfield;
98
81
        byte*           data;
111
94
        }
112
95
}
113
96
 
114
 
/*****************************************************************//**
115
 
Evaluates a comparison node.
116
 
@return the result of the comparison */
 
97
/*********************************************************************
 
98
Evaluates a comparison node. */
117
99
UNIV_INTERN
118
100
ibool
119
101
eval_cmp(
120
102
/*=====*/
121
 
        func_node_t*    cmp_node)       /*!< in: comparison node */
 
103
                                        /* out: the result of the comparison */
 
104
        func_node_t*    cmp_node)       /* in: comparison node */
122
105
{
123
106
        que_node_t*     arg1;
124
107
        que_node_t*     arg2;
170
153
        return(val);
171
154
}
172
155
 
173
 
/*****************************************************************//**
 
156
/*********************************************************************
174
157
Evaluates a logical operation node. */
175
158
UNIV_INLINE
176
159
void
177
160
eval_logical(
178
161
/*=========*/
179
 
        func_node_t*    logical_node)   /*!< in: logical operation node */
 
162
        func_node_t*    logical_node)   /* in: logical operation node */
180
163
{
181
164
        que_node_t*     arg1;
182
165
        que_node_t*     arg2;
211
194
        eval_node_set_ibool_val(logical_node, val);
212
195
}
213
196
 
214
 
/*****************************************************************//**
 
197
/*********************************************************************
215
198
Evaluates an arithmetic operation node. */
216
199
UNIV_INLINE
217
200
void
218
201
eval_arith(
219
202
/*=======*/
220
 
        func_node_t*    arith_node)     /*!< in: arithmetic operation node */
 
203
        func_node_t*    arith_node)     /* in: arithmetic operation node */
221
204
{
222
205
        que_node_t*     arg1;
223
206
        que_node_t*     arg2;
255
238
        eval_node_set_int_val(arith_node, val);
256
239
}
257
240
 
258
 
/*****************************************************************//**
 
241
/*********************************************************************
259
242
Evaluates an aggregate operation node. */
260
243
UNIV_INLINE
261
244
void
262
245
eval_aggregate(
263
246
/*===========*/
264
 
        func_node_t*    node)   /*!< in: aggregate operation node */
 
247
        func_node_t*    node)   /* in: aggregate operation node */
265
248
{
266
249
        que_node_t*     arg;
267
250
        lint            val;
289
272
        eval_node_set_int_val(node, val);
290
273
}
291
274
 
292
 
/*****************************************************************//**
 
275
/*********************************************************************
293
276
Evaluates a predefined function node where the function is not relevant
294
277
in benchmarks. */
295
278
static
296
279
void
297
280
eval_predefined_2(
298
281
/*==============*/
299
 
        func_node_t*    func_node)      /*!< in: predefined function node */
 
282
        func_node_t*    func_node)      /* in: predefined function node */
300
283
{
301
284
        que_node_t*     arg;
302
285
        que_node_t*     arg1;
376
359
        }
377
360
}
378
361
 
379
 
/*****************************************************************//**
 
362
/*********************************************************************
380
363
Evaluates a notfound-function node. */
381
364
UNIV_INLINE
382
365
void
383
366
eval_notfound(
384
367
/*==========*/
385
 
        func_node_t*    func_node)      /*!< in: function node */
 
368
        func_node_t*    func_node)      /* in: function node */
386
369
{
 
370
        que_node_t*     arg1;
 
371
        que_node_t*     arg2;
387
372
        sym_node_t*     cursor;
388
373
        sel_node_t*     sel_node;
389
374
        ibool           ibool_val;
390
375
 
 
376
        arg1 = func_node->args;
 
377
        arg2 = que_node_get_next(arg1);
 
378
 
391
379
        ut_ad(func_node->func == PARS_NOTFOUND_TOKEN);
392
380
 
393
 
        cursor = func_node->args;
 
381
        cursor = arg1;
394
382
 
395
383
        ut_ad(que_node_get_type(cursor) == QUE_NODE_SYMBOL);
396
384
 
413
401
        eval_node_set_ibool_val(func_node, ibool_val);
414
402
}
415
403
 
416
 
/*****************************************************************//**
 
404
/*********************************************************************
417
405
Evaluates a substr-function node. */
418
406
UNIV_INLINE
419
407
void
420
408
eval_substr(
421
409
/*========*/
422
 
        func_node_t*    func_node)      /*!< in: function node */
 
410
        func_node_t*    func_node)      /* in: function node */
423
411
{
424
412
        que_node_t*     arg1;
425
413
        que_node_t*     arg2;
446
434
        dfield_set_data(dfield, str1 + len1, len2);
447
435
}
448
436
 
449
 
/*****************************************************************//**
 
437
/*********************************************************************
450
438
Evaluates a replstr-procedure node. */
451
439
static
452
440
void
453
441
eval_replstr(
454
442
/*=========*/
455
 
        func_node_t*    func_node)      /*!< in: function node */
 
443
        func_node_t*    func_node)      /* in: function node */
456
444
{
457
445
        que_node_t*     arg1;
458
446
        que_node_t*     arg2;
486
474
        ut_memcpy(str1 + len1, str2, len2);
487
475
}
488
476
 
489
 
/*****************************************************************//**
 
477
/*********************************************************************
490
478
Evaluates an instr-function node. */
491
479
static
492
480
void
493
481
eval_instr(
494
482
/*=======*/
495
 
        func_node_t*    func_node)      /*!< in: function node */
 
483
        func_node_t*    func_node)      /* in: function node */
496
484
{
497
485
        que_node_t*     arg1;
498
486
        que_node_t*     arg2;
558
546
        eval_node_set_int_val(func_node, int_val);
559
547
}
560
548
 
561
 
/*****************************************************************//**
 
549
/*********************************************************************
562
550
Evaluates a predefined function node. */
563
551
UNIV_INLINE
564
552
void
565
553
eval_binary_to_number(
566
554
/*==================*/
567
 
        func_node_t*    func_node)      /*!< in: function node */
 
555
        func_node_t*    func_node)      /* in: function node */
568
556
{
569
557
        que_node_t*     arg1;
570
558
        dfield_t*       dfield;
596
584
        eval_node_copy_and_alloc_val(func_node, str2, 4);
597
585
}
598
586
 
599
 
/*****************************************************************//**
 
587
/*********************************************************************
600
588
Evaluates a predefined function node. */
601
589
static
602
590
void
603
591
eval_concat(
604
592
/*========*/
605
 
        func_node_t*    func_node)      /*!< in: function node */
 
593
        func_node_t*    func_node)      /* in: function node */
606
594
{
607
595
        que_node_t*     arg;
608
596
        dfield_t*       dfield;
638
626
        }
639
627
}
640
628
 
641
 
/*****************************************************************//**
 
629
/*********************************************************************
642
630
Evaluates a predefined function node. If the first argument is an integer,
643
631
this function looks at the second argument which is the integer length in
644
632
bytes, and converts the integer to a VARCHAR.
648
636
void
649
637
eval_to_binary(
650
638
/*===========*/
651
 
        func_node_t*    func_node)      /*!< in: function node */
 
639
        func_node_t*    func_node)      /* in: function node */
652
640
{
653
641
        que_node_t*     arg1;
654
642
        que_node_t*     arg2;
686
674
        dfield_set_data(dfield, str1 + (4 - len1), len1);
687
675
}
688
676
 
689
 
/*****************************************************************//**
 
677
/*********************************************************************
690
678
Evaluates a predefined function node. */
691
679
UNIV_INLINE
692
680
void
693
681
eval_predefined(
694
682
/*============*/
695
 
        func_node_t*    func_node)      /*!< in: function node */
 
683
        func_node_t*    func_node)      /* in: function node */
696
684
{
697
685
        que_node_t*     arg1;
698
686
        lint            int_val;
778
766
        eval_node_set_int_val(func_node, int_val);
779
767
}
780
768
 
781
 
/*****************************************************************//**
 
769
/*********************************************************************
782
770
Evaluates a function node. */
783
771
UNIV_INTERN
784
772
void
785
773
eval_func(
786
774
/*======*/
787
 
        func_node_t*    func_node)      /*!< in: function node */
 
775
        func_node_t*    func_node)      /* in: function node */
788
776
{
789
777
        que_node_t*     arg;
790
778
        ulint           class;