• kostja@bodhi.local's avatar
    A fix and test cases for · 90072e69
    kostja@bodhi.local authored
    Bug#4968 "Stored procedure crash if cursor opened on altered table"
    Bug#19733 "Repeated alter, or repeated create/drop, fails"
    Bug#19182 "CREATE TABLE bar (m INT) SELECT n FROM foo; doesn't work from 
    stored procedure."
    Bug#6895 "Prepared Statements: ALTER TABLE DROP COLUMN does nothing"
    Bug#22060 "ALTER TABLE x AUTO_INCREMENT=y in SP crashes server"
    
    Test cases for bugs 4968, 19733, 6895 will be added in 5.0.
    
    Re-execution of CREATE DATABASE, CREATE TABLE and ALTER TABLE 
    statements in stored routines or as prepared statements caused
    incorrect results (and crashes in versions prior to 5.0.25).
    In 5.1 the problem occured only for CREATE DATABASE, CREATE TABLE
    SELECT and CREATE TABLE with INDEX/DATA DIRECTOY options).
    
    The problem of bugs 4968, 19733, 19282 and 6895 was that functions
    mysql_prepare_table, mysql_create_table and mysql_alter_table were not
    re-execution friendly: during their operation they used to modify contents
    of LEX (members create_info, alter_info, key_list, create_list),
    thus making the LEX unusable for the next execution.
    In particular, these functions removed processed columns and keys from
    create_list, key_list and drop_list. Search the code in sql_table.cc 
    for drop_it.remove() and similar patterns to find evidence.
    
    The fix is to supply to these functions a usable copy of each of the
    above structures at every re-execution of an SQL statement. 
    
    To simplify memory management, LEX::key_list and LEX::create_list
    were added to LEX::alter_info, a fresh copy of which is created for
    every execution.
    
    The problem of crashing bug 22060 stemmed from the fact that the above 
    metnioned functions were not only modifying HA_CREATE_INFO structure in 
    LEX, but also were changing it to point to areas in volatile memory of 
    the execution memory root.
     
    The patch solves this problem by creating and using an on-stack
    copy of HA_CREATE_INFO (note that code in 5.1 already creates and
    uses a copy of this structure in mysql_create_table()/alter_table(),
    but this approach didn't work well for CREATE TABLE SELECT statement).
    90072e69
sql_lex.h 25 KB