@@ -30,9 +30,6 @@ Created 12/29/1997 Heikki Tuuri
30
30
#include " row0sel.h"
31
31
#include " rem0cmp.h"
32
32
33
- /* * The RND function seed */
34
- static ulint eval_rnd = 128367121 ;
35
-
36
33
/* * Dummy adress used when we should allocate a buffer of size 0 in
37
34
eval_node_alloc_val_buf */
38
35
@@ -310,119 +307,17 @@ eval_aggregate(
310
307
/* ===========*/
311
308
func_node_t * node) /* !< in: aggregate operation node */
312
309
{
313
- que_node_t * arg;
314
310
lint val;
315
- lint arg_val;
316
- int func;
317
311
318
312
ut_ad (que_node_get_type (node) == QUE_NODE_FUNC);
319
313
320
314
val = eval_node_get_int_val (node);
321
315
322
- func = node->func ;
323
-
324
- if (func == PARS_COUNT_TOKEN) {
325
-
326
- val = val + 1 ;
327
- } else {
328
- ut_ad (func == PARS_SUM_TOKEN);
329
-
330
- arg = node->args ;
331
- arg_val = eval_node_get_int_val (arg);
332
-
333
- val = val + arg_val;
334
- }
335
-
316
+ ut_a (node->func == PARS_COUNT_TOKEN);
317
+ val = val + 1 ;
336
318
eval_node_set_int_val (node, val);
337
319
}
338
320
339
- /* ****************************************************************/ /* *
340
- Evaluates a predefined function node where the function is not relevant
341
- in benchmarks. */
342
- static
343
- void
344
- eval_predefined_2 (
345
- /* ==============*/
346
- func_node_t * func_node) /* !< in: predefined function node */
347
- {
348
- que_node_t * arg;
349
- que_node_t * arg1;
350
- que_node_t * arg2 = 0 ; /* remove warning (??? bug ???) */
351
- lint int_val;
352
- byte* data;
353
- ulint len1;
354
- ulint len2;
355
- int func;
356
- ulint i;
357
-
358
- ut_ad (que_node_get_type (func_node) == QUE_NODE_FUNC);
359
-
360
- arg1 = func_node->args ;
361
-
362
- if (arg1) {
363
- arg2 = que_node_get_next (arg1);
364
- }
365
-
366
- func = func_node->func ;
367
-
368
- if (func == PARS_PRINTF_TOKEN) {
369
-
370
- arg = arg1;
371
-
372
- while (arg) {
373
- dfield_print (que_node_get_val (arg));
374
-
375
- arg = que_node_get_next (arg);
376
- }
377
-
378
- putc (' \n ' , stderr);
379
-
380
- } else if (func == PARS_ASSERT_TOKEN) {
381
-
382
- if (!eval_node_get_ibool_val (arg1)) {
383
- fputs (" SQL assertion fails in a stored procedure!\n " ,
384
- stderr);
385
- }
386
-
387
- ut_a (eval_node_get_ibool_val (arg1));
388
-
389
- /* This function, or more precisely, a debug procedure,
390
- returns no value */
391
-
392
- } else if (func == PARS_RND_TOKEN) {
393
-
394
- len1 = (ulint) eval_node_get_int_val (arg1);
395
- len2 = (ulint) eval_node_get_int_val (arg2);
396
-
397
- ut_ad (len2 >= len1);
398
-
399
- if (len2 > len1) {
400
- int_val = (lint) (len1
401
- + (eval_rnd % (len2 - len1 + 1 )));
402
- } else {
403
- int_val = (lint) len1;
404
- }
405
-
406
- eval_rnd = ut_rnd_gen_next_ulint (eval_rnd);
407
-
408
- eval_node_set_int_val (func_node, int_val);
409
-
410
- } else if (func == PARS_RND_STR_TOKEN) {
411
-
412
- len1 = (ulint) eval_node_get_int_val (arg1);
413
-
414
- data = eval_node_ensure_val_buf (func_node, len1);
415
-
416
- for (i = 0 ; i < len1; i++) {
417
- data[i] = (byte)(97 + (eval_rnd % 3 ));
418
-
419
- eval_rnd = ut_rnd_gen_next_ulint (eval_rnd);
420
- }
421
- } else {
422
- ut_error;
423
- }
424
- }
425
-
426
321
/* ****************************************************************/ /* *
427
322
Evaluates a notfound-function node. */
428
323
UNIV_INLINE
@@ -493,46 +388,6 @@ eval_substr(
493
388
dfield_set_data (dfield, str1 + len1, len2);
494
389
}
495
390
496
- /* ****************************************************************/ /* *
497
- Evaluates a replstr-procedure node. */
498
- static
499
- void
500
- eval_replstr (
501
- /* =========*/
502
- func_node_t * func_node) /* !< in: function node */
503
- {
504
- que_node_t * arg1;
505
- que_node_t * arg2;
506
- que_node_t * arg3;
507
- que_node_t * arg4;
508
- byte* str1;
509
- byte* str2;
510
- ulint len1;
511
- ulint len2;
512
-
513
- arg1 = func_node->args ;
514
- arg2 = que_node_get_next (arg1);
515
-
516
- ut_ad (que_node_get_type (arg1) == QUE_NODE_SYMBOL);
517
-
518
- arg3 = que_node_get_next (arg2);
519
- arg4 = que_node_get_next (arg3);
520
-
521
- str1 = static_cast <byte*>(dfield_get_data (que_node_get_val (arg1)));
522
- str2 = static_cast <byte*>(dfield_get_data (que_node_get_val (arg2)));
523
-
524
- len1 = (ulint) eval_node_get_int_val (arg3);
525
- len2 = (ulint) eval_node_get_int_val (arg4);
526
-
527
- if ((dfield_get_len (que_node_get_val (arg1)) < len1 + len2)
528
- || (dfield_get_len (que_node_get_val (arg2)) < len2)) {
529
-
530
- ut_error;
531
- }
532
-
533
- ut_memcpy (str1 + len1, str2, len2);
534
- }
535
-
536
391
/* ****************************************************************/ /* *
537
392
Evaluates an instr-function node. */
538
393
static
@@ -605,44 +460,6 @@ eval_instr(
605
460
eval_node_set_int_val (func_node, int_val);
606
461
}
607
462
608
- /* ****************************************************************/ /* *
609
- Evaluates a predefined function node. */
610
- UNIV_INLINE
611
- void
612
- eval_binary_to_number (
613
- /* ==================*/
614
- func_node_t * func_node) /* !< in: function node */
615
- {
616
- que_node_t * arg1;
617
- dfield_t * dfield;
618
- byte* str1;
619
- byte* str2;
620
- ulint len1;
621
- ulint int_val;
622
-
623
- arg1 = func_node->args ;
624
-
625
- dfield = que_node_get_val (arg1);
626
-
627
- str1 = static_cast <byte*>(dfield_get_data (dfield));
628
- len1 = dfield_get_len (dfield);
629
-
630
- if (len1 > 4 ) {
631
- ut_error;
632
- }
633
-
634
- if (len1 == 4 ) {
635
- str2 = str1;
636
- } else {
637
- int_val = 0 ;
638
- str2 = (byte*) &int_val;
639
-
640
- ut_memcpy (str2 + (4 - len1), str1, len1);
641
- }
642
-
643
- eval_node_copy_and_alloc_val (func_node, str2, 4 );
644
- }
645
-
646
463
/* ****************************************************************/ /* *
647
464
Evaluates a predefined function node. */
648
465
static
@@ -734,95 +551,12 @@ eval_to_binary(
734
551
}
735
552
736
553
/* ****************************************************************/ /* *
737
- Evaluates a predefined function node. */
738
- UNIV_INLINE
739
- void
740
- eval_predefined (
741
- /* ============*/
742
- func_node_t * func_node) /* !< in: function node */
554
+ Evaluate LENGTH(). */
555
+ inline void eval_length (func_node_t * func_node)
743
556
{
744
- que_node_t * arg1;
745
- lint int_val;
746
- byte* data;
747
- int func;
748
-
749
- func = func_node->func ;
750
-
751
- arg1 = func_node->args ;
752
-
753
- if (func == PARS_LENGTH_TOKEN) {
754
-
755
- int_val = (lint) dfield_get_len (que_node_get_val (arg1));
756
-
757
- } else if (func == PARS_TO_CHAR_TOKEN) {
758
-
759
- /* Convert number to character string as a
760
- signed decimal integer. */
761
-
762
- ulint uint_val;
763
- int int_len;
764
-
765
- int_val = eval_node_get_int_val (arg1);
766
-
767
- /* Determine the length of the string. */
768
-
769
- if (int_val == 0 ) {
770
- int_len = 1 ; /* the number 0 occupies 1 byte */
771
- } else {
772
- int_len = 0 ;
773
- if (int_val < 0 ) {
774
- uint_val = ((ulint) -int_val - 1 ) + 1 ;
775
- int_len++; /* reserve space for minus sign */
776
- } else {
777
- uint_val = (ulint) int_val;
778
- }
779
- for (; uint_val > 0 ; int_len++) {
780
- uint_val /= 10 ;
781
- }
782
- }
783
-
784
- /* allocate the string */
785
- data = eval_node_ensure_val_buf (func_node, int_len + 1 );
786
-
787
- /* add terminating NUL character */
788
- data[int_len] = 0 ;
789
-
790
- /* convert the number */
791
-
792
- if (int_val == 0 ) {
793
- data[0 ] = ' 0' ;
794
- } else {
795
- int tmp;
796
- if (int_val < 0 ) {
797
- data[0 ] = ' -' ; /* preceding minus sign */
798
- uint_val = ((ulint) -int_val - 1 ) + 1 ;
799
- } else {
800
- uint_val = (ulint) int_val;
801
- }
802
- for (tmp = int_len; uint_val > 0 ; uint_val /= 10 ) {
803
- data[--tmp] = (byte)
804
- (' 0' + (byte)(uint_val % 10 ));
805
- }
806
- }
807
-
808
- dfield_set_len (que_node_get_val (func_node), int_len);
809
-
810
- return ;
811
-
812
- } else if (func == PARS_TO_NUMBER_TOKEN) {
813
-
814
- int_val = atoi ((char *)
815
- dfield_get_data (que_node_get_val (arg1)));
816
-
817
- } else if (func == PARS_SYSDATE_TOKEN) {
818
- int_val = (lint) time (NULL );
819
- } else {
820
- eval_predefined_2 (func_node);
821
-
822
- return ;
823
- }
824
-
825
- eval_node_set_int_val (func_node, int_val);
557
+ eval_node_set_int_val (func_node,
558
+ dfield_get_len (que_node_get_val
559
+ (func_node->args )));
826
560
}
827
561
828
562
/* ****************************************************************/ /* *
@@ -852,8 +586,7 @@ eval_func(
852
586
853
587
if (dfield_is_null (que_node_get_val (arg))
854
588
&& (fclass != PARS_FUNC_CMP)
855
- && (func != PARS_NOTFOUND_TOKEN)
856
- && (func != PARS_PRINTF_TOKEN)) {
589
+ && (func != PARS_NOTFOUND_TOKEN)) {
857
590
ut_error;
858
591
}
859
592
@@ -878,24 +611,20 @@ eval_func(
878
611
case PARS_SUBSTR_TOKEN:
879
612
eval_substr (func_node);
880
613
return ;
881
- case PARS_REPLSTR_TOKEN:
882
- eval_replstr (func_node);
883
- return ;
884
614
case PARS_INSTR_TOKEN:
885
615
eval_instr (func_node);
886
616
return ;
887
- case PARS_BINARY_TO_NUMBER_TOKEN:
888
- eval_binary_to_number (func_node);
889
- return ;
890
617
case PARS_CONCAT_TOKEN:
891
618
eval_concat (func_node);
892
619
return ;
893
620
case PARS_TO_BINARY_TOKEN:
894
621
eval_to_binary (func_node);
895
622
return ;
896
- default :
897
- eval_predefined (func_node);
623
+ case PARS_LENGTH_TOKEN :
624
+ eval_length (func_node);
898
625
return ;
626
+ default :
627
+ ut_error;
899
628
}
900
629
case PARS_FUNC_LOGICAL:
901
630
eval_logical (func_node);
0 commit comments