Skip to content

Commit 292015d

Browse files
committed
MDEV-21254 Remove unused keywords from the InnoDB SQL parser
The InnoDB internal SQL parser, which is used for updating the InnoDB data dictionary tables (to be removed in MDEV-11655), persistent statistics (to be refactored in MDEV-15020) and fulltext indexes, implements some unused keywords and built-in functions: OUT BINARY BLOB INTEGER FLOAT SUM DISTINCT READ COMPACT BLOCK_SIZE TO_CHAR TO_NUMBER BINARY_TO_NUMBER REPLSTR SYSDATE PRINTF ASSERT RND RND_STR ROW_PRINTF UNSIGNED Also, procedures are never declared with parameters. Only one top-level procedure is declared and invoked at a time, and parameters are being passed via pars_info_t.
1 parent 59e14b9 commit 292015d

File tree

8 files changed

+1486
-2630
lines changed

8 files changed

+1486
-2630
lines changed

storage/innobase/eval/eval0eval.cc

Lines changed: 12 additions & 283 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ Created 12/29/1997 Heikki Tuuri
3030
#include "row0sel.h"
3131
#include "rem0cmp.h"
3232

33-
/** The RND function seed */
34-
static ulint eval_rnd = 128367121;
35-
3633
/** Dummy adress used when we should allocate a buffer of size 0 in
3734
eval_node_alloc_val_buf */
3835

@@ -310,119 +307,17 @@ eval_aggregate(
310307
/*===========*/
311308
func_node_t* node) /*!< in: aggregate operation node */
312309
{
313-
que_node_t* arg;
314310
lint val;
315-
lint arg_val;
316-
int func;
317311

318312
ut_ad(que_node_get_type(node) == QUE_NODE_FUNC);
319313

320314
val = eval_node_get_int_val(node);
321315

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;
336318
eval_node_set_int_val(node, val);
337319
}
338320

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-
426321
/*****************************************************************//**
427322
Evaluates a notfound-function node. */
428323
UNIV_INLINE
@@ -493,46 +388,6 @@ eval_substr(
493388
dfield_set_data(dfield, str1 + len1, len2);
494389
}
495390

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-
536391
/*****************************************************************//**
537392
Evaluates an instr-function node. */
538393
static
@@ -605,44 +460,6 @@ eval_instr(
605460
eval_node_set_int_val(func_node, int_val);
606461
}
607462

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-
646463
/*****************************************************************//**
647464
Evaluates a predefined function node. */
648465
static
@@ -734,95 +551,12 @@ eval_to_binary(
734551
}
735552

736553
/*****************************************************************//**
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)
743556
{
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)));
826560
}
827561

828562
/*****************************************************************//**
@@ -852,8 +586,7 @@ eval_func(
852586

853587
if (dfield_is_null(que_node_get_val(arg))
854588
&& (fclass != PARS_FUNC_CMP)
855-
&& (func != PARS_NOTFOUND_TOKEN)
856-
&& (func != PARS_PRINTF_TOKEN)) {
589+
&& (func != PARS_NOTFOUND_TOKEN)) {
857590
ut_error;
858591
}
859592

@@ -878,24 +611,20 @@ eval_func(
878611
case PARS_SUBSTR_TOKEN:
879612
eval_substr(func_node);
880613
return;
881-
case PARS_REPLSTR_TOKEN:
882-
eval_replstr(func_node);
883-
return;
884614
case PARS_INSTR_TOKEN:
885615
eval_instr(func_node);
886616
return;
887-
case PARS_BINARY_TO_NUMBER_TOKEN:
888-
eval_binary_to_number(func_node);
889-
return;
890617
case PARS_CONCAT_TOKEN:
891618
eval_concat(func_node);
892619
return;
893620
case PARS_TO_BINARY_TOKEN:
894621
eval_to_binary(func_node);
895622
return;
896-
default:
897-
eval_predefined(func_node);
623+
case PARS_LENGTH_TOKEN:
624+
eval_length(func_node);
898625
return;
626+
default:
627+
ut_error;
899628
}
900629
case PARS_FUNC_LOGICAL:
901630
eval_logical(func_node);

0 commit comments

Comments
 (0)