Commit 292015d4 authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 59e14b96
......@@ -30,9 +30,6 @@ Created 12/29/1997 Heikki Tuuri
#include "row0sel.h"
#include "rem0cmp.h"
/** The RND function seed */
static ulint eval_rnd = 128367121;
/** Dummy adress used when we should allocate a buffer of size 0 in
eval_node_alloc_val_buf */
......@@ -310,119 +307,17 @@ eval_aggregate(
/*===========*/
func_node_t* node) /*!< in: aggregate operation node */
{
que_node_t* arg;
lint val;
lint arg_val;
int func;
ut_ad(que_node_get_type(node) == QUE_NODE_FUNC);
val = eval_node_get_int_val(node);
func = node->func;
if (func == PARS_COUNT_TOKEN) {
val = val + 1;
} else {
ut_ad(func == PARS_SUM_TOKEN);
arg = node->args;
arg_val = eval_node_get_int_val(arg);
val = val + arg_val;
}
ut_a(node->func == PARS_COUNT_TOKEN);
val = val + 1;
eval_node_set_int_val(node, val);
}
/*****************************************************************//**
Evaluates a predefined function node where the function is not relevant
in benchmarks. */
static
void
eval_predefined_2(
/*==============*/
func_node_t* func_node) /*!< in: predefined function node */
{
que_node_t* arg;
que_node_t* arg1;
que_node_t* arg2 = 0; /* remove warning (??? bug ???) */
lint int_val;
byte* data;
ulint len1;
ulint len2;
int func;
ulint i;
ut_ad(que_node_get_type(func_node) == QUE_NODE_FUNC);
arg1 = func_node->args;
if (arg1) {
arg2 = que_node_get_next(arg1);
}
func = func_node->func;
if (func == PARS_PRINTF_TOKEN) {
arg = arg1;
while (arg) {
dfield_print(que_node_get_val(arg));
arg = que_node_get_next(arg);
}
putc('\n', stderr);
} else if (func == PARS_ASSERT_TOKEN) {
if (!eval_node_get_ibool_val(arg1)) {
fputs("SQL assertion fails in a stored procedure!\n",
stderr);
}
ut_a(eval_node_get_ibool_val(arg1));
/* This function, or more precisely, a debug procedure,
returns no value */
} else if (func == PARS_RND_TOKEN) {
len1 = (ulint) eval_node_get_int_val(arg1);
len2 = (ulint) eval_node_get_int_val(arg2);
ut_ad(len2 >= len1);
if (len2 > len1) {
int_val = (lint) (len1
+ (eval_rnd % (len2 - len1 + 1)));
} else {
int_val = (lint) len1;
}
eval_rnd = ut_rnd_gen_next_ulint(eval_rnd);
eval_node_set_int_val(func_node, int_val);
} else if (func == PARS_RND_STR_TOKEN) {
len1 = (ulint) eval_node_get_int_val(arg1);
data = eval_node_ensure_val_buf(func_node, len1);
for (i = 0; i < len1; i++) {
data[i] = (byte)(97 + (eval_rnd % 3));
eval_rnd = ut_rnd_gen_next_ulint(eval_rnd);
}
} else {
ut_error;
}
}
/*****************************************************************//**
Evaluates a notfound-function node. */
UNIV_INLINE
......@@ -493,46 +388,6 @@ eval_substr(
dfield_set_data(dfield, str1 + len1, len2);
}
/*****************************************************************//**
Evaluates a replstr-procedure node. */
static
void
eval_replstr(
/*=========*/
func_node_t* func_node) /*!< in: function node */
{
que_node_t* arg1;
que_node_t* arg2;
que_node_t* arg3;
que_node_t* arg4;
byte* str1;
byte* str2;
ulint len1;
ulint len2;
arg1 = func_node->args;
arg2 = que_node_get_next(arg1);
ut_ad(que_node_get_type(arg1) == QUE_NODE_SYMBOL);
arg3 = que_node_get_next(arg2);
arg4 = que_node_get_next(arg3);
str1 = static_cast<byte*>(dfield_get_data(que_node_get_val(arg1)));
str2 = static_cast<byte*>(dfield_get_data(que_node_get_val(arg2)));
len1 = (ulint) eval_node_get_int_val(arg3);
len2 = (ulint) eval_node_get_int_val(arg4);
if ((dfield_get_len(que_node_get_val(arg1)) < len1 + len2)
|| (dfield_get_len(que_node_get_val(arg2)) < len2)) {
ut_error;
}
ut_memcpy(str1 + len1, str2, len2);
}
/*****************************************************************//**
Evaluates an instr-function node. */
static
......@@ -605,44 +460,6 @@ eval_instr(
eval_node_set_int_val(func_node, int_val);
}
/*****************************************************************//**
Evaluates a predefined function node. */
UNIV_INLINE
void
eval_binary_to_number(
/*==================*/
func_node_t* func_node) /*!< in: function node */
{
que_node_t* arg1;
dfield_t* dfield;
byte* str1;
byte* str2;
ulint len1;
ulint int_val;
arg1 = func_node->args;
dfield = que_node_get_val(arg1);
str1 = static_cast<byte*>(dfield_get_data(dfield));
len1 = dfield_get_len(dfield);
if (len1 > 4) {
ut_error;
}
if (len1 == 4) {
str2 = str1;
} else {
int_val = 0;
str2 = (byte*) &int_val;
ut_memcpy(str2 + (4 - len1), str1, len1);
}
eval_node_copy_and_alloc_val(func_node, str2, 4);
}
/*****************************************************************//**
Evaluates a predefined function node. */
static
......@@ -734,95 +551,12 @@ eval_to_binary(
}
/*****************************************************************//**
Evaluates a predefined function node. */
UNIV_INLINE
void
eval_predefined(
/*============*/
func_node_t* func_node) /*!< in: function node */
Evaluate LENGTH(). */
inline void eval_length(func_node_t* func_node)
{
que_node_t* arg1;
lint int_val;
byte* data;
int func;
func = func_node->func;
arg1 = func_node->args;
if (func == PARS_LENGTH_TOKEN) {
int_val = (lint) dfield_get_len(que_node_get_val(arg1));
} else if (func == PARS_TO_CHAR_TOKEN) {
/* Convert number to character string as a
signed decimal integer. */
ulint uint_val;
int int_len;
int_val = eval_node_get_int_val(arg1);
/* Determine the length of the string. */
if (int_val == 0) {
int_len = 1; /* the number 0 occupies 1 byte */
} else {
int_len = 0;
if (int_val < 0) {
uint_val = ((ulint) -int_val - 1) + 1;
int_len++; /* reserve space for minus sign */
} else {
uint_val = (ulint) int_val;
}
for (; uint_val > 0; int_len++) {
uint_val /= 10;
}
}
/* allocate the string */
data = eval_node_ensure_val_buf(func_node, int_len + 1);
/* add terminating NUL character */
data[int_len] = 0;
/* convert the number */
if (int_val == 0) {
data[0] = '0';
} else {
int tmp;
if (int_val < 0) {
data[0] = '-'; /* preceding minus sign */
uint_val = ((ulint) -int_val - 1) + 1;
} else {
uint_val = (ulint) int_val;
}
for (tmp = int_len; uint_val > 0; uint_val /= 10) {
data[--tmp] = (byte)
('0' + (byte)(uint_val % 10));
}
}
dfield_set_len(que_node_get_val(func_node), int_len);
return;
} else if (func == PARS_TO_NUMBER_TOKEN) {
int_val = atoi((char*)
dfield_get_data(que_node_get_val(arg1)));
} else if (func == PARS_SYSDATE_TOKEN) {
int_val = (lint) time(NULL);
} else {
eval_predefined_2(func_node);
return;
}
eval_node_set_int_val(func_node, int_val);
eval_node_set_int_val(func_node,
dfield_get_len(que_node_get_val
(func_node->args)));
}
/*****************************************************************//**
......@@ -852,8 +586,7 @@ eval_func(
if (dfield_is_null(que_node_get_val(arg))
&& (fclass != PARS_FUNC_CMP)
&& (func != PARS_NOTFOUND_TOKEN)
&& (func != PARS_PRINTF_TOKEN)) {
&& (func != PARS_NOTFOUND_TOKEN)) {
ut_error;
}
......@@ -878,24 +611,20 @@ eval_func(
case PARS_SUBSTR_TOKEN:
eval_substr(func_node);
return;
case PARS_REPLSTR_TOKEN:
eval_replstr(func_node);
return;
case PARS_INSTR_TOKEN:
eval_instr(func_node);
return;
case PARS_BINARY_TO_NUMBER_TOKEN:
eval_binary_to_number(func_node);
return;
case PARS_CONCAT_TOKEN:
eval_concat(func_node);
return;
case PARS_TO_BINARY_TOKEN:
eval_to_binary(func_node);
return;
default:
eval_predefined(func_node);
case PARS_LENGTH_TOKEN:
eval_length(func_node);
return;
default:
ut_error;
}
case PARS_FUNC_LOGICAL:
eval_logical(func_node);
......
/* A Bison parser, made by GNU Bison 3.0.4. */
/* A Bison parser, made by GNU Bison 3.4.2. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation,
Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -30,6 +31,9 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Undocumented macros, especially those whose name start with YY_,
are private implementation details. Do not rely on them. */
#ifndef YY_YY_PARS0GRM_TAB_H_INCLUDED
# define YY_YY_PARS0GRM_TAB_H_INCLUDED
/* Debug traces. */
......@@ -58,91 +62,71 @@ extern int yydebug;
PARS_NE_TOKEN = 268,
PARS_PROCEDURE_TOKEN = 269,
PARS_IN_TOKEN = 270,
PARS_OUT_TOKEN = 271,
PARS_BINARY_TOKEN = 272,
PARS_BLOB_TOKEN = 273,
PARS_INT_TOKEN = 274,
PARS_FLOAT_TOKEN = 275,
PARS_CHAR_TOKEN = 276,
PARS_IS_TOKEN = 277,
PARS_BEGIN_TOKEN = 278,
PARS_END_TOKEN = 279,
PARS_IF_TOKEN = 280,
PARS_THEN_TOKEN = 281,
PARS_ELSE_TOKEN = 282,
PARS_ELSIF_TOKEN = 283,
PARS_LOOP_TOKEN = 284,
PARS_WHILE_TOKEN = 285,
PARS_RETURN_TOKEN = 286,
PARS_SELECT_TOKEN = 287,
PARS_SUM_TOKEN = 288,
PARS_COUNT_TOKEN = 289,
PARS_DISTINCT_TOKEN = 290,
PARS_FROM_TOKEN = 291,
PARS_WHERE_TOKEN = 292,
PARS_FOR_TOKEN = 293,
PARS_DDOT_TOKEN = 294,
PARS_READ_TOKEN = 295,
PARS_ORDER_TOKEN = 296,
PARS_BY_TOKEN = 297,
PARS_ASC_TOKEN = 298,
PARS_DESC_TOKEN = 299,
PARS_INSERT_TOKEN = 300,
PARS_INTO_TOKEN = 301,
PARS_VALUES_TOKEN = 302,
PARS_UPDATE_TOKEN = 303,
PARS_SET_TOKEN = 304,
PARS_DELETE_TOKEN = 305,
PARS_CURRENT_TOKEN = 306,
PARS_OF_TOKEN = 307,
PARS_CREATE_TOKEN = 308,
PARS_TABLE_TOKEN = 309,
PARS_INDEX_TOKEN = 310,
PARS_UNIQUE_TOKEN = 311,
PARS_CLUSTERED_TOKEN = 312,
PARS_ON_TOKEN = 313,
PARS_ASSIGN_TOKEN = 314,
PARS_DECLARE_TOKEN = 315,
PARS_CURSOR_TOKEN = 316,
PARS_SQL_TOKEN = 317,
PARS_OPEN_TOKEN = 318,
PARS_FETCH_TOKEN = 319,
PARS_CLOSE_TOKEN = 320,
PARS_NOTFOUND_TOKEN = 321,
PARS_TO_CHAR_TOKEN = 322,
PARS_TO_NUMBER_TOKEN = 323,
PARS_TO_BINARY_TOKEN = 324,
PARS_BINARY_TO_NUMBER_TOKEN = 325,
PARS_SUBSTR_TOKEN = 326,
PARS_REPLSTR_TOKEN = 327,
PARS_CONCAT_TOKEN = 328,
PARS_INSTR_TOKEN = 329,
PARS_LENGTH_TOKEN = 330,
PARS_SYSDATE_TOKEN = 331,
PARS_PRINTF_TOKEN = 332,
PARS_ASSERT_TOKEN = 333,
PARS_RND_TOKEN = 334,
PARS_RND_STR_TOKEN = 335,
PARS_ROW_PRINTF_TOKEN = 336,
PARS_COMMIT_TOKEN = 337,
PARS_ROLLBACK_TOKEN = 338,
PARS_WORK_TOKEN = 339,
PARS_UNSIGNED_TOKEN = 340,
PARS_EXIT_TOKEN = 341,
PARS_FUNCTION_TOKEN = 342,
PARS_LOCK_TOKEN = 343,
PARS_SHARE_TOKEN = 344,
PARS_MODE_TOKEN = 345,
PARS_LIKE_TOKEN = 346,
PARS_LIKE_TOKEN_EXACT = 347,
PARS_LIKE_TOKEN_PREFIX = 348,
PARS_LIKE_TOKEN_SUFFIX = 349,
PARS_LIKE_TOKEN_SUBSTR = 350,
PARS_TABLE_NAME_TOKEN = 351,
PARS_COMPACT_TOKEN = 352,
PARS_BLOCK_SIZE_TOKEN = 353,
PARS_BIGINT_TOKEN = 354,
NEG = 355
PARS_INT_TOKEN = 271,
PARS_CHAR_TOKEN = 272,
PARS_IS_TOKEN = 273,
PARS_BEGIN_TOKEN = 274,
PARS_END_TOKEN = 275,
PARS_IF_TOKEN = 276,
PARS_THEN_TOKEN = 277,
PARS_ELSE_TOKEN = 278,
PARS_ELSIF_TOKEN = 279,
PARS_LOOP_TOKEN = 280,
PARS_WHILE_TOKEN = 281,
PARS_RETURN_TOKEN = 282,
PARS_SELECT_TOKEN = 283,
PARS_COUNT_TOKEN = 284,
PARS_FROM_TOKEN = 285,
PARS_WHERE_TOKEN = 286,
PARS_FOR_TOKEN = 287,
PARS_DDOT_TOKEN = 288,
PARS_ORDER_TOKEN = 289,
PARS_BY_TOKEN = 290,
PARS_ASC_TOKEN = 291,
PARS_DESC_TOKEN = 292,
PARS_INSERT_TOKEN = 293,
PARS_INTO_TOKEN = 294,
PARS_VALUES_TOKEN = 295,
PARS_UPDATE_TOKEN = 296,
PARS_SET_TOKEN = 297,
PARS_DELETE_TOKEN = 298,
PARS_CURRENT_TOKEN = 299,
PARS_OF_TOKEN = 300,
PARS_CREATE_TOKEN = 301,
PARS_TABLE_TOKEN = 302,
PARS_INDEX_TOKEN = 303,
PARS_UNIQUE_TOKEN = 304,
PARS_CLUSTERED_TOKEN = 305,
PARS_ON_TOKEN = 306,
PARS_ASSIGN_TOKEN = 307,
PARS_DECLARE_TOKEN = 308,
PARS_CURSOR_TOKEN = 309,
PARS_SQL_TOKEN = 310,
PARS_OPEN_TOKEN = 311,
PARS_FETCH_TOKEN = 312,
PARS_CLOSE_TOKEN = 313,
PARS_NOTFOUND_TOKEN = 314,
PARS_TO_BINARY_TOKEN = 315,
PARS_SUBSTR_TOKEN = 316,
PARS_CONCAT_TOKEN = 317,
PARS_INSTR_TOKEN = 318,
PARS_LENGTH_TOKEN = 319,
PARS_COMMIT_TOKEN = 320,
PARS_ROLLBACK_TOKEN = 321,
PARS_WORK_TOKEN = 322,
PARS_EXIT_TOKEN = 323,
PARS_FUNCTION_TOKEN = 324,
PARS_LOCK_TOKEN = 325,
PARS_SHARE_TOKEN = 326,
PARS_MODE_TOKEN = 327,
PARS_LIKE_TOKEN = 328,
PARS_LIKE_TOKEN_EXACT = 329,
PARS_LIKE_TOKEN_PREFIX = 330,
PARS_LIKE_TOKEN_SUFFIX = 331,
PARS_LIKE_TOKEN_SUBSTR = 332,
PARS_TABLE_NAME_TOKEN = 333,
PARS_BIGINT_TOKEN = 334,
NEG = 335
};
#endif
......
......@@ -48,29 +48,15 @@ extern int yydebug;
NOT re-entrant */
extern sym_tab_t* pars_sym_tab_global;
extern pars_res_word_t pars_to_char_token;
extern pars_res_word_t pars_to_number_token;
extern pars_res_word_t pars_to_binary_token;
extern pars_res_word_t pars_binary_to_number_token;
extern pars_res_word_t pars_substr_token;
extern pars_res_word_t pars_replstr_token;
extern pars_res_word_t pars_concat_token;
extern pars_res_word_t pars_length_token;
extern pars_res_word_t pars_instr_token;
extern pars_res_word_t pars_sysdate_token;
extern pars_res_word_t pars_printf_token;
extern pars_res_word_t pars_assert_token;
extern pars_res_word_t pars_rnd_token;
extern pars_res_word_t pars_rnd_str_token;
extern pars_res_word_t pars_count_token;
extern pars_res_word_t pars_sum_token;
extern pars_res_word_t pars_distinct_token;
extern pars_res_word_t pars_binary_token;
extern pars_res_word_t pars_blob_token;
extern pars_res_word_t pars_int_token;
extern pars_res_word_t pars_bigint_token;
extern pars_res_word_t pars_char_token;
extern pars_res_word_t pars_float_token;
extern pars_res_word_t pars_update_token;
extern pars_res_word_t pars_asc_token;
extern pars_res_word_t pars_desc_token;
......@@ -236,17 +222,6 @@ pars_insert_statement(
que_node_t* values_list, /*!< in: value expression list or NULL */
sel_node_t* select); /*!< in: select condition or NULL */
/*********************************************************************//**
Parses a procedure parameter declaration.
@return own: symbol table node of type SYM_VAR */
sym_node_t*
pars_parameter_declaration(
/*=======================*/
sym_node_t* node, /*!< in: symbol table node allocated for the
id of the parameter */
ulint param_type,
/*!< in: PARS_INPUT or PARS_OUTPUT */
pars_res_word_t* type); /*!< in: pointer to a type token */
/*********************************************************************//**
Parses an elsif element.
@return elsif node */
elsif_node_t*
......@@ -358,8 +333,6 @@ pars_column_def(
pars_res_word_t* type, /*!< in: data type */
sym_node_t* len, /*!< in: length of column, or
NULL */
void* is_unsigned, /*!< in: if not NULL, column
is of type UNSIGNED. */
void* is_not_null); /*!< in: if not NULL, column
is of type NOT NULL. */
/*********************************************************************//**
......@@ -370,9 +343,7 @@ pars_create_table(
/*==============*/
sym_node_t* table_sym, /*!< in: table name node in the symbol
table */
sym_node_t* column_defs, /*!< in: list of column names */
sym_node_t* compact, /* in: non-NULL if COMPACT table. */
sym_node_t* block_size); /* in: block size (can be NULL) */
sym_node_t* column_defs); /*!< in: list of column names */
/*********************************************************************//**
Parses an index creation operation.
@return index create subgraph */
......@@ -394,7 +365,6 @@ pars_procedure_definition(
/*======================*/
sym_node_t* sym_node, /*!< in: procedure id node in the symbol
table */
sym_node_t* param_list, /*!< in: parameter declaration list */
que_node_t* stat_list); /*!< in: statement list */
/*************************************************************//**
......@@ -672,7 +642,6 @@ struct proc_node_t{
que_common_t common; /*!< type: QUE_NODE_PROC */
sym_node_t* proc_id; /*!< procedure name symbol in the symbol
table of this same procedure */
sym_node_t* param_list; /*!< input and output parameters */
que_node_t* stat_list; /*!< statement list */
sym_tab_t* sym_tab; /*!< symbol table of this procedure */
};
......@@ -747,7 +716,7 @@ struct col_assign_node_t{
#define PARS_FUNC_LOGICAL 2 /*!< AND, OR, NOT */
#define PARS_FUNC_CMP 3 /*!< comparison operators */
#define PARS_FUNC_PREDEFINED 4 /*!< TO_NUMBER, SUBSTR, ... */
#define PARS_FUNC_AGGREGATE 5 /*!< COUNT, DISTINCT, SUM */
#define PARS_FUNC_AGGREGATE 5 /*!< COUNT */
#define PARS_FUNC_OTHER 6 /*!< these are not real functions,
e.g., := */
/* @} */
......
This diff is collapsed.
This diff is collapsed.
/*****************************************************************************
Copyright (c) 1997, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -58,11 +58,7 @@ yylex(void);
%token PARS_NE_TOKEN
%token PARS_PROCEDURE_TOKEN
%token PARS_IN_TOKEN
%token PARS_OUT_TOKEN
%token PARS_BINARY_TOKEN
%token PARS_BLOB_TOKEN
%token PARS_INT_TOKEN
%token PARS_FLOAT_TOKEN
%token PARS_CHAR_TOKEN
%token PARS_IS_TOKEN
%token PARS_BEGIN_TOKEN
......@@ -75,14 +71,11 @@ yylex(void);
%token PARS_WHILE_TOKEN
%token PARS_RETURN_TOKEN
%token PARS_SELECT_TOKEN
%token PARS_SUM_TOKEN
%token PARS_COUNT_TOKEN
%token PARS_DISTINCT_TOKEN
%token PARS_FROM_TOKEN
%token PARS_WHERE_TOKEN
%token PARS_FOR_TOKEN
%token PARS_DDOT_TOKEN
%token PARS_READ_TOKEN
%token PARS_ORDER_TOKEN
%token PARS_BY_TOKEN
%token PARS_ASC_TOKEN
......@@ -109,25 +102,14 @@ yylex(void);
%token PARS_FETCH_TOKEN
%token PARS_CLOSE_TOKEN
%token PARS_NOTFOUND_TOKEN
%token PARS_TO_CHAR_TOKEN
%token PARS_TO_NUMBER_TOKEN
%token PARS_TO_BINARY_TOKEN
%token PARS_BINARY_TO_NUMBER_TOKEN
%token PARS_SUBSTR_TOKEN
%token PARS_REPLSTR_TOKEN
%token PARS_CONCAT_TOKEN
%token PARS_INSTR_TOKEN
%token PARS_LENGTH_TOKEN
%token PARS_SYSDATE_TOKEN
%token PARS_PRINTF_TOKEN
%token PARS_ASSERT_TOKEN
%token PARS_RND_TOKEN
%token PARS_RND_STR_TOKEN
%token PARS_ROW_PRINTF_TOKEN
%token PARS_COMMIT_TOKEN
%token PARS_ROLLBACK_TOKEN
%token PARS_WORK_TOKEN
%token PARS_UNSIGNED_TOKEN
%token PARS_EXIT_TOKEN
%token PARS_FUNCTION_TOKEN
%token PARS_LOCK_TOKEN
......@@ -139,8 +121,6 @@ yylex(void);
%token PARS_LIKE_TOKEN_SUFFIX
%token PARS_LIKE_TOKEN_SUBSTR
%token PARS_TABLE_NAME_TOKEN
%token PARS_COMPACT_TOKEN
%token PARS_BLOCK_SIZE_TOKEN
%token PARS_BIGINT_TOKEN
%left PARS_AND_TOKEN PARS_OR_TOKEN
......@@ -161,7 +141,6 @@ top_statement:
statement:
stored_procedure_call
| predefined_procedure_call ';'
| while_statement ';'
| for_statement ';'
| exit_statement ';'
......@@ -170,7 +149,6 @@ statement:
| assignment_statement ';'
| select_statement ';'
| insert_statement ';'
| row_printf_statement ';'
| delete_statement_searched ';'
| delete_statement_positioned ';'
| update_statement_searched ';'
......@@ -223,18 +201,11 @@ exp:
;
function_name:
PARS_TO_CHAR_TOKEN { $$ = &pars_to_char_token; }
| PARS_TO_NUMBER_TOKEN { $$ = &pars_to_number_token; }
| PARS_TO_BINARY_TOKEN { $$ = &pars_to_binary_token; }
| PARS_BINARY_TO_NUMBER_TOKEN
{ $$ = &pars_binary_to_number_token; }
PARS_TO_BINARY_TOKEN { $$ = &pars_to_binary_token; }
| PARS_SUBSTR_TOKEN { $$ = &pars_substr_token; }
| PARS_CONCAT_TOKEN { $$ = &pars_concat_token; }
| PARS_INSTR_TOKEN { $$ = &pars_instr_token; }
| PARS_LENGTH_TOKEN { $$ = &pars_length_token; }
| PARS_SYSDATE_TOKEN { $$ = &pars_sysdate_token; }
| PARS_RND_TOKEN { $$ = &pars_rnd_token; }
| PARS_RND_STR_TOKEN { $$ = &pars_rnd_str_token; }
;
question_mark_list:
......@@ -249,17 +220,6 @@ stored_procedure_call:
static_cast<sym_node_t*>($2)); }
;
predefined_procedure_call:
predefined_procedure_name '(' exp_list ')'
{ $$ = pars_procedure_call($1, $3); }
;
predefined_procedure_name:
PARS_REPLSTR_TOKEN { $$ = &pars_replstr_token; }
| PARS_PRINTF_TOKEN { $$ = &pars_printf_token; }
| PARS_ASSERT_TOKEN { $$ = &pars_assert_token; }
;
user_function_call:
PARS_ID_TOKEN '(' ')' { $$ = $1; }
;
......@@ -287,19 +247,9 @@ select_item:
exp { $$ = $1; }
| PARS_COUNT_TOKEN '(' '*' ')'
{ $$ = pars_func(&pars_count_token,
que_node_list_add_last(NULL,
que_node_list_add_last(NULL,
sym_tab_add_int_lit(
pars_sym_tab_global, 1))); }
| PARS_COUNT_TOKEN '(' PARS_DISTINCT_TOKEN PARS_ID_TOKEN ')'
{ $$ = pars_func(&pars_count_token,
que_node_list_add_last(NULL,
pars_func(&pars_distinct_token,
que_node_list_add_last(
NULL, $4)))); }
| PARS_SUM_TOKEN '(' exp ')'
{ $$ = pars_func(&pars_sum_token,
que_node_list_add_last(NULL,
$3)); }
;
select_item_list:
......@@ -446,12 +396,6 @@ delete_statement_positioned:
NULL); }
;
row_printf_statement:
PARS_ROW_PRINTF_TOKEN select_statement
{ $$ = pars_row_printf_statement(
static_cast<sel_node_t*>($2)); }
;
assignment_statement:
PARS_ID_TOKEN PARS_ASSIGN_TOKEN exp
{ $$ = pars_assignment_statement(
......@@ -536,12 +480,12 @@ fetch_statement:
;
column_def:
PARS_ID_TOKEN type_name opt_column_len opt_unsigned opt_not_null
PARS_ID_TOKEN type_name opt_column_len opt_not_null
{ $$ = pars_column_def(
static_cast<sym_node_t*>($1),
static_cast<pars_res_word_t*>($2),
static_cast<sym_node_t*>($3),
$4, $5); }
$4); }
;
column_def_list:
......@@ -556,13 +500,6 @@ opt_column_len:
{ $$ = $2; }
;
opt_unsigned:
/* Nothing */ { $$ = NULL; }
| PARS_UNSIGNED_TOKEN
{ $$ = &pars_int_token;
/* pass any non-NULL pointer */ }
;
opt_not_null:
/* Nothing */ { $$ = NULL; }
| PARS_NOT_TOKEN PARS_NULL_LIT
......@@ -570,27 +507,12 @@ opt_not_null:
/* pass any non-NULL pointer */ }
;
compact:
/* Nothing */ { $$ = NULL; }
| PARS_COMPACT_TOKEN { $$ = &pars_int_token;
/* pass any non-NULL pointer */ }
;
block_size:
/* Nothing */ { $$ = NULL; }
| PARS_BLOCK_SIZE_TOKEN '=' PARS_INT_LIT
{ $$ = $3; }
;
create_table:
PARS_CREATE_TOKEN PARS_TABLE_TOKEN
table_name '(' column_def_list ')'
compact block_size
{ $$ = pars_create_table(
static_cast<sym_node_t*>($3),
static_cast<sym_node_t*>($5),
static_cast<sym_node_t*>($7),
static_cast<sym_node_t*>($8)); }
static_cast<sym_node_t*>($5)); }
;
column_list:
......@@ -642,28 +564,6 @@ type_name:
PARS_INT_TOKEN { $$ = &pars_int_token; }
| PARS_BIGINT_TOKEN { $$ = &pars_bigint_token; }
| PARS_CHAR_TOKEN { $$ = &pars_char_token; }
| PARS_BINARY_TOKEN { $$ = &pars_binary_token; }
| PARS_BLOB_TOKEN { $$ = &pars_blob_token; }
;
parameter_declaration:
PARS_ID_TOKEN PARS_IN_TOKEN type_name
{ $$ = pars_parameter_declaration(
static_cast<sym_node_t*>($1),
PARS_INPUT,
static_cast<pars_res_word_t*>($3)); }
| PARS_ID_TOKEN PARS_OUT_TOKEN type_name
{ $$ = pars_parameter_declaration(
static_cast<sym_node_t*>($1),
PARS_OUTPUT,
static_cast<pars_res_word_t*>($3)); }
;
parameter_declaration_list:
/* Nothing */ { $$ = NULL; }
| parameter_declaration { $$ = que_node_list_add_last(NULL, $1); }
| parameter_declaration_list ',' parameter_declaration
{ $$ = que_node_list_add_last($1, $3); }
;
variable_declaration:
......@@ -705,16 +605,14 @@ declaration_list:
;
procedure_definition:
PARS_PROCEDURE_TOKEN PARS_ID_TOKEN '(' parameter_declaration_list ')'
PARS_PROCEDURE_TOKEN PARS_ID_TOKEN '(' ')'
PARS_IS_TOKEN
variable_declaration_list
declaration_list
PARS_BEGIN_TOKEN
statement_list
PARS_END_TOKEN { $$ = pars_procedure_definition(
static_cast<sym_node_t*>($2),
static_cast<sym_node_t*>($4),
$10); }
static_cast<sym_node_t*>($2), $9); }
;
%%
......@@ -249,30 +249,10 @@ In the state 'id', only two actions are possible (defined below). */
return(PARS_IN_TOKEN);
}
"OUT" {
return(PARS_OUT_TOKEN);
}
"BINARY" {
return(PARS_BINARY_TOKEN);
}
"BLOB" {
return(PARS_BLOB_TOKEN);
}
"INT" {
return(PARS_INT_TOKEN);
}
"INTEGER" {
return(PARS_INT_TOKEN);
}
"FLOAT" {
return(PARS_FLOAT_TOKEN);
}
"CHAR" {
return(PARS_CHAR_TOKEN);
}
......@@ -321,18 +301,10 @@ In the state 'id', only two actions are possible (defined below). */
return(PARS_SELECT_TOKEN);
}
"SUM" {
return(PARS_SUM_TOKEN);
}
"COUNT" {
return(PARS_COUNT_TOKEN);
}
"DISTINCT" {
return(PARS_DISTINCT_TOKEN);
}
"FROM" {
return(PARS_FROM_TOKEN);
}
......@@ -345,10 +317,6 @@ In the state 'id', only two actions are possible (defined below). */
return(PARS_FOR_TOKEN);
}
"READ" {
return(PARS_READ_TOKEN);
}
"ORDER" {
return(PARS_ORDER_TOKEN);
}
......@@ -405,14 +373,6 @@ In the state 'id', only two actions are possible (defined below). */
return(PARS_TABLE_TOKEN);
}
"COMPACT" {
return(PARS_COMPACT_TOKEN);
}
"BLOCK_SIZE" {
return(PARS_BLOCK_SIZE_TOKEN);
}
"INDEX" {
return(PARS_INDEX_TOKEN);
}
......@@ -453,30 +413,14 @@ In the state 'id', only two actions are possible (defined below). */
return(PARS_NOTFOUND_TOKEN);
}
"TO_CHAR" {
return(PARS_TO_CHAR_TOKEN);
}
"TO_NUMBER" {
return(PARS_TO_NUMBER_TOKEN);
}
"TO_BINARY" {
return(PARS_TO_BINARY_TOKEN);
}
"BINARY_TO_NUMBER" {
return(PARS_BINARY_TO_NUMBER_TOKEN);
}
"SUBSTR" {
return(PARS_SUBSTR_TOKEN);
}
"REPLSTR" {
return(PARS_REPLSTR_TOKEN);
}
"CONCAT" {
return(PARS_CONCAT_TOKEN);
}
......@@ -489,30 +433,6 @@ In the state 'id', only two actions are possible (defined below). */
return(PARS_LENGTH_TOKEN);
}
"SYSDATE" {
return(PARS_SYSDATE_TOKEN);
}
"PRINTF" {
return(PARS_PRINTF_TOKEN);
}
"ASSERT" {
return(PARS_ASSERT_TOKEN);
}
"RND" {
return(PARS_RND_TOKEN);
}
"RND_STR" {
return(PARS_RND_STR_TOKEN);
}
"ROW_PRINTF" {
return(PARS_ROW_PRINTF_TOKEN);
}
"COMMIT" {
return(PARS_COMMIT_TOKEN);
}
......@@ -525,10 +445,6 @@ In the state 'id', only two actions are possible (defined below). */
return(PARS_WORK_TOKEN);
}
"UNSIGNED" {
return(PARS_UNSIGNED_TOKEN);
}
"EXIT" {
return(PARS_EXIT_TOKEN);
}
......
......@@ -50,29 +50,15 @@ sym_tab_t* pars_sym_tab_global;
/* Global variables used to denote certain reserved words, used in
constructing the parsing tree */
pars_res_word_t pars_to_char_token = {PARS_TO_CHAR_TOKEN};
pars_res_word_t pars_to_number_token = {PARS_TO_NUMBER_TOKEN};
pars_res_word_t pars_to_binary_token = {PARS_TO_BINARY_TOKEN};
pars_res_word_t pars_binary_to_number_token = {PARS_BINARY_TO_NUMBER_TOKEN};
pars_res_word_t pars_substr_token = {PARS_SUBSTR_TOKEN};
pars_res_word_t pars_replstr_token = {PARS_REPLSTR_TOKEN};
pars_res_word_t pars_concat_token = {PARS_CONCAT_TOKEN};
pars_res_word_t pars_instr_token = {PARS_INSTR_TOKEN};
pars_res_word_t pars_length_token = {PARS_LENGTH_TOKEN};
pars_res_word_t pars_sysdate_token = {PARS_SYSDATE_TOKEN};
pars_res_word_t pars_printf_token = {PARS_PRINTF_TOKEN};
pars_res_word_t pars_assert_token = {PARS_ASSERT_TOKEN};
pars_res_word_t pars_rnd_token = {PARS_RND_TOKEN};
pars_res_word_t pars_rnd_str_token = {PARS_RND_STR_TOKEN};
pars_res_word_t pars_count_token = {PARS_COUNT_TOKEN};
pars_res_word_t pars_sum_token = {PARS_SUM_TOKEN};
pars_res_word_t pars_distinct_token = {PARS_DISTINCT_TOKEN};
pars_res_word_t pars_binary_token = {PARS_BINARY_TOKEN};
pars_res_word_t pars_blob_token = {PARS_BLOB_TOKEN};
pars_res_word_t pars_int_token = {PARS_INT_TOKEN};
pars_res_word_t pars_bigint_token = {PARS_BIGINT_TOKEN};
pars_res_word_t pars_char_token = {PARS_CHAR_TOKEN};
pars_res_word_t pars_float_token = {PARS_FLOAT_TOKEN};
pars_res_word_t pars_update_token = {PARS_UPDATE_TOKEN};
pars_res_word_t pars_asc_token = {PARS_ASC_TOKEN};
pars_res_word_t pars_desc_token = {PARS_DESC_TOKEN};
......@@ -195,24 +181,15 @@ pars_func_get_class(
case PARS_AND_TOKEN: case PARS_OR_TOKEN: case PARS_NOT_TOKEN:
return(PARS_FUNC_LOGICAL);
case PARS_COUNT_TOKEN: case PARS_SUM_TOKEN:
case PARS_COUNT_TOKEN:
return(PARS_FUNC_AGGREGATE);
case PARS_TO_CHAR_TOKEN:
case PARS_TO_NUMBER_TOKEN:
case PARS_TO_BINARY_TOKEN:
case PARS_BINARY_TO_NUMBER_TOKEN:
case PARS_SUBSTR_TOKEN:
case PARS_CONCAT_TOKEN:
case PARS_LENGTH_TOKEN:
case PARS_INSTR_TOKEN:
case PARS_SYSDATE_TOKEN:
case PARS_NOTFOUND_TOKEN:
case PARS_PRINTF_TOKEN:
case PARS_ASSERT_TOKEN:
case PARS_RND_TOKEN:
case PARS_RND_STR_TOKEN:
case PARS_REPLSTR_TOKEN:
return(PARS_FUNC_PREDEFINED);
default:
......@@ -499,7 +476,6 @@ pars_resolve_func_data_type(
arg = node->args;
switch (node->func) {
case PARS_SUM_TOKEN:
case '+': case '-': case '*': case '/':
/* Inherit the data type from the first argument (which must
not be the SQL null literal whose type is DATA_ERROR) */
......@@ -516,13 +492,6 @@ pars_resolve_func_data_type(
dtype_set(que_node_get_data_type(node), DATA_INT, 0, 4);
break;
case PARS_TO_CHAR_TOKEN:
case PARS_RND_STR_TOKEN:
ut_a(dtype_get_mtype(que_node_get_data_type(arg)) == DATA_INT);
dtype_set(que_node_get_data_type(node), DATA_VARCHAR,
DATA_ENGLISH, 0);
break;
case PARS_TO_BINARY_TOKEN:
if (dtype_get_mtype(que_node_get_data_type(arg)) == DATA_INT) {
dtype_set(que_node_get_data_type(node), DATA_VARCHAR,
......@@ -533,19 +502,12 @@ pars_resolve_func_data_type(
}
break;
case PARS_TO_NUMBER_TOKEN:
case PARS_BINARY_TO_NUMBER_TOKEN:
case PARS_LENGTH_TOKEN:
case PARS_INSTR_TOKEN:
ut_a(pars_is_string_type(que_node_get_data_type(arg)->mtype));
dtype_set(que_node_get_data_type(node), DATA_INT, 0, 4);
break;
case PARS_SYSDATE_TOKEN:
ut_a(arg == NULL);
dtype_set(que_node_get_data_type(node), DATA_INT, 0, 4);
break;
case PARS_SUBSTR_TOKEN:
case PARS_CONCAT_TOKEN:
ut_a(pars_is_string_type(que_node_get_data_type(arg)->mtype));
......@@ -566,11 +528,6 @@ pars_resolve_func_data_type(
dtype_set(que_node_get_data_type(node), DATA_INT, 0, 4);
break;
case PARS_RND_TOKEN:
ut_a(dtype_get_mtype(que_node_get_data_type(arg)) == DATA_INT);
dtype_set(que_node_get_data_type(node), DATA_INT, 0, 4);
break;
case PARS_LIKE_TOKEN_EXACT:
case PARS_LIKE_TOKEN_PREFIX:
case PARS_LIKE_TOKEN_SUFFIX:
......@@ -1355,9 +1312,7 @@ pars_set_dfield_type(
pars_res_word_t* type, /*!< in: pointer to a type
token */
ulint len, /*!< in: length, or 0 */
ibool is_unsigned, /*!< in: if TRUE, column is
UNSIGNED. */
ibool is_not_null) /*!< in: if TRUE, column is
bool is_not_null) /*!< in: whether the column is
NOT NULL. */
{
ulint flags = 0;
......@@ -1366,10 +1321,6 @@ pars_set_dfield_type(
flags |= DATA_NOT_NULL;
}
if (is_unsigned) {
flags |= DATA_UNSIGNED;
}
if (type == &pars_bigint_token) {
ut_a(len == 0);
......@@ -1384,16 +1335,6 @@ pars_set_dfield_type(
dtype_set(dfield_get_type(dfield), DATA_VARCHAR,
DATA_ENGLISH | flags, len);
} else if (type == &pars_binary_token) {
ut_a(len != 0);
dtype_set(dfield_get_type(dfield), DATA_FIXBINARY,
DATA_BINARY_TYPE | flags, len);
} else if (type == &pars_blob_token) {
ut_a(len == 0);
dtype_set(dfield_get_type(dfield), DATA_BLOB,
DATA_BINARY_TYPE | flags, 0);
} else {
ut_error;
}
......@@ -1414,28 +1355,7 @@ pars_variable_declaration(
node->param_type = PARS_NOT_PARAM;
pars_set_dfield_type(que_node_get_val(node), type, 0, FALSE, FALSE);
return(node);
}
/*********************************************************************//**
Parses a procedure parameter declaration.
@return own: symbol table node of type SYM_VAR */
sym_node_t*
pars_parameter_declaration(
/*=======================*/
sym_node_t* node, /*!< in: symbol table node allocated for the
id of the parameter */
ulint param_type,
/*!< in: PARS_INPUT or PARS_OUTPUT */
pars_res_word_t* type) /*!< in: pointer to a type token */
{
ut_a((param_type == PARS_INPUT) || (param_type == PARS_OUTPUT));
pars_variable_declaration(node, type);
node->param_type = param_type;
pars_set_dfield_type(que_node_get_val(node), type, 0, false);
return(node);
}
......@@ -1821,8 +1741,6 @@ pars_column_def(
pars_res_word_t* type, /*!< in: data type */
sym_node_t* len, /*!< in: length of column, or
NULL */
void* is_unsigned, /*!< in: if not NULL, column
is of type UNSIGNED. */
void* is_not_null) /*!< in: if not NULL, column
is of type NOT NULL. */
{
......@@ -1835,7 +1753,7 @@ pars_column_def(
}
pars_set_dfield_type(que_node_get_val(sym_node), type, len2,
is_unsigned != NULL, is_not_null != NULL);
is_not_null != NULL);
return(sym_node);
}
......@@ -1848,9 +1766,7 @@ pars_create_table(
/*==============*/
sym_node_t* table_sym, /*!< in: table name node in the symbol
table */
sym_node_t* column_defs, /*!< in: list of column names */
sym_node_t* compact, /* in: non-NULL if COMPACT table. */
sym_node_t* block_size) /* in: block size (can be NULL) */
sym_node_t* column_defs) /*!< in: list of column names */
{
dict_table_t* table;
sym_node_t* column;
......@@ -1858,57 +1774,11 @@ pars_create_table(
const dtype_t* dtype;
ulint n_cols;
ulint flags = 0;
ulint flags2 = 0;
if (compact != NULL) {
/* System tables currently only use the REDUNDANT row
format therefore the check for srv_file_per_table should be
safe for now. */
flags |= DICT_TF_COMPACT;
/* FIXME: Ideally this should be part of the SQL syntax
or use some other mechanism. We want to reduce dependency
on global variables. There is an inherent race here but
that has always existed around this variable. */
if (srv_file_per_table) {
flags2 |= DICT_TF2_USE_FILE_PER_TABLE;
}
}
if (block_size != NULL) {
ulint size;
dfield_t* dfield;
ulint flags2 = DICT_TF2_FTS_AUX_HEX_NAME;
dfield = que_node_get_val(block_size);
ut_a(dfield_get_len(dfield) == 4);
size = mach_read_from_4(static_cast<byte*>(
dfield_get_data(dfield)));
switch (size) {
case 0:
break;
case 1: case 2: case 4: case 8: case 16:
flags |= DICT_TF_COMPACT;
/* FTS-FIXME: needs the zip changes */
/* flags |= size << DICT_TF_COMPRESSED_SHIFT; */
break;
default:
ut_error;
}
}
/* Set the flags2 when create table or alter tables */
flags2 |= DICT_TF2_FTS_AUX_HEX_NAME;
DBUG_EXECUTE_IF("innodb_test_wrong_fts_aux_table_name",
flags2 &= ~DICT_TF2_FTS_AUX_HEX_NAME;);
n_cols = que_node_list_get_len(column_defs);
table = dict_mem_table_create(
......@@ -2001,7 +1871,6 @@ pars_procedure_definition(
/*======================*/
sym_node_t* sym_node, /*!< in: procedure id node in the symbol
table */
sym_node_t* param_list, /*!< in: parameter declaration list */
que_node_t* stat_list) /*!< in: statement list */
{
proc_node_t* node;
......@@ -2026,7 +1895,6 @@ pars_procedure_definition(
sym_node->resolved = TRUE;
node->proc_id = sym_node;
node->param_list = param_list;
node->stat_list = stat_list;
pars_set_parent_in_list(stat_list, node);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment