mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixed that sequences and default works with ps-protocol
The bug was that for prepared statments the new TABLE_LIST was allocated in the wrong arena.
This commit is contained in:
@ -152,6 +152,22 @@ UNLOCK TABLES;
|
|||||||
drop table t1;
|
drop table t1;
|
||||||
drop sequence s1;
|
drop sequence s1;
|
||||||
#
|
#
|
||||||
|
# Testing prepared statements
|
||||||
|
#
|
||||||
|
CREATE or replace SEQUENCE s1 nocache engine=myisam;
|
||||||
|
CREATE or replace table t1 (a int default next value for s1, b int);
|
||||||
|
PREPARE stmt FROM "insert into t1 (b) values(?)";
|
||||||
|
execute stmt using 1;
|
||||||
|
execute stmt using 2;
|
||||||
|
execute stmt using 3;
|
||||||
|
select * from t1;
|
||||||
|
a b
|
||||||
|
1 1
|
||||||
|
2 2
|
||||||
|
3 3
|
||||||
|
drop table t1,s1;
|
||||||
|
deallocate prepare stmt;
|
||||||
|
#
|
||||||
# Wrong usage of default
|
# Wrong usage of default
|
||||||
#
|
#
|
||||||
CREATE table t1 (a int default next value for s1, b int);
|
CREATE table t1 (a int default next value for s1, b int);
|
||||||
|
@ -90,6 +90,20 @@ UNLOCK TABLES;
|
|||||||
drop table t1;
|
drop table t1;
|
||||||
drop sequence s1;
|
drop sequence s1;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # Testing prepared statements
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
CREATE or replace SEQUENCE s1 nocache engine=myisam;
|
||||||
|
CREATE or replace table t1 (a int default next value for s1, b int);
|
||||||
|
PREPARE stmt FROM "insert into t1 (b) values(?)";
|
||||||
|
execute stmt using 1;
|
||||||
|
execute stmt using 2;
|
||||||
|
execute stmt using 3;
|
||||||
|
select * from t1;
|
||||||
|
drop table t1,s1;
|
||||||
|
deallocate prepare stmt;
|
||||||
|
|
||||||
--echo #
|
--echo #
|
||||||
--echo # Wrong usage of default
|
--echo # Wrong usage of default
|
||||||
--echo #
|
--echo #
|
||||||
|
@ -4243,12 +4243,33 @@ static bool table_already_fk_prelocked(TABLE_LIST *tl, LEX_CSTRING *db,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static bool internal_table_exists(TABLE_LIST *global_list,
|
||||||
add_internal_tables(THD *thd, Query_tables_list *prelocking_ctx,
|
const char *table_name)
|
||||||
TABLE_LIST *global_table_list, TABLE_LIST *tables)
|
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
if (global_list->table_name == table_name)
|
||||||
|
return 1;
|
||||||
|
} while ((global_list= global_list->next_global));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool
|
||||||
|
add_internal_tables(THD *thd, Query_tables_list *prelocking_ctx,
|
||||||
|
TABLE_LIST *tables)
|
||||||
|
{
|
||||||
|
TABLE_LIST *global_table_list= prelocking_ctx->query_tables;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Skip table if already in the list. Can happen with prepared statements
|
||||||
|
*/
|
||||||
|
if (tables->next_local &&
|
||||||
|
internal_table_exists(global_table_list, tables->table_name))
|
||||||
|
continue;
|
||||||
|
|
||||||
TABLE_LIST *tl= (TABLE_LIST *) thd->alloc(sizeof(TABLE_LIST));
|
TABLE_LIST *tl= (TABLE_LIST *) thd->alloc(sizeof(TABLE_LIST));
|
||||||
if (!tl)
|
if (!tl)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -4368,12 +4389,20 @@ handle_table(THD *thd, Query_tables_list *prelocking_ctx,
|
|||||||
/* Open any tables used by DEFAULT (like sequence tables) */
|
/* Open any tables used by DEFAULT (like sequence tables) */
|
||||||
if (table->internal_tables &&
|
if (table->internal_tables &&
|
||||||
((sql_command_flags[thd->lex->sql_command] & CF_INSERTS_DATA) ||
|
((sql_command_flags[thd->lex->sql_command] & CF_INSERTS_DATA) ||
|
||||||
thd->lex->default_used) &&
|
thd->lex->default_used))
|
||||||
add_internal_tables(thd, prelocking_ctx, table_list,
|
|
||||||
table->internal_tables))
|
|
||||||
{
|
{
|
||||||
*need_prelocking= TRUE;
|
Query_arena *arena, backup;
|
||||||
return TRUE;
|
bool error;
|
||||||
|
arena= thd->activate_stmt_arena_if_needed(&backup);
|
||||||
|
error= add_internal_tables(thd, prelocking_ctx,
|
||||||
|
table->internal_tables);
|
||||||
|
if (arena)
|
||||||
|
thd->restore_active_arena(arena, &backup);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
*need_prelocking= TRUE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user