• unknown's avatar
    5.1 version of a fix and test cases for bugs: · e1e991b1
    unknown authored
    Bug#4968 ""Stored procedure crash if cursor opened on altered table"
    Bug#6895 "Prepared Statements: ALTER TABLE DROP COLUMN does nothing"
    Bug#19182 "CREATE TABLE bar (m INT) SELECT n FROM foo; doesn't work from 
    stored procedure."
    Bug#19733 "Repeated alter, or repeated create/drop, fails"
    Bug#22060 "ALTER TABLE x AUTO_INCREMENT=y in SP crashes server"
    Bug#24879 "Prepared Statements: CREATE TABLE (UTF8 KEY) produces a 
    growing key length" (this bug is not fixed 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 are not
    re-execution friendly: during their operation they 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 in mysql_execute_command.
    
    Additionally, this patch splits the part of mysql_alter_table
    that analizes and rewrites information from the parser into
    a separate function - mysql_prepare_alter_table, in analogy with
    mysql_prepare_table, which is renamed to mysql_prepare_create_table.
    
    
    mysql-test/r/ps.result:
      Update test results (Bug#19182, Bug#22060, Bug#4968, Bug#6895)
    mysql-test/r/sp.result:
      Update results (Bug#19733)
    mysql-test/t/ps.test:
      Add test cases for Bug#19182, Bug#22060, Bug#4968, Bug#6895
    mysql-test/t/sp.test:
      Add a test case for Bug#19733
    sql/field.h:
      Implement a deep copy constructor for create_field
    sql/mysql_priv.h:
      LEX::key_list and LEX::create_list were moved to LEX::alter_info.
      Update declarations to use LEX::alter_info instead of these two
      members.
      Remove declarations of mysql_add_index, mysql_drop_index.
    sql/sql_class.cc:
      Implement deep copy constructors.
    sql/sql_class.h:
      Implement (almost) deep copy constructors for key_part_spec, 
      Alter_drop, Alter_column, Key, foreign_key.
      Replace pair<columns, keys> with an instance of Alter_info in
      select_create constructor. We create a new copy of Alter_info
      each time we re-execute SELECT .. CREATE prepared statement.
    sql/sql_insert.cc:
      Adjust to a new signature of create_table_from_items.
    sql/sql_lex.cc:
      Implement Alter_info::Alter_info that would make a "deep" copy
      of all definition lists (keys, columns).
      Move is_partition_management() from sql_partition.cc (feature-based
      file division is evil).
    sql/sql_lex.h:
      Move key_list and create_list to class Alter_info. Implement
      Alter_info::Alter_info that can be used with PS and SP.
      Get rid of Alter_info::clear() which was an attempt to save on
      matches and always use Alter_info::reset().
      Implement an auxiliary Alter_info::init_for_create_from_alter()
      which is used in mysql_alter_table.
    sql/sql_list.cc:
        Implement a copy constructor of class List that makes a deep copy
        of all list nodes.
    sql/sql_list.h:
      Implement a way to make a deep copy of all list nodes.
    sql/sql_parse.cc:
      Adjust to new signatures of mysql_create_table, mysql_alter_table,
      select_create. Functions mysql_create_index and mysql_drop_index has
      become identical after initialization of alter_info was moved to the 
      parser, and were merged. Flag enable_slow_log was not updated for 
      SQLCOM_DROP_INDEX, which was a bug.
      Just like CREATE INDEX, DROP INDEX is currently done via complete 
      table rebuild and is rightfully a slow administrative statement.
    sql/sql_partition.cc:
      Move is_partition_management() to sql_lex.cc
      Adjust code to the new Alter_info.
    sql/sql_table.cc:
      Adjust mysql_alter_table, mysql_recreate_table, mysql_create_table,
      mysql_prepare_table to new signatures.
      Rename mysql_prepare_table to mysql_prepare_create_table. Make
      sure it follows the convention and returns FALSE for success and
      TRUE for error.
      Move parts of mysql_alter_table to mysql_prepare_alter_table.
      Move the first invokation of mysql_prepare_table from mysql_alter_table
      to compare_tables, as it was needed only for the purpose
      of correct comparison.
      Since now Alter_info itself is created in the runtime mem root,
      adjust mysql_prepare_table to always allocate memory in the
      runtime memory root.
      Remove dead code.
    sql/sql_yacc.yy:
      LEX::key_list and LEX::create_list moved to class Alter_info
    e1e991b1
sql_yacc.yy 315 KB