~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2009-03-22 07:55:08 UTC
  • mto: (960.5.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: mordred@inaugust.com-20090322075508-1h34cksq2knhaxc3
Removed global.h from a header.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
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
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/**************************************************//**
20
 
@file eval/eval0eval.c
 
19
/******************************************************
21
20
SQL evaluator: evaluates simple data structures, like expressions, in
22
21
a query graph
23
22
 
33
32
#include "data0data.h"
34
33
#include "row0sel.h"
35
34
 
36
 
/** The RND function seed */
 
35
/* The RND function seed */
37
36
static ulint    eval_rnd        = 128367121;
38
37
 
39
 
/** Dummy adress used when we should allocate a buffer of size 0 in
40
 
eval_node_alloc_val_buf */
 
38
/* Dummy adress used when we should allocate a buffer of size 0 in
 
39
the function below */
41
40
 
42
41
static byte     eval_dummy;
43
42
 
44
 
/*****************************************************************//**
 
43
/*********************************************************************
45
44
Allocate a buffer from global dynamic memory for a value of a que_node.
46
45
NOTE that this memory must be explicitly freed when the query graph is
47
46
freed. If the node already has an allocated buffer, that buffer is freed
48
47
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 */
 
48
allocated for a query node val field. */
51
49
UNIV_INTERN
52
50
byte*
53
51
eval_node_alloc_val_buf(
54
52
/*====================*/
55
 
        que_node_t*     node,   /*!< in: query graph node; sets the val field
 
53
                                /* out: pointer to allocated buffer */
 
54
        que_node_t*     node,   /* in: query graph node; sets the val field
56
55
                                data field to point to the new buffer, and
57
56
                                len field equal to size */
58
 
        ulint           size)   /*!< in: buffer size */
 
57
        ulint           size)   /* in: buffer size */
59
58
{
60
59
        dfield_t*       dfield;
61
60
        byte*           data;
84
83
        return(data);
85
84
}
86
85
 
87
 
/*****************************************************************//**
 
86
/*********************************************************************
88
87
Free the buffer from global dynamic memory for a value of a que_node,
89
88
if it has been allocated in the above function. The freeing for pushed
90
89
column values is done in sel_col_prefetch_buf_free. */
92
91
void
93
92
eval_node_free_val_buf(
94
93
/*===================*/
95
 
        que_node_t*     node)   /*!< in: query graph node */
 
94
        que_node_t*     node)   /* in: query graph node */
96
95
{
97
96
        dfield_t*       dfield;
98
97
        byte*           data;
111
110
        }
112
111
}
113
112
 
114
 
/*****************************************************************//**
115
 
Evaluates a comparison node.
116
 
@return the result of the comparison */
 
113
/*********************************************************************
 
114
Evaluates a comparison node. */
117
115
UNIV_INTERN
118
116
ibool
119
117
eval_cmp(
120
118
/*=====*/
121
 
        func_node_t*    cmp_node)       /*!< in: comparison node */
 
119
                                        /* out: the result of the comparison */
 
120
        func_node_t*    cmp_node)       /* in: comparison node */
122
121
{
123
122
        que_node_t*     arg1;
124
123
        que_node_t*     arg2;
170
169
        return(val);
171
170
}
172
171
 
173
 
/*****************************************************************//**
 
172
/*********************************************************************
174
173
Evaluates a logical operation node. */
175
174
UNIV_INLINE
176
175
void
177
176
eval_logical(
178
177
/*=========*/
179
 
        func_node_t*    logical_node)   /*!< in: logical operation node */
 
178
        func_node_t*    logical_node)   /* in: logical operation node */
180
179
{
181
180
        que_node_t*     arg1;
182
181
        que_node_t*     arg2;
211
210
        eval_node_set_ibool_val(logical_node, val);
212
211
}
213
212
 
214
 
/*****************************************************************//**
 
213
/*********************************************************************
215
214
Evaluates an arithmetic operation node. */
216
215
UNIV_INLINE
217
216
void
218
217
eval_arith(
219
218
/*=======*/
220
 
        func_node_t*    arith_node)     /*!< in: arithmetic operation node */
 
219
        func_node_t*    arith_node)     /* in: arithmetic operation node */
221
220
{
222
221
        que_node_t*     arg1;
223
222
        que_node_t*     arg2;
255
254
        eval_node_set_int_val(arith_node, val);
256
255
}
257
256
 
258
 
/*****************************************************************//**
 
257
/*********************************************************************
259
258
Evaluates an aggregate operation node. */
260
259
UNIV_INLINE
261
260
void
262
261
eval_aggregate(
263
262
/*===========*/
264
 
        func_node_t*    node)   /*!< in: aggregate operation node */
 
263
        func_node_t*    node)   /* in: aggregate operation node */
265
264
{
266
265
        que_node_t*     arg;
267
266
        lint            val;
289
288
        eval_node_set_int_val(node, val);
290
289
}
291
290
 
292
 
/*****************************************************************//**
 
291
/*********************************************************************
293
292
Evaluates a predefined function node where the function is not relevant
294
293
in benchmarks. */
295
294
static
296
295
void
297
296
eval_predefined_2(
298
297
/*==============*/
299
 
        func_node_t*    func_node)      /*!< in: predefined function node */
 
298
        func_node_t*    func_node)      /* in: predefined function node */
300
299
{
301
300
        que_node_t*     arg;
302
301
        que_node_t*     arg1;
376
375
        }
377
376
}
378
377
 
379
 
/*****************************************************************//**
 
378
/*********************************************************************
380
379
Evaluates a notfound-function node. */
381
380
UNIV_INLINE
382
381
void
383
382
eval_notfound(
384
383
/*==========*/
385
 
        func_node_t*    func_node)      /*!< in: function node */
 
384
        func_node_t*    func_node)      /* in: function node */
386
385
{
 
386
        que_node_t*     arg1;
 
387
        que_node_t*     arg2;
387
388
        sym_node_t*     cursor;
388
389
        sel_node_t*     sel_node;
389
390
        ibool           ibool_val;
390
391
 
 
392
        arg1 = func_node->args;
 
393
        arg2 = que_node_get_next(arg1);
 
394
 
391
395
        ut_ad(func_node->func == PARS_NOTFOUND_TOKEN);
392
396
 
393
 
        cursor = func_node->args;
 
397
        cursor = arg1;
394
398
 
395
399
        ut_ad(que_node_get_type(cursor) == QUE_NODE_SYMBOL);
396
400
 
413
417
        eval_node_set_ibool_val(func_node, ibool_val);
414
418
}
415
419
 
416
 
/*****************************************************************//**
 
420
/*********************************************************************
417
421
Evaluates a substr-function node. */
418
422
UNIV_INLINE
419
423
void
420
424
eval_substr(
421
425
/*========*/
422
 
        func_node_t*    func_node)      /*!< in: function node */
 
426
        func_node_t*    func_node)      /* in: function node */
423
427
{
424
428
        que_node_t*     arg1;
425
429
        que_node_t*     arg2;
446
450
        dfield_set_data(dfield, str1 + len1, len2);
447
451
}
448
452
 
449
 
/*****************************************************************//**
 
453
/*********************************************************************
450
454
Evaluates a replstr-procedure node. */
451
455
static
452
456
void
453
457
eval_replstr(
454
458
/*=========*/
455
 
        func_node_t*    func_node)      /*!< in: function node */
 
459
        func_node_t*    func_node)      /* in: function node */
456
460
{
457
461
        que_node_t*     arg1;
458
462
        que_node_t*     arg2;
486
490
        ut_memcpy(str1 + len1, str2, len2);
487
491
}
488
492
 
489
 
/*****************************************************************//**
 
493
/*********************************************************************
490
494
Evaluates an instr-function node. */
491
495
static
492
496
void
493
497
eval_instr(
494
498
/*=======*/
495
 
        func_node_t*    func_node)      /*!< in: function node */
 
499
        func_node_t*    func_node)      /* in: function node */
496
500
{
497
501
        que_node_t*     arg1;
498
502
        que_node_t*     arg2;
558
562
        eval_node_set_int_val(func_node, int_val);
559
563
}
560
564
 
561
 
/*****************************************************************//**
 
565
/*********************************************************************
562
566
Evaluates a predefined function node. */
563
567
UNIV_INLINE
564
568
void
565
569
eval_binary_to_number(
566
570
/*==================*/
567
 
        func_node_t*    func_node)      /*!< in: function node */
 
571
        func_node_t*    func_node)      /* in: function node */
568
572
{
569
573
        que_node_t*     arg1;
570
574
        dfield_t*       dfield;
596
600
        eval_node_copy_and_alloc_val(func_node, str2, 4);
597
601
}
598
602
 
599
 
/*****************************************************************//**
 
603
/*********************************************************************
600
604
Evaluates a predefined function node. */
601
605
static
602
606
void
603
607
eval_concat(
604
608
/*========*/
605
 
        func_node_t*    func_node)      /*!< in: function node */
 
609
        func_node_t*    func_node)      /* in: function node */
606
610
{
607
611
        que_node_t*     arg;
608
612
        dfield_t*       dfield;
638
642
        }
639
643
}
640
644
 
641
 
/*****************************************************************//**
 
645
/*********************************************************************
642
646
Evaluates a predefined function node. If the first argument is an integer,
643
647
this function looks at the second argument which is the integer length in
644
648
bytes, and converts the integer to a VARCHAR.
648
652
void
649
653
eval_to_binary(
650
654
/*===========*/
651
 
        func_node_t*    func_node)      /*!< in: function node */
 
655
        func_node_t*    func_node)      /* in: function node */
652
656
{
653
657
        que_node_t*     arg1;
654
658
        que_node_t*     arg2;
686
690
        dfield_set_data(dfield, str1 + (4 - len1), len1);
687
691
}
688
692
 
689
 
/*****************************************************************//**
 
693
/*********************************************************************
690
694
Evaluates a predefined function node. */
691
695
UNIV_INLINE
692
696
void
693
697
eval_predefined(
694
698
/*============*/
695
 
        func_node_t*    func_node)      /*!< in: function node */
 
699
        func_node_t*    func_node)      /* in: function node */
696
700
{
697
701
        que_node_t*     arg1;
698
702
        lint            int_val;
778
782
        eval_node_set_int_val(func_node, int_val);
779
783
}
780
784
 
781
 
/*****************************************************************//**
 
785
/*********************************************************************
782
786
Evaluates a function node. */
783
787
UNIV_INTERN
784
788
void
785
789
eval_func(
786
790
/*======*/
787
 
        func_node_t*    func_node)      /*!< in: function node */
 
791
        func_node_t*    func_node)      /* in: function node */
788
792
{
789
793
        que_node_t*     arg;
790
794
        ulint           class;