Commit ee06414b authored by Georgi Kodinov's avatar Georgi Kodinov

Bug #49250 : spatial btree index corruption and crash

SPATIAL and FULLTEXT indexes don't support algorithm
selection. 
Disabled by creating a special grammar rule for these
in the parser.
Added some encasulation of duplicate parser code.
parent 3c434c93
......@@ -518,3 +518,17 @@ EXECUTE s;
MATCH (col) AGAINST('findme')
DEALLOCATE PREPARE s;
DROP TABLE t1;
#
# Bug #49250 : spatial btree index corruption and crash
# Part two : fulltext syntax check
#
CREATE TABLE t1(col1 TEXT,
FULLTEXT INDEX USING BTREE (col1));
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE (col1))' at line 2
CREATE TABLE t2(col1 TEXT);
CREATE FULLTEXT INDEX USING BTREE ON t2(col);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE ON t2(col)' at line 1
ALTER TABLE t2 ADD FULLTEXT INDEX USING BTREE (col1);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE (col1)' at line 1
DROP TABLE t2;
End of 5.0 tests
......@@ -983,4 +983,17 @@ GEOMFROMTEXT(
SELECT 1 FROM t1 WHERE a <> (SELECT GEOMETRYCOLLECTIONFROMWKB(b) FROM t1);
1
DROP TABLE t1;
#
# Bug #49250 : spatial btree index corruption and crash
# Part one : spatial syntax check
#
CREATE TABLE t1(col1 MULTIPOLYGON NOT NULL,
SPATIAL INDEX USING BTREE (col1));
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE (col1))' at line 2
CREATE TABLE t2(col1 MULTIPOLYGON NOT NULL);
CREATE SPATIAL INDEX USING BTREE ON t2(col);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE ON t2(col)' at line 1
ALTER TABLE t2 ADD SPATIAL INDEX USING BTREE (col1);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE (col1)' at line 1
DROP TABLE t2;
End of 5.0 tests
......@@ -455,3 +455,20 @@ EXECUTE s;
DEALLOCATE PREPARE s;
DROP TABLE t1;
--echo #
--echo # Bug #49250 : spatial btree index corruption and crash
--echo # Part two : fulltext syntax check
--echo #
--error ER_PARSE_ERROR
CREATE TABLE t1(col1 TEXT,
FULLTEXT INDEX USING BTREE (col1));
CREATE TABLE t2(col1 TEXT);
--error ER_PARSE_ERROR
CREATE FULLTEXT INDEX USING BTREE ON t2(col);
--error ER_PARSE_ERROR
ALTER TABLE t2 ADD FULLTEXT INDEX USING BTREE (col1);
DROP TABLE t2;
--echo End of 5.0 tests
......@@ -669,5 +669,20 @@ SELECT 1 FROM t1 WHERE a <> (SELECT GEOMETRYCOLLECTIONFROMWKB(b) FROM t1);
DROP TABLE t1;
--echo #
--echo # Bug #49250 : spatial btree index corruption and crash
--echo # Part one : spatial syntax check
--echo #
--error ER_PARSE_ERROR
CREATE TABLE t1(col1 MULTIPOLYGON NOT NULL,
SPATIAL INDEX USING BTREE (col1));
CREATE TABLE t2(col1 MULTIPOLYGON NOT NULL);
--error ER_PARSE_ERROR
CREATE SPATIAL INDEX USING BTREE ON t2(col);
--error ER_PARSE_ERROR
ALTER TABLE t2 ADD SPATIAL INDEX USING BTREE (col1);
DROP TABLE t2;
--echo End of 5.0 tests
......@@ -418,6 +418,34 @@ Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
DBUG_RETURN(result);
}
static bool add_create_index_prepare (LEX *lex, Table_ident *table)
{
lex->sql_command= SQLCOM_CREATE_INDEX;
if (!lex->current_select->add_table_to_list(lex->thd, table, NULL,
TL_OPTION_UPDATING))
return TRUE;
lex->alter_info.reset();
lex->alter_info.flags= ALTER_ADD_INDEX;
lex->col_list.empty();
lex->change= NullS;
return FALSE;
}
static bool add_create_index (LEX *lex,
Key::Keytype type, const char *name, enum ha_key_alg key_alg,
bool generated= 0)
{
Key *key= new Key(type, name, key_alg, generated, lex->col_list);
if (key == NULL)
return TRUE;
lex->alter_info.key_list.push_back(key);
lex->col_list.empty();
return FALSE;
}
%}
%union {
int num;
......@@ -1110,7 +1138,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
option_type opt_var_type opt_var_ident_type
%type <key_type>
key_type opt_unique_or_fulltext constraint_key_type
key_type opt_unique fulltext_or_spatial constraint_key_type
key_type_fulltext_or_spatial
%type <key_alg>
key_alg opt_btree_or_rtree
......@@ -1543,27 +1572,25 @@ create:
}
create2
{ Lex->current_select= &Lex->select_lex; }
| CREATE opt_unique_or_fulltext INDEX_SYM ident key_alg ON table_ident
| CREATE opt_unique INDEX_SYM ident key_alg ON table_ident
{
LEX *lex=Lex;
lex->sql_command= SQLCOM_CREATE_INDEX;
if (!lex->current_select->add_table_to_list(lex->thd, $7, NULL,
TL_OPTION_UPDATING))
MYSQL_YYABORT;
lex->alter_info.reset();
lex->alter_info.flags= ALTER_ADD_INDEX;
lex->col_list.empty();
lex->change=NullS;
if (add_create_index_prepare (Lex, $7))
MYSQL_YYABORT;
}
'(' key_list ')'
'(' key_list ')'
{
LEX *lex=Lex;
Key *key= new Key($2, $4.str, $5, 0, lex->col_list);
if (key == NULL)
if (add_create_index (Lex, $2, $4.str, $5))
MYSQL_YYABORT;
}
| CREATE fulltext_or_spatial INDEX_SYM ident ON table_ident
{
if (add_create_index_prepare (Lex, $6))
MYSQL_YYABORT;
}
'(' key_list ')'
{
if (add_create_index (Lex, $2, $4.str, HA_KEY_ALG_UNDEF))
MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
lex->col_list.empty();
}
| CREATE DATABASE opt_if_not_exists ident
{
......@@ -3133,23 +3160,18 @@ column_def:
key_def:
key_type opt_ident key_alg '(' key_list ')' key_alg
{
LEX *lex=Lex;
Key *key= new Key($1, $2, $7 ? $7 : $3, 0, lex->col_list);
if (key == NULL)
if (add_create_index (Lex, $1, $2, $7 ? $7 : $3))
MYSQL_YYABORT;
}
| key_type_fulltext_or_spatial opt_ident '(' key_list ')'
{
if (add_create_index (Lex, $1, $2, HA_KEY_ALG_UNDEF))
MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
lex->col_list.empty(); /* Alloced by sql_alloc */
}
| opt_constraint constraint_key_type opt_ident key_alg '(' key_list ')' key_alg
{
LEX *lex=Lex;
const char *key_name= $3 ? $3:$1;
Key *key= new Key($2, key_name, $4, 0, lex->col_list);
if (key == NULL)
if (add_create_index (Lex, $2, $3 ? $3:$1, $4))
MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
lex->col_list.empty(); /* Alloced by sql_alloc */
}
| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
{
......@@ -3164,13 +3186,9 @@ key_def:
if (key == NULL)
MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
key= new Key(Key::MULTIPLE, key_name,
HA_KEY_ALG_UNDEF, 1,
lex->col_list);
if (key == NULL)
if (add_create_index (lex, Key::MULTIPLE, key_name,
HA_KEY_ALG_UNDEF, 1))
MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
lex->col_list.empty(); /* Alloced by sql_alloc */
}
| constraint opt_check_constraint
{
......@@ -3630,7 +3648,10 @@ delete_option:
key_type:
key_or_index { $$= Key::MULTIPLE; }
| FULLTEXT_SYM opt_key_or_index { $$= Key::FULLTEXT; }
;
key_type_fulltext_or_spatial:
FULLTEXT_SYM opt_key_or_index { $$= Key::FULLTEXT; }
| SPATIAL_SYM opt_key_or_index
{
#ifdef HAVE_SPATIAL
......@@ -3660,10 +3681,8 @@ keys_or_index:
| INDEX_SYM {}
| INDEXES {};
opt_unique_or_fulltext:
/* empty */ { $$= Key::MULTIPLE; }
| UNIQUE_SYM { $$= Key::UNIQUE; }
| FULLTEXT_SYM { $$= Key::FULLTEXT;}
fulltext_or_spatial:
FULLTEXT_SYM { $$= Key::FULLTEXT;}
| SPATIAL_SYM
{
#ifdef HAVE_SPATIAL
......@@ -3676,6 +3695,11 @@ opt_unique_or_fulltext:
}
;
opt_unique:
/* empty */ { $$= Key::MULTIPLE; }
| UNIQUE_SYM { $$= Key::UNIQUE; }
;
key_alg:
/* empty */ { $$= HA_KEY_ALG_UNDEF; }
| USING opt_btree_or_rtree { $$= $2; }
......
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