Temporary commit of merge of MariaDB 10.0-base and MySQL 5.6

This commit is contained in:
Michael Widenius 2012-08-01 17:27:34 +03:00
commit 1d0f70c2f8
557 changed files with 124529 additions and 30315 deletions

View file

@ -1,24 +1,24 @@
#!/bin/bash
#
# Copyright (c) 2006, 2009, Innobase Oy. All Rights Reserved.
#
# Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
#
# 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
# Foundation; version 2 of the License.
#
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
#
# generate parser files from bison input files.
set -eu
TMPFILE=pars0grm.tab.c
OUTFILE=pars0grm.c
OUTFILE=pars0grm.cc
bison -d pars0grm.y
mv pars0grm.tab.h ../include/pars0grm.h

View file

@ -1,25 +1,25 @@
#!/bin/bash
#
# Copyright (c) 2006, 2009, Innobase Oy. All Rights Reserved.
#
# Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
#
# 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
# Foundation; version 2 of the License.
#
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
#
# generate lexer files from flex input files.
set -eu
TMPFILE=_flex_tmp.c
OUTFILE=lexyy.c
TMPFILE=_flex_tmp.cc
OUTFILE=lexyy.cc
flex -o $TMPFILE pars0lex.l

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
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
@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
*****************************************************************************/
@ -137,6 +137,15 @@ yylex(void);
%token PARS_LOCK_TOKEN
%token PARS_SHARE_TOKEN
%token PARS_MODE_TOKEN
%token PARS_LIKE_TOKEN
%token PARS_LIKE_TOKEN_EXACT
%token PARS_LIKE_TOKEN_PREFIX
%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
%left PARS_NOT_TOKEN
@ -201,8 +210,10 @@ exp:
| '-' exp %prec NEG { $$ = pars_op('-', $2, NULL); }
| '(' exp ')' { $$ = $2; }
| exp '=' exp { $$ = pars_op('=', $1, $3); }
| exp '<' exp { $$ = pars_op('<', $1, $3); }
| exp '>' exp { $$ = pars_op('>', $1, $3); }
| exp PARS_LIKE_TOKEN PARS_STR_LIT
{ $$ = pars_op(PARS_LIKE_TOKEN, $1, $3); }
| exp '<' exp { $$ = pars_op('<', $1, $3); }
| exp '>' exp { $$ = pars_op('>', $1, $3); }
| exp PARS_GE_TOKEN exp { $$ = pars_op(PARS_GE_TOKEN, $1, $3); }
| exp PARS_LE_TOKEN exp { $$ = pars_op(PARS_LE_TOKEN, $1, $3); }
| exp PARS_NE_TOKEN exp { $$ = pars_op(PARS_NE_TOKEN, $1, $3); }
@ -238,7 +249,8 @@ question_mark_list:
stored_procedure_call:
'{' PARS_ID_TOKEN '(' question_mark_list ')' '}'
{ $$ = pars_stored_procedure_call($2); }
{ $$ = pars_stored_procedure_call(
static_cast<sym_node_t*>($2)); }
;
predefined_procedure_call:
@ -257,8 +269,8 @@ user_function_call:
;
table_list:
PARS_ID_TOKEN { $$ = que_node_list_add_last(NULL, $1); }
| table_list ',' PARS_ID_TOKEN
table_name { $$ = que_node_list_add_last(NULL, $1); }
| table_list ',' table_name
{ $$ = que_node_list_add_last($1, $3); }
;
@ -305,7 +317,8 @@ select_list:
'*' { $$ = pars_select_list(&pars_star_denoter,
NULL); }
| select_item_list PARS_INTO_TOKEN variable_list
{ $$ = pars_select_list($1, $3); }
{ $$ = pars_select_list(
$1, static_cast<sym_node_t*>($3)); }
| select_item_list { $$ = pars_select_list($1, NULL); }
;
@ -335,7 +348,9 @@ order_direction:
order_by_clause:
/* Nothing */ { $$ = NULL; }
| PARS_ORDER_TOKEN PARS_BY_TOKEN PARS_ID_TOKEN order_direction
{ $$ = pars_order_by($3, $4); }
{ $$ = pars_order_by(
static_cast<sym_node_t*>($3),
static_cast<pars_res_word_t*>($4)); }
;
select_statement:
@ -344,24 +359,35 @@ select_statement:
search_condition
for_update_clause
lock_shared_clause
order_by_clause { $$ = pars_select_statement($2, $4, $5,
$6, $7, $8); }
order_by_clause { $$ = pars_select_statement(
static_cast<sel_node_t*>($2),
static_cast<sym_node_t*>($4),
static_cast<que_node_t*>($5),
static_cast<pars_res_word_t*>($6),
static_cast<pars_res_word_t*>($7),
static_cast<order_node_t*>($8)); }
;
insert_statement_start:
PARS_INSERT_TOKEN PARS_INTO_TOKEN
PARS_ID_TOKEN { $$ = $3; }
table_name { $$ = $3; }
;
insert_statement:
insert_statement_start PARS_VALUES_TOKEN '(' exp_list ')'
{ $$ = pars_insert_statement($1, $4, NULL); }
{ $$ = pars_insert_statement(
static_cast<sym_node_t*>($1), $4, NULL); }
| insert_statement_start select_statement
{ $$ = pars_insert_statement($1, NULL, $2); }
{ $$ = pars_insert_statement(
static_cast<sym_node_t*>($1),
NULL,
static_cast<sel_node_t*>($2)); }
;
column_assignment:
PARS_ID_TOKEN '=' exp { $$ = pars_column_assignment($1, $3); }
PARS_ID_TOKEN '=' exp { $$ = pars_column_assignment(
static_cast<sym_node_t*>($1),
static_cast<que_node_t*>($3)); }
;
column_assignment_list:
@ -377,46 +403,64 @@ cursor_positioned:
;
update_statement_start:
PARS_UPDATE_TOKEN PARS_ID_TOKEN
PARS_UPDATE_TOKEN table_name
PARS_SET_TOKEN
column_assignment_list { $$ = pars_update_statement_start(FALSE,
$2, $4); }
column_assignment_list { $$ = pars_update_statement_start(
FALSE,
static_cast<sym_node_t*>($2),
static_cast<col_assign_node_t*>($4)); }
;
update_statement_searched:
update_statement_start
search_condition { $$ = pars_update_statement($1, NULL, $2); }
search_condition { $$ = pars_update_statement(
static_cast<upd_node_t*>($1),
NULL,
static_cast<que_node_t*>($2)); }
;
update_statement_positioned:
update_statement_start
cursor_positioned { $$ = pars_update_statement($1, $2, NULL); }
cursor_positioned { $$ = pars_update_statement(
static_cast<upd_node_t*>($1),
static_cast<sym_node_t*>($2),
NULL); }
;
delete_statement_start:
PARS_DELETE_TOKEN PARS_FROM_TOKEN
PARS_ID_TOKEN { $$ = pars_update_statement_start(TRUE,
$3, NULL); }
table_name { $$ = pars_update_statement_start(
TRUE,
static_cast<sym_node_t*>($3), NULL); }
;
delete_statement_searched:
delete_statement_start
search_condition { $$ = pars_update_statement($1, NULL, $2); }
search_condition { $$ = pars_update_statement(
static_cast<upd_node_t*>($1),
NULL,
static_cast<que_node_t*>($2)); }
;
delete_statement_positioned:
delete_statement_start
cursor_positioned { $$ = pars_update_statement($1, $2, NULL); }
cursor_positioned { $$ = pars_update_statement(
static_cast<upd_node_t*>($1),
static_cast<sym_node_t*>($2),
NULL); }
;
row_printf_statement:
PARS_ROW_PRINTF_TOKEN select_statement
{ $$ = pars_row_printf_statement($2); }
{ $$ = pars_row_printf_statement(
static_cast<sel_node_t*>($2)); }
;
assignment_statement:
PARS_ID_TOKEN PARS_ASSIGN_TOKEN exp
{ $$ = pars_assignment_statement($1, $3); }
{ $$ = pars_assignment_statement(
static_cast<sym_node_t*>($1),
static_cast<que_node_t*>($3)); }
;
elsif_element:
@ -456,7 +500,9 @@ for_statement:
exp PARS_DDOT_TOKEN exp
PARS_LOOP_TOKEN statement_list
PARS_END_TOKEN PARS_LOOP_TOKEN
{ $$ = pars_for_statement($2, $4, $6, $8); }
{ $$ = pars_for_statement(
static_cast<sym_node_t*>($2),
$4, $6, $8); }
;
exit_statement:
@ -470,25 +516,36 @@ return_statement:
open_cursor_statement:
PARS_OPEN_TOKEN PARS_ID_TOKEN
{ $$ = pars_open_statement(
ROW_SEL_OPEN_CURSOR, $2); }
ROW_SEL_OPEN_CURSOR,
static_cast<sym_node_t*>($2)); }
;
close_cursor_statement:
PARS_CLOSE_TOKEN PARS_ID_TOKEN
{ $$ = pars_open_statement(
ROW_SEL_CLOSE_CURSOR, $2); }
ROW_SEL_CLOSE_CURSOR,
static_cast<sym_node_t*>($2)); }
;
fetch_statement:
PARS_FETCH_TOKEN PARS_ID_TOKEN PARS_INTO_TOKEN variable_list
{ $$ = pars_fetch_statement($2, $4, NULL); }
{ $$ = pars_fetch_statement(
static_cast<sym_node_t*>($2),
static_cast<sym_node_t*>($4), NULL); }
| PARS_FETCH_TOKEN PARS_ID_TOKEN PARS_INTO_TOKEN user_function_call
{ $$ = pars_fetch_statement($2, NULL, $4); }
{ $$ = pars_fetch_statement(
static_cast<sym_node_t*>($2),
NULL,
static_cast<sym_node_t*>($4)); }
;
column_def:
PARS_ID_TOKEN type_name opt_column_len opt_unsigned opt_not_null
{ $$ = pars_column_def($1, $2, $3, $4, $5); }
{ $$ = pars_column_def(
static_cast<sym_node_t*>($1),
static_cast<pars_res_word_t*>($2),
static_cast<sym_node_t*>($3),
$4, $5); }
;
column_def_list:
@ -524,10 +581,27 @@ not_fit_in_memory:
/* 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
PARS_ID_TOKEN '(' column_def_list ')'
not_fit_in_memory { $$ = pars_create_table($3, $5, $7); }
table_name '(' column_def_list ')'
not_fit_in_memory compact block_size
{ $$ = pars_create_table(
static_cast<sym_node_t*>($3),
static_cast<sym_node_t*>($5),
static_cast<sym_node_t*>($8),
static_cast<sym_node_t*>($9), $7); }
;
column_list:
@ -550,8 +624,19 @@ create_index:
PARS_CREATE_TOKEN unique_def
clustered_def
PARS_INDEX_TOKEN
PARS_ID_TOKEN PARS_ON_TOKEN PARS_ID_TOKEN
'(' column_list ')' { $$ = pars_create_index($2, $3, $5, $7, $9); }
PARS_ID_TOKEN PARS_ON_TOKEN
table_name
'(' column_list ')' { $$ = pars_create_index(
static_cast<pars_res_word_t*>($2),
static_cast<pars_res_word_t*>($3),
static_cast<sym_node_t*>($5),
static_cast<sym_node_t*>($7),
static_cast<sym_node_t*>($9)); }
;
table_name:
PARS_ID_TOKEN { $$ = $1; }
| PARS_TABLE_NAME_TOKEN { $$ = $1; }
;
commit_statement:
@ -567,6 +652,7 @@ rollback_statement:
type_name:
PARS_INT_TOKEN { $$ = &pars_int_token; }
| PARS_INTEGER_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; }
@ -574,11 +660,15 @@ type_name:
parameter_declaration:
PARS_ID_TOKEN PARS_IN_TOKEN type_name
{ $$ = pars_parameter_declaration($1,
PARS_INPUT, $3); }
{ $$ = 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($1,
PARS_OUTPUT, $3); }
{ $$ = pars_parameter_declaration(
static_cast<sym_node_t*>($1),
PARS_OUTPUT,
static_cast<pars_res_word_t*>($3)); }
;
parameter_declaration_list:
@ -590,7 +680,9 @@ parameter_declaration_list:
variable_declaration:
PARS_ID_TOKEN type_name ';'
{ $$ = pars_variable_declaration($1, $2); }
{ $$ = pars_variable_declaration(
static_cast<sym_node_t*>($1),
static_cast<pars_res_word_t*>($2)); }
;
variable_declaration_list:
@ -602,12 +694,15 @@ variable_declaration_list:
cursor_declaration:
PARS_DECLARE_TOKEN PARS_CURSOR_TOKEN PARS_ID_TOKEN
PARS_IS_TOKEN select_statement ';'
{ $$ = pars_cursor_declaration($3, $5); }
{ $$ = pars_cursor_declaration(
static_cast<sym_node_t*>($3),
static_cast<sel_node_t*>($5)); }
;
function_declaration:
PARS_DECLARE_TOKEN PARS_FUNCTION_TOKEN PARS_ID_TOKEN ';'
{ $$ = pars_function_declaration($3); }
{ $$ = pars_function_declaration(
static_cast<sym_node_t*>($3)); }
;
declaration:
@ -628,8 +723,10 @@ procedure_definition:
declaration_list
PARS_BEGIN_TOKEN
statement_list
PARS_END_TOKEN { $$ = pars_procedure_definition($2, $4,
$10); }
PARS_END_TOKEN { $$ = pars_procedure_definition(
static_cast<sym_node_t*>($2),
static_cast<sym_node_t*>($4),
$10); }
;
%%

View file

@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
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
@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
*****************************************************************************/
@ -64,7 +64,9 @@ Created 12/14/1997 Heikki Tuuri
#define realloc(P, A) ut_realloc(P, A)
#define exit(A) ut_error
#define YY_INPUT(buf, result, max_size) pars_get_lex_chars(buf, &result, max_size)
/* Note: We cast &result to int* from yysize_t* */
#define YY_INPUT(buf, result, max_size) \
pars_get_lex_chars(buf, (int*) &result, max_size)
/* String buffer for removing quotes */
static ulint stringbuf_len_alloc = 0; /* Allocated length */
@ -79,7 +81,7 @@ string_append(
ulint len) /*!< in: length of the string */
{
if (stringbuf == NULL) {
stringbuf = malloc(1);
stringbuf = static_cast<char*>(malloc(1));
stringbuf_len_alloc = 1;
}
@ -87,7 +89,9 @@ string_append(
while (stringbuf_len + len > stringbuf_len_alloc) {
stringbuf_len_alloc <<= 1;
}
stringbuf = realloc(stringbuf, stringbuf_len_alloc);
stringbuf = static_cast<char*>(
realloc(stringbuf, stringbuf_len_alloc));
}
memcpy(stringbuf + stringbuf_len, str, len);
@ -96,8 +100,9 @@ string_append(
%}
DIGIT [0-9]
ID [a-z_A-Z][a-z_A-Z0-9]*
DIGIT [0-9]
ID [a-z_A-Z][a-z_A-Z0-9]*
TABLE_NAME [a-z_A-Z][a-z_A-Z0-9]*\/(#sql-|[a-z_A-Z])[a-z_A-Z0-9]*
BOUND_LIT \:[a-z_A-Z0-9]+
BOUND_ID \$[a-z_A-Z0-9]+
@ -249,27 +254,27 @@ In the state 'id', only two actions are possible (defined below). */
}
"BINARY" {
return(PARS_BINARY_TOKEN);
return(PARS_BINARY_TOKEN);
}
"BLOB" {
return(PARS_BLOB_TOKEN);
return(PARS_BLOB_TOKEN);
}
"INT" {
return(PARS_INT_TOKEN);
return(PARS_INT_TOKEN);
}
"INTEGER" {
return(PARS_INT_TOKEN);
return(PARS_INT_TOKEN);
}
"FLOAT" {
return(PARS_FLOAT_TOKEN);
return(PARS_FLOAT_TOKEN);
}
"CHAR" {
return(PARS_CHAR_TOKEN);
return(PARS_CHAR_TOKEN);
}
"IS" {
@ -400,16 +405,24 @@ 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);
return(PARS_INDEX_TOKEN);
}
"UNIQUE" {
return(PARS_UNIQUE_TOKEN);
return(PARS_UNIQUE_TOKEN);
}
"CLUSTERED" {
return(PARS_CLUSTERED_TOKEN);
return(PARS_CLUSTERED_TOKEN);
}
"DOES_NOT_FIT_IN_MEMORY" {
@ -417,7 +430,7 @@ In the state 'id', only two actions are possible (defined below). */
}
"ON" {
return(PARS_ON_TOKEN);
return(PARS_ON_TOKEN);
}
"DECLARE" {
@ -540,13 +553,28 @@ In the state 'id', only two actions are possible (defined below). */
return(PARS_MODE_TOKEN);
}
"LIKE" {
return(PARS_LIKE_TOKEN);
}
"BIGINT" {
return(PARS_BIGINT_TOKEN);
}
{ID} {
yylval = sym_tab_add_id(pars_sym_tab_global,
(byte*)yytext,
(byte*) yytext,
ut_strlen(yytext));
return(PARS_ID_TOKEN);
}
{TABLE_NAME} {
yylval = sym_tab_add_id(pars_sym_tab_global,
(byte*) yytext,
ut_strlen(yytext));
return(PARS_TABLE_NAME_TOKEN);
}
".." {
return(PARS_DDOT_TOKEN);
}

View file

@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
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
@ -11,13 +11,13 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
*****************************************************************************/
/**************************************************//**
@file pars/pars0opt.c
@file pars/pars0opt.cc
Simple SQL optimizer
Created 12/21/1997 Heikki Tuuri
@ -68,6 +68,7 @@ opt_invert_cmp_op(
} else if (op == PARS_GE_TOKEN) {
return(PARS_LE_TOKEN);
} else {
/* TODO: LIKE operator */
ut_error;
}
@ -96,7 +97,7 @@ opt_check_exp_determined_before(
ut_ad(exp && sel_node);
if (que_node_get_type(exp) == QUE_NODE_FUNC) {
func_node = exp;
func_node = static_cast<func_node_t*>(exp);
arg = func_node->args;
@ -114,7 +115,7 @@ opt_check_exp_determined_before(
ut_a(que_node_get_type(exp) == QUE_NODE_SYMBOL);
sym_node = exp;
sym_node = static_cast<sym_node_t*>(exp);
if (sym_node->token_type != SYM_COLUMN) {
@ -165,11 +166,18 @@ opt_look_for_col_in_comparison_before(
|| (search_cond->func == '>')
|| (search_cond->func == '=')
|| (search_cond->func == PARS_GE_TOKEN)
|| (search_cond->func == PARS_LE_TOKEN));
|| (search_cond->func == PARS_LE_TOKEN)
|| (search_cond->func == PARS_LIKE_TOKEN_EXACT)
|| (search_cond->func == PARS_LIKE_TOKEN_PREFIX)
|| (search_cond->func == PARS_LIKE_TOKEN_SUFFIX)
|| (search_cond->func == PARS_LIKE_TOKEN_SUBSTR));
table = sel_node_get_nth_plan(sel_node, nth_table)->table;
if ((cmp_type == OPT_EQUAL) && (search_cond->func != '=')) {
if ((cmp_type == OPT_EQUAL)
&& (search_cond->func != '=')
&& (search_cond->func != PARS_LIKE_TOKEN_EXACT)
&& (search_cond->func != PARS_LIKE_TOKEN_PREFIX)) {
return(NULL);
@ -177,7 +185,9 @@ opt_look_for_col_in_comparison_before(
&& (search_cond->func != '<')
&& (search_cond->func != '>')
&& (search_cond->func != PARS_GE_TOKEN)
&& (search_cond->func != PARS_LE_TOKEN)) {
&& (search_cond->func != PARS_LE_TOKEN)
&& (search_cond->func != PARS_LIKE_TOKEN_PREFIX)
&& (search_cond->func != PARS_LIKE_TOKEN_SUFFIX)) {
return(NULL);
}
@ -185,7 +195,7 @@ opt_look_for_col_in_comparison_before(
arg = search_cond->args;
if (que_node_get_type(arg) == QUE_NODE_SYMBOL) {
sym_node = arg;
sym_node = static_cast<sym_node_t*>(arg);
if ((sym_node->token_type == SYM_COLUMN)
&& (sym_node->table == table)
@ -211,7 +221,7 @@ opt_look_for_col_in_comparison_before(
arg = que_node_get_next(arg);
if (que_node_get_type(arg) == QUE_NODE_SYMBOL) {
sym_node = arg;
sym_node = static_cast<sym_node_t*>(arg);
if ((sym_node->token_type == SYM_COLUMN)
&& (sym_node->table == table)
@ -262,7 +272,7 @@ opt_look_for_col_in_cond_before(
ut_a(search_cond->func != PARS_NOT_TOKEN);
if (search_cond->func == PARS_AND_TOKEN) {
new_cond = search_cond->args;
new_cond = static_cast<func_node_t*>(search_cond->args);
exp = opt_look_for_col_in_cond_before(cmp_type, col_no,
new_cond, sel_node,
@ -272,7 +282,8 @@ opt_look_for_col_in_cond_before(
return(exp);
}
new_cond = que_node_get_next(new_cond);
new_cond = static_cast<func_node_t*>(
que_node_get_next(new_cond));
exp = opt_look_for_col_in_cond_before(cmp_type, col_no,
new_cond, sel_node,
@ -332,6 +343,12 @@ opt_calc_index_goodness(
ulint op;
ulint j;
/* At least for now we don't support using FTS indexes for queries
done through InnoDB's own SQL parser. */
if (index->type == DICT_FTS) {
return(0);
}
goodness = 0;
/* Note that as higher level node pointers in the B-tree contain
@ -346,7 +363,8 @@ opt_calc_index_goodness(
col_no = dict_index_get_nth_col_no(index, j);
exp = opt_look_for_col_in_cond_before(
OPT_EQUAL, col_no, sel_node->search_cond,
OPT_EQUAL, col_no,
static_cast<func_node_t*>(sel_node->search_cond),
sel_node, nth_table, &op);
if (exp) {
/* The value for this column is exactly known already
@ -359,7 +377,9 @@ opt_calc_index_goodness(
/* Look for non-equality comparisons */
exp = opt_look_for_col_in_cond_before(
OPT_COMPARISON, col_no, sel_node->search_cond,
OPT_COMPARISON, col_no,
static_cast<func_node_t*>(
sel_node->search_cond),
sel_node, nth_table, &op);
if (exp) {
index_plan[j] = exp;
@ -413,7 +433,12 @@ opt_op_to_search_mode(
ascending order */
ulint op) /*!< in: operator '=', PARS_GE_TOKEN, ... */
{
if (op == '=') {
if (op == '='
|| op == PARS_LIKE_TOKEN_EXACT
|| op == PARS_LIKE_TOKEN_PREFIX
|| op == PARS_LIKE_TOKEN_SUFFIX
|| op == PARS_LIKE_TOKEN_SUBSTR) {
if (asc) {
return(PAGE_CUR_GE);
} else {
@ -583,12 +608,18 @@ opt_search_plan_for_table(
n_fields);
dict_index_copy_types(plan->tuple, plan->index, n_fields);
plan->tuple_exps = mem_heap_alloc(pars_sym_tab_global->heap,
n_fields * sizeof(void*));
plan->tuple_exps = static_cast<que_node_t**>(
mem_heap_alloc(
pars_sym_tab_global->heap,
n_fields * sizeof(void*)));
ut_memcpy(plan->tuple_exps, best_index_plan,
n_fields * sizeof(void*));
if (best_last_op == '=') {
if (best_last_op == '='
|| best_last_op == PARS_LIKE_TOKEN_EXACT
|| best_last_op == PARS_LIKE_TOKEN_PREFIX
|| best_last_op == PARS_LIKE_TOKEN_SUFFIX
|| best_last_op == PARS_LIKE_TOKEN_SUBSTR) {
plan->n_exact_match = n_fields;
} else {
plan->n_exact_match = n_fields - 1;
@ -717,7 +748,7 @@ opt_find_test_conds(
conditions or NULL */
{
func_node_t* new_cond;
ulint class;
ulint fclass;
plan_t* plan;
if (cond == NULL) {
@ -726,11 +757,12 @@ opt_find_test_conds(
}
if (cond->func == PARS_AND_TOKEN) {
new_cond = cond->args;
new_cond = static_cast<func_node_t*>(cond->args);
opt_find_test_conds(sel_node, i, new_cond);
new_cond = que_node_get_next(new_cond);
new_cond = static_cast<func_node_t*>(
que_node_get_next(new_cond));
opt_find_test_conds(sel_node, i, new_cond);
@ -739,12 +771,12 @@ opt_find_test_conds(
plan = sel_node_get_nth_plan(sel_node, i);
class = opt_classify_comparison(sel_node, i, cond);
fclass = opt_classify_comparison(sel_node, i, cond);
if (class == OPT_END_COND) {
if (fclass == OPT_END_COND) {
UT_LIST_ADD_LAST(cond_list, plan->end_conds, cond);
} else if (class == OPT_TEST_COND) {
} else if (fclass == OPT_TEST_COND) {
UT_LIST_ADD_LAST(cond_list, plan->other_conds, cond);
}
@ -772,7 +804,7 @@ opt_normalize_cmp_conds(
if (que_node_get_type(arg2) == QUE_NODE_SYMBOL) {
sym_node = arg2;
sym_node = static_cast<sym_node_t*>(arg2);
if ((sym_node->token_type == SYM_COLUMN)
&& (sym_node->table == table)) {
@ -812,7 +844,10 @@ opt_determine_and_normalize_test_conds(
/* Recursively go through the conjuncts and classify them */
opt_find_test_conds(sel_node, i, sel_node->search_cond);
opt_find_test_conds(
sel_node,
i,
static_cast<func_node_t*>(sel_node->search_cond));
opt_normalize_cmp_conds(UT_LIST_GET_FIRST(plan->end_conds),
plan->table);
@ -852,14 +887,14 @@ opt_find_all_cols(
}
if (que_node_get_type(exp) == QUE_NODE_FUNC) {
func_node = exp;
func_node = static_cast<func_node_t*>(exp);
arg = func_node->args;
for (arg = func_node->args;
arg != 0;
arg = que_node_get_next(arg)) {
while (arg) {
opt_find_all_cols(copy_val, index, col_list, plan,
arg);
arg = que_node_get_next(arg);
opt_find_all_cols(
copy_val, index, col_list, plan, arg);
}
return;
@ -867,7 +902,7 @@ opt_find_all_cols(
ut_a(que_node_get_type(exp) == QUE_NODE_SYMBOL);
sym_node = exp;
sym_node = static_cast<sym_node_t*>(exp);
if (sym_node->token_type != SYM_COLUMN) {
@ -953,11 +988,12 @@ opt_find_copy_cols(
ut_ad(que_node_get_type(search_cond) == QUE_NODE_FUNC);
if (search_cond->func == PARS_AND_TOKEN) {
new_cond = search_cond->args;
new_cond = static_cast<func_node_t*>(search_cond->args);
opt_find_copy_cols(sel_node, i, new_cond);
new_cond = que_node_get_next(new_cond);
new_cond = static_cast<func_node_t*>(
que_node_get_next(new_cond));
opt_find_copy_cols(sel_node, i, new_cond);
@ -1004,21 +1040,23 @@ opt_classify_cols(
/* All select list columns should be copied: therefore TRUE as the
first argument */
exp = sel_node->select_list;
for (exp = sel_node->select_list;
exp != 0;
exp = que_node_get_next(exp)) {
while (exp) {
opt_find_all_cols(TRUE, plan->index, &(plan->columns), plan,
exp);
exp = que_node_get_next(exp);
opt_find_all_cols(
TRUE, plan->index, &(plan->columns), plan, exp);
}
opt_find_copy_cols(sel_node, i, sel_node->search_cond);
opt_find_copy_cols(
sel_node, i, static_cast<func_node_t*>(sel_node->search_cond));
/* All remaining columns in the search condition are temporary
columns: therefore FALSE */
opt_find_all_cols(FALSE, plan->index, &(plan->columns), plan,
sel_node->search_cond);
opt_find_all_cols(
FALSE, plan->index, &plan->columns, plan,
static_cast<func_node_t*>(sel_node->search_cond));
}
/*******************************************************************//**
@ -1068,7 +1106,8 @@ opt_clust_access(
dict_index_copy_types(plan->clust_ref, clust_index, n_fields);
plan->clust_map = mem_heap_alloc(heap, n_fields * sizeof(ulint));
plan->clust_map = static_cast<ulint*>(
mem_heap_alloc(heap, n_fields * sizeof(ulint)));
for (i = 0; i < n_fields; i++) {
pos = dict_index_get_nth_field_pos(index, clust_index, i);
@ -1082,7 +1121,7 @@ opt_clust_access(
|| dict_index_get_nth_field(clust_index, i)
->prefix_len != 0) {
fprintf(stderr,
"InnoDB: Error in pars0opt.c:"
"InnoDB: Error in pars0opt.cc:"
" table %s has prefix_len != 0\n",
index->table_name);
}
@ -1108,8 +1147,10 @@ opt_search_plan(
order_node_t* order_by;
ulint i;
sel_node->plans = mem_heap_alloc(pars_sym_tab_global->heap,
sel_node->n_tables * sizeof(plan_t));
sel_node->plans = static_cast<plan_t*>(
mem_heap_alloc(
pars_sym_tab_global->heap,
sel_node->n_tables * sizeof(plan_t)));
/* Analyze the search condition to find out what we know at each
join stage about the conditions that the columns of a table should
@ -1138,7 +1179,8 @@ opt_search_plan(
opt_determine_and_normalize_test_conds(sel_node, i);
table_node = que_node_get_next(table_node);
table_node = static_cast<sym_node_t*>(
que_node_get_next(table_node));
}
table_node = sel_node->table_list;
@ -1155,7 +1197,8 @@ opt_search_plan(
opt_clust_access(sel_node, i);
table_node = que_node_get_next(table_node);
table_node = static_cast<sym_node_t*>(
que_node_get_next(table_node));
}
/* Check that the plan obeys a possible order-by clause: if not,

View file

@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
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
@ -11,13 +11,13 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
*****************************************************************************/
/**************************************************//**
@file pars/pars0sym.c
@file pars/pars0sym.cc
SQL parser symbol table
Created 12/15/1997 Heikki Tuuri
@ -49,7 +49,8 @@ sym_tab_create(
{
sym_tab_t* sym_tab;
sym_tab = mem_heap_alloc(heap, sizeof(sym_tab_t));
sym_tab = static_cast<sym_tab_t*>(
mem_heap_alloc(heap, sizeof(sym_tab_t)));
UT_LIST_INIT(sym_tab->sym_list);
UT_LIST_INIT(sym_tab->func_node_list);
@ -59,6 +60,7 @@ sym_tab_create(
return(sym_tab);
}
/******************************************************************//**
Frees the memory allocated dynamically AFTER parsing phase for variables
etc. in the symbol table. Does not free the mem heap where the table was
@ -72,9 +74,23 @@ sym_tab_free_private(
sym_node_t* sym;
func_node_t* func;
sym = UT_LIST_GET_FIRST(sym_tab->sym_list);
ut_ad(mutex_own(&dict_sys->mutex));
for (sym = UT_LIST_GET_FIRST(sym_tab->sym_list);
sym != NULL;
sym = UT_LIST_GET_NEXT(sym_list, sym)) {
/* Close the tables opened in pars_retrieve_table_def(). */
if (sym->token_type == SYM_TABLE_REF_COUNTED) {
dict_table_close(sym->table, TRUE);
sym->table = NULL;
sym->resolved = FALSE;
sym->token_type = SYM_UNSET;
}
while (sym) {
eval_node_free_val_buf(sym);
if (sym->prefetch_buf) {
@ -84,16 +100,13 @@ sym_tab_free_private(
if (sym->cursor_def) {
que_graph_free_recursive(sym->cursor_def);
}
sym = UT_LIST_GET_NEXT(sym_list, sym);
}
func = UT_LIST_GET_FIRST(sym_tab->func_node_list);
for (func = UT_LIST_GET_FIRST(sym_tab->func_node_list);
func != NULL;
func = UT_LIST_GET_NEXT(func_node_list, func)) {
while (func) {
eval_node_free_val_buf(func);
func = UT_LIST_GET_NEXT(func_node_list, func);
}
}
@ -110,10 +123,12 @@ sym_tab_add_int_lit(
sym_node_t* node;
byte* data;
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node = static_cast<sym_node_t*>(
mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
node->common.type = QUE_NODE_SYMBOL;
node->table = NULL;
node->resolved = TRUE;
node->token_type = SYM_LIT;
@ -121,7 +136,7 @@ sym_tab_add_int_lit(
dtype_set(dfield_get_type(&node->common.val), DATA_INT, 0, 4);
data = mem_heap_alloc(sym_tab->heap, 4);
data = static_cast<byte*>(mem_heap_alloc(sym_tab->heap, 4));
mach_write_to_4(data, val);
dfield_set_data(&(node->common.val), data, 4);
@ -132,6 +147,8 @@ sym_tab_add_int_lit(
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
node->like_node = NULL;
node->sym_table = sym_tab;
return(node);
@ -145,17 +162,19 @@ sym_node_t*
sym_tab_add_str_lit(
/*================*/
sym_tab_t* sym_tab, /*!< in: symbol table */
byte* str, /*!< in: string with no quotes around
const byte* str, /*!< in: string with no quotes around
it */
ulint len) /*!< in: string length */
{
sym_node_t* node;
byte* data;
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node = static_cast<sym_node_t*>(
mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
node->common.type = QUE_NODE_SYMBOL;
node->table = NULL;
node->resolved = TRUE;
node->token_type = SYM_LIT;
@ -164,12 +183,8 @@ sym_tab_add_str_lit(
dtype_set(dfield_get_type(&node->common.val),
DATA_VARCHAR, DATA_ENGLISH, 0);
if (len) {
data = mem_heap_alloc(sym_tab->heap, len);
ut_memcpy(data, str, len);
} else {
data = NULL;
}
data = (len) ? static_cast<byte*>(mem_heap_dup(sym_tab->heap, str, len))
: NULL;
dfield_set_data(&(node->common.val), data, len);
@ -179,6 +194,8 @@ sym_tab_add_str_lit(
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
node->like_node = NULL;
node->sym_table = sym_tab;
return(node);
@ -202,10 +219,13 @@ sym_tab_add_bound_lit(
blit = pars_info_get_bound_lit(sym_tab->info, name);
ut_a(blit);
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node = static_cast<sym_node_t*>(
mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
node->common.type = QUE_NODE_SYMBOL;
node->common.brother = node->common.parent = NULL;
node->table = NULL;
node->resolved = TRUE;
node->token_type = SYM_LIT;
@ -255,11 +275,57 @@ sym_tab_add_bound_lit(
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
blit->node = node;
node->like_node = NULL;
node->sym_table = sym_tab;
return(node);
}
/**********************************************************************
Rebind literal to a node in the symbol table. */
sym_node_t*
sym_tab_rebind_lit(
/*===============*/
/* out: symbol table node */
sym_node_t* node, /* in: node that is bound to literal*/
const void* address, /* in: pointer to data */
ulint length) /* in: length of data */
{
dfield_t* dfield = que_node_get_val(node);
dtype_t* dtype = dfield_get_type(dfield);
ut_a(node->token_type == SYM_LIT);
dfield_set_data(&node->common.val, address, length);
if (node->like_node) {
ut_a(dtype_get_mtype(dtype) == DATA_CHAR
|| dtype_get_mtype(dtype) == DATA_VARCHAR);
/* Don't force [FALSE] creation of sub-nodes (for LIKE) */
pars_like_rebind(
node,static_cast<const byte*>(address), length);
}
/* FIXME: What's this ? */
node->common.val_buf_size = 0;
if (node->prefetch_buf) {
sel_col_prefetch_buf_free(node->prefetch_buf);
node->prefetch_buf = NULL;
}
if (node->cursor_def) {
que_graph_free_recursive(node->cursor_def);
node->cursor_def = NULL;
}
return(node);
}
/******************************************************************//**
Adds an SQL null literal to a symbol table.
@return symbol table node */
@ -271,10 +337,12 @@ sym_tab_add_null_lit(
{
sym_node_t* node;
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node = static_cast<sym_node_t*>(
mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
node->common.type = QUE_NODE_SYMBOL;
node->table = NULL;
node->resolved = TRUE;
node->token_type = SYM_LIT;
@ -290,6 +358,8 @@ sym_tab_add_null_lit(
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
node->like_node = NULL;
node->sym_table = sym_tab;
return(node);
@ -308,13 +378,11 @@ sym_tab_add_id(
{
sym_node_t* node;
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node = static_cast<sym_node_t*>(
mem_heap_zalloc(sym_tab->heap, sizeof(*node)));
node->common.type = QUE_NODE_SYMBOL;
node->resolved = FALSE;
node->indirection = NULL;
node->name = mem_heap_strdupl(sym_tab->heap, (char*) name, len);
node->name_len = len;
@ -322,10 +390,6 @@ sym_tab_add_id(
dfield_set_null(&node->common.val);
node->common.val_buf_size = 0;
node->prefetch_buf = NULL;
node->cursor_def = NULL;
node->sym_table = sym_tab;
return(node);
@ -337,7 +401,7 @@ Add a bound identifier to a symbol table.
UNIV_INTERN
sym_node_t*
sym_tab_add_bound_id(
/*===========*/
/*=================*/
sym_tab_t* sym_tab, /*!< in: symbol table */
const char* name) /*!< in: name of bound id */
{
@ -347,11 +411,14 @@ sym_tab_add_bound_id(
bid = pars_info_get_bound_id(sym_tab->info, name);
ut_a(bid);
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node = static_cast<sym_node_t*>(
mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
node->common.type = QUE_NODE_SYMBOL;
node->table = NULL;
node->resolved = FALSE;
node->token_type = SYM_UNSET;
node->indirection = NULL;
node->name = mem_heap_strdup(sym_tab->heap, bid->id);
@ -365,6 +432,8 @@ sym_tab_add_bound_id(
node->prefetch_buf = NULL;
node->cursor_def = NULL;
node->like_node = NULL;
node->sym_table = sym_tab;
return(node);