An error occurred fetching the project authors.
  1. 18 Nov, 2010 1 commit
    • Alexander Barkov's avatar
      Bug#57306 SHOW PROCESSLIST does not display string literals well. · 185e189d
      Alexander Barkov authored
      Problem: Extended characters outside of ASCII range where not displayed
      properly in SHOW PROCESSLIST, because thd_info->query was always sent as 
      system_character_set (utf8). This was wrong, because query buffer
      is never converted to utf8 - it is always have client character set.
      
      Fix: sending query buffer using query character set
      
        @ sql/sql_class.cc
        @ sql/sql_class.h
          Introducing a new class CSET_STRING, a LEX_STRING with character set.
          Adding set_query(&CSET_STRING)
          Adding reset_query(), to use instead of set_query(0, NULL).
      
        @ sql/event_data_objects.cc
          Using reset_query()
      
        @ sql/log_event.cc
          Using reset_query()
          Adding charset argument to set_query_and_id().
      
        @ sql/slave.cc
          Using reset_query().
      
        @ sql/sp_head.cc
          Changing backing up and restore code to use CSET_STRING.
      
        @ sql/sql_audit.h
          Using CSET_STRING.
          In the "else" branch it's OK not to use
          global_system_variables.character_set_client.
          &my_charset_latin1, which is set in constructor, is fine
          (verified with Sergey Vojtovich).
      
        @ sql/sql_insert.cc
          Using set_query() with proper character set: table_name is utf8.
      
        @ sql/sql_parse.cc
          Adding character set argument to set_query_and_id().
          (This is the main point where thd->charset() is stored
           into thd->query_string.cs, for use in "SHOW PROCESSLIST".)
          Using reset_query().
          
        @ sql/sql_prepare.cc
          Storing client character set into thd->query_string.cs.
      
        @ sql/sql_show.cc
          Using CSET_STRING to fetch and send charset-aware query information
          from threads.
      
        @ storage/myisam/ha_myisam.cc
          Using set_query() with proper character set: table_name is utf8.
      
        @ mysql-test/r/show_check.result
        @ mysql-test/t/show_check.test
          Adding tests
      185e189d
  2. 16 Nov, 2010 1 commit
    • Davi Arnaut's avatar
      Bug#57058: SERVER_QUERY_WAS_SLOW not wired up. · 247a696d
      Davi Arnaut authored
      Finalize the server flags after any kind of command is executed.
      To avoid updating the flag multiple times, reorganize code so that
      its invoked only once for each command.
      
      sql/log_event.cc:
        Explicit update after the query is executed in the slave.
      sql/sql_parse.cc:
        Reorganize so that the status flag is updated for any command and
        not done twice for a query command.
      247a696d
  3. 12 Nov, 2010 1 commit
    • Konstantin Osipov's avatar
      Implement a fix for Bug#57058 -- send SERVER_QUERY_WAS_SLOW over · 78fa2e4d
      Konstantin Osipov authored
      network when a query was slow.
      
      When a query is slow, sent a special flag to the client
      indicating this fact.
      
      Add a test case.
      Implement review comments.
      
      
      
      include/mysql_com.h:
        Clear SERVER_QUERY_WAS_SLOW at end of each statement.
        Since this patch removes the technique when 
        thd->server_status is modified briefly only to
        execute my_eof(), reset more server status
        bit that may remain in the status from
        execution of the previous statement.
      sql/protocol.cc:
        Always use thd->server_status to 
        in net_* functions to send the latest
        status to the client.
      sql/sp_head.cc:
        Calculate if a query was slow before
        sending EOF packet.
      sql/sql_cursor.cc:
        Remove juggling with thd->server_status.
        The extra status bits are reset at
        start of the next statement.
      sql/sql_db.cc:
        Remove juggling with thd->server_status.
        The extra status bits are reset at
        start of the next statement.
      sql/sql_error.cc:
        Remove m_server_status member,
        it's not really part of the Diagnostics_area.
      sql/sql_error.h:
        Remove server_status member, it's
        not part of the Diagnostics_area.
        The associated hack is removed as well.
      sql/sql_parse.cc:
        Do not calculate if a query was
        slow twice. Use a status flag in thd->server_status.
      tests/mysql_client_test.c:
        Add a test case for Bug#57058.
        Check that the status is present
        at the client, when sent.
      78fa2e4d
  4. 11 Nov, 2010 1 commit
    • Dmitry Lenev's avatar
      Patch that refactors global read lock implementation and fixes · 6bf6272f
      Dmitry Lenev authored
      bug #57006 "Deadlock between HANDLER and FLUSH TABLES WITH READ
      LOCK" and bug #54673 "It takes too long to get readlock for
      'FLUSH TABLES WITH READ LOCK'".
      
      The first bug manifested itself as a deadlock which occurred
      when a connection, which had some table open through HANDLER
      statement, tried to update some data through DML statement
      while another connection tried to execute FLUSH TABLES WITH
      READ LOCK concurrently.
      
      What happened was that FTWRL in the second connection managed
      to perform first step of GRL acquisition and thus blocked all
      upcoming DML. After that it started to wait for table open
      through HANDLER statement to be flushed. When the first connection
      tried to execute DML it has started to wait for GRL/the second
      connection creating deadlock.
      
      The second bug manifested itself as starvation of FLUSH TABLES
      WITH READ LOCK statements in cases when there was a constant
      stream of concurrent DML statements (in two or more
      connections).
      
      This has happened because requests for protection against GRL
      which were acquired by DML statements were ignoring presence of
      pending GRL and thus the latter was starved.
      
      This patch solves both these problems by re-implementing GRL
      using metadata locks.
      
      Similar to the old implementation acquisition of GRL in new
      implementation is two-step. During the first step we block
      all concurrent DML and DDL statements by acquiring global S
      metadata lock (each DML and DDL statement acquires global IX
      lock for its duration). During the second step we block commits
      by acquiring global S lock in COMMIT namespace (commit code
      acquires global IX lock in this namespace).
      
      Note that unlike in old implementation acquisition of
      protection against GRL in DML and DDL is semi-automatic.
      We assume that any statement which should be blocked by GRL
      will either open and acquires write-lock on tables or acquires
      metadata locks on objects it is going to modify. For any such
      statement global IX metadata lock is automatically acquired
      for its duration.
      
      The first problem is solved because waits for GRL become
      visible to deadlock detector in metadata locking subsystem
      and thus deadlocks like one in the first bug become impossible.
      
      The second problem is solved because global S locks which
      are used for GRL implementation are given preference over
      IX locks which are acquired by concurrent DML (and we can
      switch to fair scheduling in future if needed).
      
      Important change:
      FTWRL/GRL no longer blocks DML and DDL on temporary tables.
      Before this patch behavior was not consistent in this respect:
      in some cases DML/DDL statements on temporary tables were
      blocked while in others they were not. Since the main use cases
      for FTWRL are various forms of backups and temporary tables are
      not preserved during backups we have opted for consistently
      allowing DML/DDL on temporary tables during FTWRL/GRL.
      
      Important change:
      This patch changes thread state names which are used when
      DML/DDL of FTWRL is waiting for global read lock. It is now
      either "Waiting for global read lock" or "Waiting for commit
      lock" depending on the stage on which FTWRL is.
      
      Incompatible change:
      To solve deadlock in events code which was exposed by this
      patch we have to replace LOCK_event_metadata mutex with
      metadata locks on events. As result we have to prohibit
      DDL on events under LOCK TABLES.
      
      This patch also adds extensive test coverage for interaction
      of DML/DDL and FTWRL.
      
      Performance of new and old global read lock implementations
      in sysbench tests were compared. There were no significant
      difference between new and old implementations.
      
      mysql-test/include/check_ftwrl_compatible.inc:
        Added helper script which allows to check that a statement is
        compatible with FLUSH TABLES WITH READ LOCK.
      mysql-test/include/check_ftwrl_incompatible.inc:
        Added helper script which allows to check that a statement is
        incompatible with FLUSH TABLES WITH READ LOCK.
      mysql-test/include/handler.inc:
        Adjusted test case to the fact that now DROP TABLE closes
        open HANDLERs for the table to be dropped before checking
        if there active FTWRL in this connection.
      mysql-test/include/wait_show_condition.inc:
        Fixed small error in the timeout message. The correct name
        of variable used as parameter for this script is "$condition"
        and not "$wait_condition".
      mysql-test/r/delayed.result:
        Added test coverage for scenario which triggered assert in
        metadata locking subsystem.
      mysql-test/r/events_2.result:
        Updated test results after prohibiting event DDL operations
        under LOCK TABLES.
      mysql-test/r/flush.result:
        Added test coverage for bug #57006 "Deadlock between HANDLER
        and FLUSH TABLES WITH READ LOCK".
      mysql-test/r/flush_read_lock.result:
        Added test coverage for various aspects of FLUSH TABLES WITH
        READ LOCK functionality.
      mysql-test/r/flush_read_lock_kill.result:
        Adjusted test case after replacing custom global read lock
        implementation with one based on metadata locks. Use new
        debug_sync point. Do not disable concurrent inserts as now
        InnoDB we always use InnoDB table.
      mysql-test/r/handler_innodb.result:
        Adjusted test case to the fact that now DROP TABLE closes
        open HANDLERs for the table to be dropped before checking
        if there active FTWRL in this connection.
      mysql-test/r/handler_myisam.result:
        Adjusted test case to the fact that now DROP TABLE closes
        open HANDLERs for the table to be dropped before checking
        if there active FTWRL in this connection.
      mysql-test/r/mdl_sync.result:
        Adjusted test case after replacing custom global read lock
        implementation with one based on metadata locks. Replaced
        usage of GRL-specific debug_sync's with appropriate sync
        points in MDL subsystem.
      mysql-test/suite/perfschema/r/dml_setup_instruments.result:
        Updated test results after removing global
        COND_global_read_lock condition variable.
      mysql-test/suite/perfschema/r/func_file_io.result:
        Ensure that this test doesn't affect subsequent tests.
        At the end of its execution enable back P_S instrumentation
        which this test disables at some point.
      mysql-test/suite/perfschema/r/func_mutex.result:
        Ensure that this test doesn't affect subsequent tests.
        At the end of its execution enable back P_S instrumentation
        which this test disables at some point.
      mysql-test/suite/perfschema/r/global_read_lock.result:
        Adjusted test case to take into account that new GRL
        implementation is based on MDL.
      mysql-test/suite/perfschema/r/server_init.result:
        Adjusted test case after replacing custom global read
        lock implementation with one based on MDL and replacing
        LOCK_event_metadata mutex with metadata lock.
      mysql-test/suite/perfschema/t/func_file_io.test:
        Ensure that this test doesn't affect subsequent tests.
        At the end of its execution enable back P_S instrumentation
        which this test disables at some point.
      mysql-test/suite/perfschema/t/func_mutex.test:
        Ensure that this test doesn't affect subsequent tests.
        At the end of its execution enable back P_S instrumentation
        which this test disables at some point.
      mysql-test/suite/perfschema/t/global_read_lock.test:
        Adjusted test case to take into account that new GRL
        implementation is based on MDL.
      mysql-test/suite/perfschema/t/server_init.test:
        Adjusted test case after replacing custom global read
        lock implementation with one based on MDL and replacing
        LOCK_event_metadata mutex with metadata lock.
      mysql-test/suite/rpl/r/rpl_tmp_table_and_DDL.result:
        Updated test results after prohibiting event DDL under
        LOCK TABLES.
      mysql-test/t/delayed.test:
        Added test coverage for scenario which triggered assert in
        metadata locking subsystem.
      mysql-test/t/events_2.test:
        Updated test case after prohibiting event DDL operations
        under LOCK TABLES.
      mysql-test/t/flush.test:
        Added test coverage for bug #57006 "Deadlock between HANDLER
        and FLUSH TABLES WITH READ LOCK".
      mysql-test/t/flush_block_commit.test:
        Adjusted test case after changing thread state name which
        is used when COMMIT waits for FLUSH TABLES WITH READ LOCK
        from "Waiting for release of readlock" to "Waiting for commit
        lock".
      mysql-test/t/flush_block_commit_notembedded.test:
        Adjusted test case after changing thread state name which is
        used when DML waits for FLUSH TABLES WITH READ LOCK. Now we
        use "Waiting for global read lock" in this case.
      mysql-test/t/flush_read_lock.test:
        Added test coverage for various aspects of FLUSH TABLES WITH
        READ LOCK functionality.
      mysql-test/t/flush_read_lock_kill-master.opt:
        We no longer need to use make_global_read_lock_block_commit_loop
        debug tag in this test. Instead we rely on an appropriate
        debug_sync point in MDL code.
      mysql-test/t/flush_read_lock_kill.test:
        Adjusted test case after replacing custom global read lock
        implementation with one based on metadata locks. Use new
        debug_sync point. Do not disable concurrent inserts as now
        InnoDB we always use InnoDB table.
      mysql-test/t/lock_multi.test:
        Adjusted test case after changing thread state names which
        are used when DML or DDL waits for FLUSH TABLES WITH READ
        LOCK to "Waiting for global read lock".
      mysql-test/t/mdl_sync.test:
        Adjusted test case after replacing custom global read lock
        implementation with one based on metadata locks. Replaced
        usage of GRL-specific debug_sync's with appropriate sync
        points in MDL subsystem. Updated thread state names which
        are used when DDL waits for FTWRL.
      mysql-test/t/trigger_notembedded.test:
        Adjusted test case after changing thread state names which
        are used when DML or DDL waits for FLUSH TABLES WITH READ
        LOCK to "Waiting for global read lock".
      sql/event_data_objects.cc:
        Removed Event_queue_element::status/last_executed_changed
        members and Event_queue_element::update_timing_fields()
        method. We no longer use this class for updating mysql.events
        once event is chosen for execution. Accesses to instances of
        this class in scheduler thread require protection by
        Event_queue::LOCK_event_queue mutex and we try to avoid
        updating table while holding this lock.
      sql/event_data_objects.h:
        Removed Event_queue_element::status/last_executed_changed
        members and Event_queue_element::update_timing_fields()
        method. We no longer use this class for updating mysql.events
        once event is chosen for execution. Accesses to instances of
        this class in scheduler thread require protection by
        Event_queue::LOCK_event_queue mutex and we try to avoid
        updating table while holding this lock.
      sql/event_db_repository.cc:
        - Changed Event_db_repository methods to not release all
          metadata locks once they are done updating mysql.events
          table. This allows to keep metadata lock protecting
          against GRL and lock protecting particular event around
          until corresponding DDL statement is written to the binary
          log.
        - Removed logic for conditional update of "status" and
          "last_executed" fields from update_timing_fields_for_event()
          method. In the only case when this method is called now
          "last_executed" is always modified and tracking change
          of "status" is too much hassle.
      sql/event_db_repository.h:
        Removed logic for conditional update of "status" and
        "last_executed" fields from Event_db_repository::
        update_timing_fields_for_event() method.
        In the only case when this method is called now "last_executed"
        is always modified and tracking change of "status" field is
        too much hassle.
      sql/event_queue.cc:
        Changed event scheduler code not to update mysql.events
        table while holding Event_queue::LOCK_event_queue mutex.
        Doing so led to a deadlock with a new GRL implementation.
        This deadlock didn't occur with old implementation due to
        fact that code acquiring protection against GRL ignored
        pending GRL requests (which lead to GRL starvation).
        One of goals of new implementation is to disallow GRL
        starvation and so we have to solve problem with this
        deadlock in a different way.
      sql/events.cc:
        Changed methods of Events class to acquire protection
        against GRL while perfoming DDL statement and keep it
        until statement is written to the binary log.
        Unfortunately this step together with new GRL implementation
        exposed deadlock involving Events::LOCK_event_metadata
        and GRL. To solve it Events::LOCK_event_metadata mutex was
        replaced with a metadata lock on event. As a side-effect
        events DDL has to be prohibited under LOCK TABLES even in
        cases when mysql.events table was explicitly locked for
        write.
      sql/events.h:
        Replaced Events::LOCK_event_metadata mutex with a metadata
        lock on event.
      sql/ha_ndbcluster.cc:
        Updated code after replacing custom global read lock
        implementation with one based on MDL. Since MDL subsystem
        should now be able to detect deadlocks involving metadata
        locks and GRL there is no need for special handling of
        active GRL.
      sql/handler.cc:
        Replaced custom implementation of global read lock with
        one based on metadata locks. Consequently when doing
        commit instead of calling method of Global_read_lock
        class to acquire protection against GRL we simply acquire
        IX in COMMIT namespace.
      sql/lock.cc:
        Replaced custom implementation of global read lock with
        one based on metadata locks. This step allows to expose
        wait for GRL to deadlock detector of MDL subsystem and
        thus succesfully resolve deadlocks similar to one behind
        bug #57006 "Deadlock between HANDLER and FLUSH TABLES
        WITH READ LOCK". It also solves problem with GRL starvation
        described in bug #54673 "It takes too long to get readlock
        for 'FLUSH TABLES WITH READ LOCK'" since metadata locks used
        by GRL give preference to FTWRL statement instead of DML
        statements (if needed in future this can be changed to
        fair scheduling).
        
        Similar to old implementation of acquisition of GRL is
        two-step. During the first step we block all concurrent
        DML and DDL statements by acquiring global S metadata lock
        (each DML and DDL statement acquires global IX lock for
        its duration). During the second step we block commits by
        acquiring global S lock in COMMIT namespace (commit code
        acquires global IX lock in this namespace).
        
        Note that unlike in old implementation acquisition of
        protection against GRL in DML and DDL is semi-automatic.
        We assume that any statement which should be blocked by GRL
        will either open and acquires write-lock on tables or acquires
        metadata locks on objects it is going to modify. For any such
        statement global IX metadata lock is automatically acquired
        for its duration.
        
        To support this change:
        - Global_read_lock::lock/unlock_global_read_lock and
          make_global_read_lock_block_commit methods were changed
          accordingly.
        - Global_read_lock::wait_if_global_read_lock() and
          start_waiting_global_read_lock() methods were dropped.
          It is now responsibility of code acquiring metadata locks
          opening tables to acquire protection against GRL by
          explicitly taking global IX lock with statement duration.
        - Global variables, mutex and condition variable used by
          old implementation was removed.
        - lock_routine_name() was changed to use statement duration for
          its global IX lock. It was also renamed to lock_object_name()
          as it now also used to take metadata locks on events.
        - Global_read_lock::set_explicit_lock_duration() was added which
          allows not to release locks used for GRL when leaving prelocked
          mode.
      sql/lock.h:
        - Renamed lock_routine_name() to lock_object_name() and changed
          its signature to allow its usage for events.
        - Removed broadcast_refresh() function. It is no longer needed
          with new GRL implementation.
      sql/log_event.cc:
        Release metadata locks with statement duration at the end
        of processing legacy event for LOAD DATA. This ensures that
        replication thread processing such event properly releases
        its protection against global read lock.
      sql/mdl.cc:
        Changed MDL subsystem to support new MDL-based implementation
        of global read lock.
        
        Added COMMIT and EVENTS namespaces for metadata locks. Changed
        thread state name for GLOBAL namespace to "Waiting for global
        read lock".
        
        Optimized MDL_map::find_or_insert() method to avoid taking
        m_mutex mutex when looking up MDL_lock objects for GLOBAL
        or COMMIT namespaces. We keep pre-created MDL_lock objects
        for these namespaces around and simply return pointers to
        these global objects when needed.
        
        Changed MDL_lock/MDL_scoped_lock to properly handle
        notification of insert delayed handler threads when FTWRL
        takes global S lock.
        
        Introduced concept of lock duration. In addition to locks with
        transaction duration which work in the way which is similar to
        how locks worked before (i.e. they are released at the end of
        transaction), locks with statement and explicit duration were
        introduced.
        Locks with statement duration are automatically released at the
        end of statement. Locks with explicit duration require explicit
        release and obsolete concept of transactional sentinel.
        
        * Changed MDL_request and MDL_ticket classes to support notion
          of duration.
        * Changed MDL_context to keep locks with different duration in
          different lists. Changed code handling ticket list to take
          this into account.
        * Changed methods responsible for releasing locks to take into
          account duration of tickets. Particularly public
          MDL_context::release_lock() method now only can release
          tickets with explicit duration (there is still internal
          method which allows to specify duration). To release locks
          with statement or transaction duration one have to use
          release_statement/transactional_locks() methods.
        * Concept of savepoint for MDL subsystem now has to take into
          account locks with statement duration. Consequently
          MDL_savepoint class was introduced and methods working with
          savepoints were updated accordingly.
        * Added methods which allow to set duration for one or all
          locks in the context.
      sql/mdl.h:
        Changed MDL subsystem to support new MDL-based implementation
        of global read lock.
        
        Added COMMIT and EVENTS namespaces for metadata locks.
        
        Introduced concept of lock duration. In addition to locks with
        transaction duration which work in the way which is similar to
        how locks worked before (i.e. they are released at the end of
        transaction), locks with statement and explicit duration were
        introduced.
        Locks with statement duration are automatically released at the
        end of statement. Locks with explicit duration require explicit
        release and obsolete concept of transactional sentinel.
        
        * Changed MDL_request and MDL_ticket classes to support notion
          of duration.
        * Changed MDL_context to keep locks with different duration in
          different lists. Changed code handling ticket list to take
          this into account.
        * Changed methods responsible for releasing locks to take into
          account duration of tickets. Particularly public
          MDL_context::release_lock() method now only can release
          tickets with explicit duration (there is still internal
          method which allows to specify duration). To release locks
          with statement or transaction duration one have to use
          release_statement/transactional_locks() methods.
        * Concept of savepoint for MDL subsystem now has to take into
          account locks with statement duration. Consequently
          MDL_savepoint class was introduced and methods working with
          savepoints were updated accordingly.
        * Added methods which allow to set duration for one or all
          locks in the context.
      sql/mysqld.cc:
        Removed global mutex and condition variables which were used
        by old implementation of GRL.
        Also we no longer need to initialize Events::LOCK_event_metadata
        mutex as it was replaced with metadata locks on events.
      sql/mysqld.h:
        Removed global variable, mutex and condition variables which
        were used by old implementation of GRL.
      sql/rpl_rli.cc:
        When slave thread closes tables which were open for handling
        of RBR events ensure that it releases global IX lock which
        was acquired as protection against GRL.
      sql/sp.cc:
        Adjusted code to the new signature of lock_object/routine_name(),
        to the fact that one now needs specify duration of lock when
        initializing MDL_request and to the fact that savepoints for MDL
        subsystem are now represented by MDL_savepoint class.
      sql/sp_head.cc:
        Ensure that statements in stored procedures release statement
        metadata locks and thus release their protectiong against GRL
        in proper moment in time.
        Adjusted code to the fact that one now needs specify duration
        of lock when initializing MDL_request.
      sql/sql_admin.cc:
        Adjusted code to the fact that one now needs specify duration
        of lock when initializing MDL_request.
      sql/sql_base.cc:
        - Implemented support for new approach to acquiring protection
          against global read lock. We no longer acquire such protection
          explicitly on the basis of statement flags. Instead we always
          rely on code which is responsible for acquiring metadata locks
          on object to be changed acquiring this protection. This is
          achieved by acquiring global IX metadata lock with statement
          duration. Code doing this also responsible for checking that
          current connection has no active GRL by calling an
          Global_read_lock::can_acquire_protection() method.
          Changed code in open_table() and lock_table_names()
          accordingly.
          Note that as result of this change DDL and DML on temporary
          tables is always compatible with GRL (before it was
          incompatible in some cases and compatible in other cases).
        - To speed-up code acquiring protection against GRL introduced
          m_has_protection_against_grl member in Open_table_context
          class. It indicates that protection was already acquired
          sometime during open_tables() execution and new attempts
          can be skipped.
        - Thanks to new GRL implementation calls to broadcast_refresh()
          became unnecessary and were removed.
        - Adjusted code to the fact that one now needs specify duration
          of lock when initializing MDL_request and to the fact that
          savepoints for MDL subsystem are now represented by
          MDL_savepoint class.
      sql/sql_base.h:
        Adjusted code to the fact that savepoints for MDL subsystem are
        now represented by MDL_savepoint class.
        Also introduced Open_table_context::m_has_protection_against_grl
        member which allows to avoid acquiring protection against GRL
        while opening tables if such protection was already acquired.
      sql/sql_class.cc:
        Changed THD::leave_locked_tables_mode() after transactional
        sentinel for metadata locks was obsoleted by introduction of
        locks with explicit duration.
      sql/sql_class.h:
        - Adjusted code to the fact that savepoints for MDL subsystem
          are now represented by MDL_savepoint class.
        - Changed Global_read_lock class according to changes in
          global read lock implementation:
          * wait_if_global_read_lock and start_waiting_global_read_lock
            are now gone. Instead code needing protection against GRL
            has to acquire global IX metadata lock with statement
            duration itself. To help it new can_acquire_protection()
            was introduced. Also as result of the above change
            m_protection_count member is gone too.
          * Added m_mdl_blocks_commits_lock member to store metadata
            lock blocking commits.
          * Adjusted code to the fact that concept of transactional
            sentinel was obsoleted by concept of lock duration.
        - Removed CF_PROTECT_AGAINST_GRL flag as it is no longer
          necessary. New GRL implementation acquires protection
          against global read lock automagically when statement
          acquires metadata locks on tables or other objects it
          is going to change.
      sql/sql_db.cc:
        Adjusted code to the fact that one now needs specify duration
        of lock when initializing MDL_request.
      sql/sql_handler.cc:
        Removed call to broadcast_refresh() function. It is no longer
        needed with new GRL implementation.
        Adjusted code after introducing duration concept for metadata
        locks. Particularly to the fact transactional sentinel was
        replaced with explicit duration.
      sql/sql_handler.h:
        Renamed mysql_ha_move_tickets_after_trans_sentinel() to
        mysql_ha_set_explicit_lock_duration() after transactional
        sentinel was obsoleted by locks with explicit duration.
      sql/sql_insert.cc:
        Adjusted code handling delaying inserts after switching to
        new GRL implementation. Now connection thread initiating
        delayed insert has to acquire global IX lock in addition
        to metadata lock on table being inserted into. This IX lock
        protects against GRL and similarly to SW lock on table being
        inserted into has to be passed to handler thread in order to
        avoid deadlocks.
      sql/sql_lex.cc:
        LEX::protect_against_global_read_lock member is no longer
        necessary since protection against GRL is automatically
        taken by code acquiring metadata locks/opening tables.
      sql/sql_lex.h:
        LEX::protect_against_global_read_lock member is no longer
        necessary since protection against GRL is automatically
        taken by code acquiring metadata locks/opening tables.
      sql/sql_parse.cc:
        - Implemented support for new approach to acquiring protection
          against global read lock. We no longer acquire such protection
          explicitly on the basis of statement flags. Instead we always
          rely on code which is responsible for acquiring metadata locks
          on object to be changed acquiring this protection. This is
          achieved by acquiring global IX metadata lock with statement
          duration. This lock is automatically released at the end of
          statement execution.
        - Changed implementation of CREATE/DROP PROCEDURE/FUNCTION not
          to release metadata locks and thus protection against of GRL
          in the middle of statement execution.
        - Adjusted code to the fact that one now needs specify duration
          of lock when initializing MDL_request and to the fact that
          savepoints for MDL subsystem are now represented by
          MDL_savepoint class.
      sql/sql_prepare.cc:
        Adjusted code to the to the fact that savepoints for MDL
        subsystem are now represented by MDL_savepoint class.
      sql/sql_rename.cc:
        With new GRL implementation there is no need to explicitly
        acquire protection against GRL before renaming tables.
        This happens automatically in code which acquires metadata
        locks on tables being renamed.
      sql/sql_show.cc:
        Adjusted code to the fact that one now needs specify duration
        of lock when initializing MDL_request and to the fact that
        savepoints for MDL subsystem are now represented by
        MDL_savepoint class.
      sql/sql_table.cc:
        - With new GRL implementation there is no need to explicitly
          acquire protection against GRL before dropping tables.
          This happens automatically in code which acquires metadata
          locks on tables being dropped.
        - Changed mysql_alter_table() not to release lock on new table
          name explicitly and to rely on automatic release of locks
          at the end of statement instead. This was necessary since
          now MDL_context::release_lock() is supported only for locks
          for explicit duration.
      sql/sql_trigger.cc:
        With new GRL implementation there is no need to explicitly
        acquire protection against GRL before changing table triggers.
        This happens automatically in code which acquires metadata
        locks on tables which triggers are to be changed.
      sql/sql_update.cc:
        Fix bug exposed by GRL testing. During prepare phase acquire
        only S metadata locks instead of SW locks to keep prepare of
        multi-UPDATE compatible with concurrent LOCK TABLES WRITE
        and global read lock.
      sql/sql_view.cc:
        With new GRL implementation there is no need to explicitly
        acquire protection against GRL before creating view.
        This happens automatically in code which acquires metadata
        lock on view to be created.
      sql/sql_yacc.yy:
        LEX::protect_against_global_read_lock member is no longer
        necessary since protection against GRL is automatically
        taken by code acquiring metadata locks/opening tables.
      sql/table.cc:
        Adjusted code to the fact that one now needs specify duration
        of lock when initializing MDL_request.
      sql/table.h:
        Adjusted code to the fact that one now needs specify duration
        of lock when initializing MDL_request.
      sql/transaction.cc:
        Replaced custom implementation of global read lock with
        one based on metadata locks. Consequently when doing
        commit instead of calling method of Global_read_lock
        class to acquire protection against GRL we simply acquire
        IX in COMMIT namespace.
        Also adjusted code to the fact that MDL savepoint is now
        represented by MDL_savepoint class.
      6bf6272f
  5. 23 Oct, 2010 1 commit
    • unknown's avatar
      Bug#27606 GRANT statement should be replicated with DEFINER information · 06c49d57
      unknown authored
      "Grantor" columns' data is lost when replicating mysql.tables_priv.
      Slave SQL thread used its default user ''@'' as the grantor of GRANT|REVOKE
      statements executing on it.
      
      In this patch, current user is put in query log event for all GRANT and REVOKE
      statement, SQL thread uses the user in query log event as grantor.
      
      
      mysql-test/suite/rpl/r/rpl_do_grant.result:
        Add test for this bug.
      mysql-test/suite/rpl/t/rpl_do_grant.test:
        Add test for this bug.
      sql/log_event.cc:
        Refactoring THD::current_user_used and related functions.
        current_user_used is used to judge if current user should be
        binlogged in query log event. So it is better to call it m_binlog_invoker.
        The related functions are renamed too.
      sql/sql_class.cc:
        Refactoring THD::current_user_used and related functions.
        current_user_used is used to judge if current user should be
        binlogged in query log event. So it is better to call it m_binlog_invoker.
        The related functions are renamed too.
      sql/sql_class.h:
        Refactoring THD::current_user_used and related functions.
        current_user_used is used to judge if current user should be
        binlogged in query log event. So it is better to call it m_binlog_invoker.
        The related functions are renamed too.
      sql/sql_parse.cc:
        Call binlog_invoker() for GRANT and REVOKE statements.
      06c49d57
  6. 22 Oct, 2010 1 commit
    • Davi Arnaut's avatar
      Bug#37780: Make KILL reliable (main.kill fails randomly) · 2881b801
      Davi Arnaut authored
      - A prerequisite cleanup patch for making KILL reliable.
      
      The test case main.kill did not work reliably.
      
      The following problems have been identified:
      
      1. A kill signal could go lost if it came in, short before a
      thread went reading on the client connection.
      
      2. A kill signal could go lost if it came in, short before a
      thread went waiting on a condition variable.
      
      These problems have been solved as follows. Please see also
      added code comments for more details.
      
      1. There is no safe way to detect, when a thread enters the
      blocking state of a read(2) or recv(2) system call, where it
      can be interrupted by a signal. Hence it is not possible to
      wait for the right moment to send a kill signal. It has been
      decided, not to fix it in the code.  Instead, the test case
      repeats the KILL statement until the connection terminates.
      
      2. Before waiting on a condition variable, we register it
      together with a synchronizating mutex in THD::mysys_var. After
      this, we need to test THD::killed again. At some places we did
      only test it in a loop condition before the registration. When
      THD::killed had been set between this test and the registration,
      we entered waiting without noticing the killed flag. Additional
      checks ahve been introduced where required.
      
      In addition to the above, a re-write of the main.kill test
      case has been done. All sleeps have been replaced by Debug
      Sync Facility synchronization. A couple of sync points have
      been added to the server code.
      
      To avoid further problems, if the test case fails in spite of
      the fixes, the test case has been added to the "experimental"
      list for now.
      
      - Most of the work on this patch is authored by Ingo Struewing
      
      
      mysql-test/t/kill.test:
        Re-wrote test case to use Debug Sync points instead of sleeps
      sql/event_queue.cc:
        Fixed kill detection in Event_queue::cond_wait() by adding a check
        after enter_cond().
      sql/lock.cc:
        Moved Debug Sync points behind enter_cond().
        Fixed comments.
      sql/slave.cc:
        Fixed kill detection in start_slave_thread() by adding a check
        after enter_cond().
      sql/sql_class.cc:
        Swapped order of kill and close in THD::awake().
        Added comments.
      sql/sql_class.h:
        Added a comment to THD::killed.
      sql/sql_parse.cc:
        Added a sync point in do_command().
      sql/sql_select.cc:
        Added a sync point in JOIN::optimize().
      2881b801
  7. 21 Oct, 2010 1 commit
    • Dmitry Shulga's avatar
      Fixed bug#45445 - cannot execute procedures with thread_stack · 89e43c84
      Dmitry Shulga authored
      set to 128k.
      
      sql/sp.cc:
        Added checking for stack overrun at functions
        db_load_routine/sp_find_routine.
      sql/sp_head.cc:
        sp_head::execute() modified: pass constant value STACK_MIN_SIZE
        instead of 8 * STACK_MIN_SIZE  as second argument value
        in call to check_stack_overrun. Added checking for stack overrun
        at functions sp_lex_keeper::reset_lex_and_exec_core/sp_instr_stmt::execute.
      sql/sql_parse.cc:
        check_stack_overrun modified: allocate buffer for error message
        at heap instead of stack.
        parse_sql modified: added call to check_stack_overrun() before
        parsing of sql statement.
      89e43c84
  8. 16 Oct, 2010 1 commit
    • unknown's avatar
      Bug#56118 STOP SLAVE does not wait till trx with CREATE TMP TABLE ends, · 211552cc
      unknown authored
                replication aborts
      
      When recieving a 'SLAVE STOP' command, slave SQL thread will roll back the
      transaction and stop immidiately if there is only transactional table updated,
      even through 'CREATE|DROP TEMPOARY TABLE' statement are in it. But These
      statements can never be rolled back. Because the temporary tables to the user
      session mapping remain until 'RESET SLAVE', Therefore it will abort SQL thread
      with an error that the table already exists or doesn't exist, when it restarts
      and executes the whole transaction again.
      
      After this patch, SQL thread always waits till the transaction ends and then stops,
      if 'CREATE|DROP TEMPOARY TABLE' statement are in it.
      
      mysql-test/extra/rpl_tests/rpl_stop_slave.test:
        Auxiliary file which is used to test this bug.
      mysql-test/suite/rpl/t/rpl_stop_slave.test:
        Test case for this bug.
      sql/slave.cc:
        Checking if OPTION_KEEP_LOG is set. If it is set, SQL thread should wait
        until the transaction ends.
      sql/sql_parse.cc:
        Add a debug point for testing this bug.
      211552cc
  9. 07 Oct, 2010 1 commit
    • Dmitry Lenev's avatar
      Fix for bug#57061 "User without privilege on routine can · eaae6752
      Dmitry Lenev authored
      discover its existence".
      
      The problem was that user without any privileges on 
      routine was able to find out whether it existed or not.
      DROP FUNCTION and DROP PROCEDURE statements were 
      checking if routine being dropped existed and reported 
      ER_SP_DOES_NOT_EXIST error/warning before checking 
      if user had enough privileges to drop it.
      
      This patch solves this problem by changing code not to 
      check if routine exists before checking if user has enough 
      privileges to drop it. Moreover we no longer perform this 
      check using a separate call instead we rely on 
      sp_drop_routine() returning SP_KEY_NOT_FOUND if routine 
      doesn't exist.
      
      This change also simplifies one of upcoming patches
      refactoring global read lock implementation.
      
      mysql-test/r/grant.result:
        Updated test case after fixing bug#57061 "User without
        privilege on routine can discover its existence". Removed
        DROP PROCEDURE/FUNCTION statements which have started to
        fail after this fix (correctly). There is no need in
        dropping routines in freshly created database anyway.
      mysql-test/r/sp-security.result:
        Added new test case for bug#57061 "User without privilege
        on routine can discover its existence". Updated existing
        tests according to new behaviour.
      mysql-test/suite/funcs_1/r/innodb_storedproc_06.result:
        Updated test case after fixing bug#57061 "User without
        privilege on routine can discover its existence".
        Now we drop routines under user which has enough
        privileges to do so.
      mysql-test/suite/funcs_1/r/memory_storedproc_06.result:
        Updated test case after fixing bug#57061 "User without
        privilege on routine can discover its existence".
        Now we drop routines under user which has enough
        privileges to do so.
      mysql-test/suite/funcs_1/r/myisam_storedproc_06.result:
        Updated test case after fixing bug#57061 "User without
        privilege on routine can discover its existence".
        Now we drop routines under user which has enough
        privileges to do so.
      mysql-test/suite/funcs_1/storedproc/storedproc_06.inc:
        Updated test case after fixing bug#57061 "User without
        privilege on routine can discover its existence".
        Now we drop routines under user which has enough
        privileges to do so.
      mysql-test/t/grant.test:
        Updated test case after fixing bug#57061 "User without
        privilege on routine can discover its existence". Removed
        DROP PROCEDURE/FUNCTION statements which have started to
        fail after this fix (correctly). There is no need in
        dropping routines in freshly created database anyway.
      mysql-test/t/sp-security.test:
        Added new test case for bug#57061 "User without privilege
        on routine can discover its existence". Updated existing
        tests according to new behaviour.
      sql/sp.cc:
        Removed sp_routine_exists_in_table() which is no longer
        used.
      sql/sp.h:
        Removed sp_routine_exists_in_table() which is no longer
        used.
      sql/sql_parse.cc:
        When dropping routine we no longer check if routine exists 
        before checking if user has enough privileges to do so. 
        Moreover we no longer perform this check using a separate 
        call instead we rely on sp_drop_routine() returning 
        SP_KEY_NOT_FOUND if routine doesn't exist.
      eaae6752
  10. 06 Oct, 2010 1 commit
    • Davi Arnaut's avatar
      Bug#49938: Failing assertion: inode or deadlock in fsp/fsp0fsp.c · a5efb91d
      Davi Arnaut authored
      Bug#54678: InnoDB, TRUNCATE, ALTER, I_S SELECT, crash or deadlock
      
      - Incompatible change: truncate no longer resorts to a row by
      row delete if the storage engine does not support the truncate
      method. Consequently, the count of affected rows does not, in
      any case, reflect the actual number of rows.
      
      - Incompatible change: it is no longer possible to truncate a
      table that participates as a parent in a foreign key constraint,
      unless it is a self-referencing constraint (both parent and child
      are in the same table). To work around this incompatible change
      and still be able to truncate such tables, disable foreign checks
      with SET foreign_key_checks=0 before truncate. Alternatively, if
      foreign key checks are necessary, please use a DELETE statement
      without a WHERE condition.
      
      Problem description:
      
      The problem was that for storage engines that do not support
      truncate table via a external drop and recreate, such as InnoDB
      which implements truncate via a internal drop and recreate, the
      delete_all_rows method could be invoked with a shared metadata
      lock, causing problems if the engine needed exclusive access
      to some internal metadata. This problem originated with the
      fact that there is no truncate specific handler method, which
      ended up leading to a abuse of the delete_all_rows method that
      is primarily used for delete operations without a condition.
      
      Solution:
      
      The solution is to introduce a truncate handler method that is
      invoked when the engine does not support truncation via a table
      drop and recreate. This method is invoked under a exclusive
      metadata lock, so that there is only a single instance of the
      table when the method is invoked.
      
      Also, the method is not invoked and a error is thrown if
      the table is a parent in a non-self-referencing foreign key
      relationship. This was necessary to avoid inconsistency as
      some integrity checks are bypassed. This is inline with the
      fact that truncate is primarily a DDL operation that was
      designed to quickly remove all data from a table.
      
      mysql-test/suite/innodb/t/innodb-truncate.test:
        Add test cases for truncate and foreign key checks.
        Also test that InnoDB resets auto-increment on truncate.
      mysql-test/suite/innodb/t/innodb.test:
        FK is not necessary, test is related to auto-increment.
        
        Update error number, truncate is no longer invoked if
        table is parent in a FK relationship.
      mysql-test/suite/innodb/t/innodb_mysql.test:
        Update error number, truncate is no longer invoked if
        table is parent in a FK relationship.
        
        Use delete instead of truncate, test is used to check
        the interaction of FKs, triggers and delete.
      mysql-test/suite/parts/inc/partition_check.inc:
        Fix typo.
      mysql-test/suite/sys_vars/t/foreign_key_checks_func.test:
        Update error number, truncate is no longer invoked if
        table is parent in a FK relationship.
      mysql-test/t/mdl_sync.test:
        Modify test case to reflect and ensure that truncate takes
        a exclusive metadata lock.
      mysql-test/t/trigger-trans.test:
        Update error number, truncate is no longer invoked if
        table is parent in a FK relationship.
      sql/ha_partition.cc:
        Reorganize the various truncate methods. delete_all_rows is now
        passed directly to the underlying engines, so as truncate. The
        code responsible for truncating individual partitions is moved
        to ha_partition::truncate_partition, which is invoked when a
        ALTER TABLE t1 TRUNCATE PARTITION p statement is executed.
        
        Since the partition truncate no longer can be invoked via
        delete, the bitmap operations are not necessary anymore. The
        explicit reset of the auto-increment value is also removed
        as the underlying engines are now responsible for reseting
        the value.
      sql/handler.cc:
        Wire up the handler truncate method.
      sql/handler.h:
        Introduce and document the truncate handler method. It assumes
        certain use cases of delete_all_rows.
        
        Add method to retrieve the list of foreign keys referencing a
        table. Method is used to avoid truncating tables that are
        parent in a foreign key relationship.
      sql/share/errmsg-utf8.txt:
        Add error message for truncate and FK.
      sql/sql_lex.h:
        Introduce a flag so that the partition engine can detect when
        a partition is being truncated. Used to give a special error.
      sql/sql_parse.cc:
        Function mysql_truncate_table no longer exists.
      sql/sql_partition_admin.cc:
        Implement the TRUNCATE PARTITION statement.
      sql/sql_truncate.cc:
        Change the truncate table implementation to use the new truncate
        handler method and to not rely on row-by-row delete anymore.
        
        The truncate handler method is always invoked with a exclusive
        metadata lock. Also, it is no longer possible to truncate a
        table that is parent in some non-self-referencing foreign key.
      storage/archive/ha_archive.cc:
        Rename method as the description indicates that in the future
        this could be a truncate operation.
      storage/blackhole/ha_blackhole.cc:
        Implement truncate as no operation for the blackhole engine in
        order to remain compatible with older releases.
      storage/federated/ha_federated.cc:
        Introduce truncate method that invokes delete_all_rows.
        This is required to support partition truncate as this
        form of truncate does not implement the drop and recreate
        protocol.
      storage/heap/ha_heap.cc:
        Introduce truncate method that invokes delete_all_rows.
        This is required to support partition truncate as this
        form of truncate does not implement the drop and recreate
        protocol.
      storage/ibmdb2i/ha_ibmdb2i.cc:
        Introduce truncate method that invokes delete_all_rows.
        This is required to support partition truncate as this
        form of truncate does not implement the drop and recreate
        protocol.
      storage/innobase/handler/ha_innodb.cc:
        Rename delete_all_rows to truncate. InnoDB now does truncate
        under a exclusive metadata lock.
        
        Introduce and reorganize methods used to retrieve the list
        of foreign keys referenced by a or referencing a table.
      storage/myisammrg/ha_myisammrg.cc:
        Introduce truncate method that invokes delete_all_rows.
        This is required in order to remain compatible with earlier
        releases where truncate would resort to a row-by-row delete.
      a5efb91d
  11. 22 Sep, 2010 1 commit
    • Jon Olav Hauglid's avatar
      Bug #56494 Segfault in upgrade_shared_lock_to_exclusive() for · e14934d2
      Jon Olav Hauglid authored
                 REPAIR of merge table
      Bug #56422 CHECK TABLE run when the table is locked reports
                 corruption along with timeout
      
      The crash happened if a table maintenance statement (ANALYZE TABLE,
      REPAIR TABLE, etc.) was executed on a MERGE table and opening and 
      locking a child table failed. This could for example happen if a child
      table did not exist or if a lock timeout happened while waiting for
      a conflicting metadata lock to disappear.
      
      Since opening and locking the MERGE table and its children failed,
      the tables would be closed and the metadata locks released.
      However, TABLE_LIST::table for the MERGE table would still be set,
      with its value invalid since the tables had been closed.
      This caused the table maintenance statement to try to continue
      and upgrade the metadata lock on the MERGE table. But since the lock
      already had been released, this caused a segfault.
      
      This patch fixes the problem by setting TABLE_LIST::table to NULL 
      if open_and_lock_tables() fails. This prevents maintenance
      statements from continuing and trying to upgrade the metadata lock.
      
      The patch includes a 5.5 version of the fix for
      Bug #46339 crash on REPAIR TABLE merge table USE_FRM.
      This bug caused REPAIR TABLE ... USE_FRM to give an assert 
      when used on merge tables.
      
      The patch also enables the CHECK TABLE statement for log tables.
      Before, CHECK TABLE for log tables gave ER_CANT_LOCK_LOG_TABLE,
      yet still counted the statement as successfully executed.
      With the changes to table maintenance statement error handling
      in this patch, CHECK TABLE would no longer be considered as
      successful in this case. This would have caused upgrade scripts
      to mistakenly think that the general and slow logs are corrupted
      and have to be repaired. Enabling CHECK TABLES for log tables
      prevents this from happening.
      
      Finally, the patch changes the error message from "Corrupt" to
      "Operation failed" for a number of issues not related to table
      corruption. For example "Lock wait timeout exceeded" and 
      "Deadlock found trying to get lock".
      
      Test cases added to merge.test and check.test.
      e14934d2
  12. 31 Aug, 2010 2 commits
    • Alexander Nozdrin's avatar
      Remove check_merge_table_access(). · 587f776c
      Alexander Nozdrin authored
      check_merge_table_access() used to do two things:
        - set proper database for every merge table child;
        - check SELECT | UPDATE | DELETE for merge table children.
      
      Setting database is not needed anymore, since it's done
      on the parsing stage.
      
      Thus, check_merge_table_access() can be removed;
      needed privileges can be checked using check_table_access().
      587f776c
    • Alexander Nozdrin's avatar
      Bug#27480 (Extend CREATE TEMPORARY TABLES privilege · 65c5e8dc
      Alexander Nozdrin authored
      to allow temp table operations) -- prerequisite patch #2.
      
      Introduce a new form of find_temporary_table() function:
      find_temporary_table() by a table key. It will be used
      in further patches.
      
      Replace find_temporary_table(table_list->db, table_list->name)
      by more appropiate find_temporary_table(table_list) across
      the codebase.
      65c5e8dc
  13. 18 Aug, 2010 2 commits
    • unknown's avatar
      WL#5370 Keep forward-compatibility when changing · d0d8bbed
      unknown authored
              'CREATE TABLE IF NOT EXISTS ... SELECT' behaviour
      BUG#47132, BUG#47442, BUG49494, BUG#23992 and BUG#48814 will disappear
      automatically after the this patch.
      BUG#55617 is fixed by this patch too.
                  
      This is the 5.5 part.
      It implements:
      - 'CREATE TABLE IF NOT EXISTS ... SELECT' statement will not insert
        anything and binlog anything if the table already exists.
        It only generate a warning that table already exists.
      - A couple of test cases for the behavior changing.
      d0d8bbed
    • unknown's avatar
      WL#5370 Keep forward-compatibility when changing · 9d681150
      unknown authored
              'CREATE TABLE IF NOT EXISTS ... SELECT' behaviour
      BUG#55474, BUG#55499, BUG#55598, BUG#55616 and BUG#55777 are fixed
      in this patch too.
      
      This is the 5.1 part.
      It implements:
      - if the table exists, binlog two events: CREATE TABLE IF NOT EXISTS
        and INSERT ... SELECT
      
      - Insert nothing and binlog nothing on master if the existing object
        is a view. It only generates a warning that table already exists.
      
      
      mysql-test/r/trigger.result:
        Ather this patch, 'CREATE TABLE IF NOT EXISTS ... SELECT' will not
        insert anything if the creating table already exists and is a view.
      sql/sql_class.h:
        Declare virtual function write_to_binlog() for select_insert.
        It's used to binlog 'create select'
      sql/sql_insert.cc:
        Implement write_to_binlog();
        Use write_to_binlog() instead of binlog_query() to binlog the statement.
        if the table exists, binlog two events: CREATE TABLE IF NOT EXISTS
        and INSERT ... SELECT
      sql/sql_lex.h:
        Declare create_select_start_with_brace and create_select_pos.
        They are helpful for binlogging 'create select'
      sql/sql_parse.cc:
        Do nothing on master if the existing object is a view.
      sql/sql_yacc.yy:
        Record the relative postion of 'SELECT' in the 'CREATE ...SELECT' statement.
        Record whether there is a '(' before the 'SELECT' clause.
      9d681150
  14. 16 Aug, 2010 2 commits
    • Mattias Jonsson's avatar
    • Mattias Jonsson's avatar
      Bug#49907: ALTER TABLE ... TRUNCATE PARTITION does not wait for · 4b20ccaf
      Mattias Jonsson authored
                 locks on the table
      
      Fixing the partitioning specifics after TRUNCATE TABLE in
      bug-42643 was fixed.
      
      Reorganize of code to decrease the size of the giant switch
      in mysql_execute_command, and to prepare for future parser
      reengineering. Moved code into Sql_statement objects.
      
      Updated patch according to davi's review comments.
      
      libmysqld/CMakeLists.txt:
        Added new files.
      libmysqld/Makefile.am:
        Added new files.
      mysql-test/r/not_partition.result:
        now returning error on partitioning commands
        if partitioning is not enabled.
      mysql-test/r/partition_disabled.result:
        There is no partition handlerton, so it cannot
        find the specified engine in the .frm file.
      mysql-test/r/partition_truncate.result:
        Updated test results.
      mysql-test/suite/parts/inc/partition_mgm.inc:
        Added check that TRUNCATE PARTITION does not delete on failure.
      mysql-test/suite/parts/r/partition_debug_sync_innodb.result:
        updated results.
      mysql-test/suite/parts/r/partition_mgm_lc0_archive.result:
        updated results.
      mysql-test/suite/parts/r/partition_mgm_lc1_archive.result:
        updated results.
      mysql-test/suite/parts/r/partition_mgm_lc2_archive.result:
        updated results.
      mysql-test/suite/parts/t/partition_debug_sync_innodb.test:
        Test case for this bug.
      mysql-test/t/not_partition.test:
        Added check for TRUNCATE PARTITION without partitioning.
      mysql-test/t/partition_truncate.test:
        Added test of TRUNCATE PARTITION on non partitioned table.
      sql/CMakeLists.txt:
        Added new files.
      sql/Makefile.am:
        Added new files.
      sql/datadict.cc:
        Moved out the storage engine check into an own
        function, including assert for lock.
      sql/datadict.h:
        added dd_frm_storage_engine.
      sql/sql_alter_table.cc:
        moved the code for SQLCOM_ALTER_TABLE in mysql_execute_command
        into its own file, and using the Sql_statement object to
        prepare for future parser reengineering.
      sql/sql_alter_table.h:
        Created Sql_statement object for ALTER TABLE.
      sql/sql_lex.cc:
        resetting m_stmt.
      sql/sql_lex.h:
        Temporary hack for forward declaration of enum_alter_table_change_level.
      sql/sql_parse.cc:
        Moved out ALTER/ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE
        from the giant switch into their own Sql_statement
        objects.
      sql/sql_parse.h:
        Exporting check_merge_table_access.
      sql/sql_partition_admin.cc:
        created Sql_statement for
        ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR/TRUNCATE
        PARTITION. To be able to reuse the TABLE equivalents.
      sql/sql_partition_admin.h:
        Added Sql_statement of partition admin statements.
      sql/sql_table.cc:
        Moved table maintenance code into sql_table_maintenance.cc
      sql/sql_table.h:
        Moved table maintenance code into sql_table_maintenance.h
        exporting functions used by sql_table_maintenance.
      sql/sql_table_maintenance.cc:
        Moved table maintenance code from sql_table.cc
      sql/sql_table_maintenance.h:
        Sql_statement objects for ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE.
        Also declaring the keycache functions.
      sql/sql_truncate.cc:
        Moved code from SQLCOM_TRUNCATE in mysql_execute_command into
        Truncate_statement::execute.
        Added check for partitioned table on TRUNCATE PARTITION.
        Moved locking fix for partitioned table into
        Alter_table_truncate_partition::execute.
      sql/sql_truncate.h:
        Truncate_statement declaration (sub class of Sql_statement).
      sql/sql_yacc.yy:
        Using the new Sql_statment objects.
      4b20ccaf
  15. 13 Aug, 2010 1 commit
  16. 12 Aug, 2010 1 commit
  17. 10 Aug, 2010 1 commit
    • Alfranio Correia's avatar
      BUG#50312 Warnings for unsafe sub-statement not returned to client · 88b32056
      Alfranio Correia authored
                              
      After BUG#36649, warnings for sub-statements are cleared when a 
      new sub-statement is started. This is problematic since it suppresses
      warnings for unsafe statements in some cases. It is important that we
      always give a warning to the client, because the user needs to know
      when there is a risk that the slave goes out of sync.
                              
      We fixed the problem by generating warning messages for unsafe statements
      while returning from a stored procedure, function, trigger or while
      executing a top level statement.
                              
      We also started checking unsafeness when both performance and log tables are
      used. This is necessary after the performance schema which does a distinction
      between performance and log tables.
      
      mysql-test/extra/rpl_tests/create_recursive_construct.inc:
        Changed the order of the calls in the procedure because the code
        that checks if a warning message is printed out expects that the
        first statement gives an warning what is not the case for INSERT
        INTO ta$CRC_ARG_level VALUES (47);
      mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result:
        Updated the result file.
      mysql-test/suite/binlog/r/binlog_unsafe.result:
        There are several changes here:
                
        (1) - Changed the CREATE PROCEDURE $CRC.
                                        
        (2) - The procedure $CRC was failing and the content of the binlog
              was being printed out, after fix (1) the failure disappeared.
                                        
        (3) - The warning message for unsafeness due to auto-increment collumns was
              changed.
                                        
        (4) - The warning message for unsafeness due to VERSION(), RAND() was changed.
      mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test:
        Tested filters.
      mysql-test/suite/binlog/t/binlog_unsafe.test:
        Reenabled the test case binlog_unsafe.
      mysql-test/suite/binlog/t/disabled.def:
        Reenabled the test case binlog_unsafe.
      mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result:
        Updated the result file.
      mysql-test/suite/rpl/r/rpl_non_direct_stm_mixing_engines.result:
        Updated the result file.
      mysql-test/suite/rpl/r/rpl_stm_auto_increment_bug33029.result:
        Updated the result file.
      sql/sql_class.cc:
        Moved the stmt_accessed_table_flag variable and related information to the
        LEX as we need the variable reset after each statement even inside a stored
        procedure, what did not happen if the information was in the THD.
                
        Changed the routine in the THD::binlog_query that prints the warning
        messages to avoid trying to print them when inside a stored procedure,
        function or trigger.
                                
        Checked for unsafeness when both performance and log tables where used.
        After the introduction of the performance schema, we need to check both.
      88b32056
  18. 09 Aug, 2010 2 commits
    • Konstantin Osipov's avatar
      A fix for Bug#41158 "DROP TABLE holds LOCK_open during unlink()". · 52306698
      Konstantin Osipov authored
      Remove acquisition of LOCK_open around file system operations,
      since such operations are now protected by metadata locks.
      Rework table discovery algorithm to not require LOCK_open.
      
      No new tests added since all MDL locking operations are covered
      in lock.test and mdl_sync.test, and as long as these tests
      pass despite the increased concurrency, consistency must be
      unaffected.
      
      mysql-test/t/disabled.def:
        Disable NDB tests due to Bug#55799.
      sql/datadict.cc:
        No longer necessary to protect ha_create_table() with
        LOCK_open. Serial execution is now ensured by metadata
        locks.
      sql/ha_ndbcluster.cc:
        Do not manipulate with LOCK_open in cluster code.
      sql/ha_ndbcluster_binlog.cc:
        Do not manipulate with LOCK_open in cluster code.
      sql/ha_ndbcluster_binlog.h:
        Update function signature.
      sql/handler.cc:
        Implement ha_check_if_table_exists().
        @todo: some engines provide ha_table_exists_in_engine()
        handlerton call, for those we perhaps shouldn't
        call ha_discover(), to be more efficient.
        Since currently it's only NDB, postpone till
        integration with NDB.
      sql/handler.h:
        Declare ha_check_if_table_exists() function.
      sql/mdl.cc:
        Remove an obsolete comment.
      sql/sql_base.cc:
        Update to a new signature of close_cached_tables():
        from now on we always call it without LOCK_open.
        Update comments.
        Remove get_table_share_with_create(), we should
        not attempt to create a table under LOCK_open.
        Introduce get_table_share_with_discover() instead,
        which would request a back off action if the table
        exists in engine.
        Remove acquisition of LOCK_open for 
        data dictionary operations, such as check_if_table_exists().
        Do not use get_table_share_with_create/discover for views,
        where it's not needed.
        Make tdc_remove_table() optionally acquire LOCK_open
        to simplify usage of this function.
        Use the right mutex in the partitioning code when
        manipulating with thd->open_tables.
      sql/sql_base.h:
        Update signatures of changes functions.
      sql/sql_insert.cc:
        Do not wrap quick_rm_table() with LOCK_open acquisition, 
        this is unnecessary.
      sql/sql_parse.cc:
        Update to the new calling convention of tdc_remove_table().
        Update to the new signature of close_cached_tables().
        Update comments.
      sql/sql_rename.cc:
        Update to the new calling convention of tdc_remove_table().
        Remove acquisition of LOCK_open around filesystem
        operations.
      sql/sql_show.cc:
        Remove get_trigger_table_impl().
        Do not acquire LOCK_open for a dirty read of the trigger
        file.
      sql/sql_table.cc:
        Do not acquire LOCK_open for filesystem operations.
      sql/sql_trigger.cc:
        Do not require LOCK_open for trigger file I/O.
      sql/sql_truncate.cc:
        Update to the new signature of tdc_remove_table().
      sql/sql_view.cc:
        Do not require LOCK_open for view I/O.
        Use tdc_remove_table() to expel view share.
        Update comments.
      sql/sys_vars.cc:
        Update to the new signature of close_cached_tables().
      52306698
    • Georgi Kodinov's avatar
      WL#1054: Pluggable authentication support · 97057115
      Georgi Kodinov authored
      Merged the implementation to a new base tree.
      97057115
  19. 29 Jul, 2010 1 commit
    • unknown's avatar
      BUG#49124 Security issue with /*!-versioned */ SQL statements on Slave · 2124538d
      unknown authored
      /*![:version:] Query Code */, where [:version:] is a sequence of 5 
      digits representing the mysql server version(e.g /*!50200 ... */),
      is a special comment that the query in it can be executed on those 
      servers whose versions are larger than the version appearing in the 
      comment. It leads to a security issue when slave's version is larger 
      than master's. A malicious user can improve his privileges on slaves. 
      Because slave SQL thread is running with SUPER privileges, so it can
      execute queries that he/she does not have privileges on master.
      
      This bug is fixed with the logic below: 
      - To replace '!' with ' ' in the magic comments which are not applied on
        master. So they become common comments and will not be applied on slave.
      
      - Example:
        'INSERT INTO t1 VALUES (1) /*!10000, (2)*/ /*!99999 ,(3)*/
        will be binlogged as
        'INSERT INTO t1 VALUES (1) /*!10000, (2)*/ /* 99999 ,(3)*/
      
      mysql-test/suite/rpl/t/rpl_conditional_comments.test:
        Test the patch for this bug.
      sql/mysql_priv.h:
        Rename inBuf as rawBuf and remove the const limitation.
      sql/sql_lex.cc:
        To replace '!' with ' ' in the magic comments which are not applied on
        master.
      sql/sql_lex.h:
        Remove the const limitation on parameter buff, as it can be modified in the function since
        this patch.
        Add member function yyUnput for Lex_input_stream. It set a character back the query buff.
      sql/sql_parse.cc:
        Rename inBuf as rawBuf and remove the const limitation.
      sql/sql_partition.cc:
        Remove the const limitation on parameter part_buff, as it can be modified in the function since
        this patch.
      sql/sql_partition.h:
        Remove the const limitation on parameter part_buff, as it can be modified in the function since
        this patch.
      sql/table.h:
        Remove the const limitation on variable partition_info, as it can be modified since
        this patch.
      2124538d
  20. 28 Jul, 2010 1 commit
  21. 27 Jul, 2010 2 commits
    • Dmitry Lenev's avatar
      Fix for bug #52044 "FLUSH TABLES WITH READ LOCK and FLUSH · 00496b7a
      Dmitry Lenev authored
      TABLES <list> WITH READ LOCK are incompatible".
      
      The problem was that FLUSH TABLES <list> WITH READ LOCK
      which was issued when other connection has acquired global
      read lock using FLUSH TABLES WITH READ LOCK was blocked
      and has to wait until global read lock is released.
      
      This issue stemmed from the fact that FLUSH TABLES <list>
      WITH READ LOCK implementation has acquired X metadata locks
      on tables to be flushed. Since these locks required acquiring
      of global IX lock this statement was incompatible with global
      read lock.
      
      This patch addresses problem by using SNW metadata type of
      lock for tables to be flushed by FLUSH TABLES <list> WITH
      READ LOCK. It is OK to acquire them without global IX lock
      as long as we won't try to upgrade those locks. Since SNW
      locks allow concurrent statements using same table FLUSH
      TABLE <list> WITH READ LOCK now has to wait until old
      versions of tables to be flushed go away after acquiring
      metadata locks. Since such waiting can lead to deadlock
      MDL deadlock detector was extended to take into account
      waits for flush and resolve such deadlocks.
      
      As a bonus code in open_tables() which was responsible for
      waiting old versions of tables to go away was refactored.
      Now when we encounter old version of table in open_table()
      we don't back-off and wait for all old version to go away,
      but instead wait for this particular table to be flushed.
      Such approach supported by deadlock detection should reduce
      number of scenarios in which FLUSH TABLES aborts concurrent
      multi-statement transactions.
      
      Note that active FLUSH TABLES <list> WITH READ LOCK still
      blocks concurrent FLUSH TABLES WITH READ LOCK statement
      as the former keeps tables open and thus prevents the
      latter statement from doing flush.
      
      mysql-test/include/handler.inc:
        Adjusted test case after changing status which is set
        when FLUSH TABLES waits for tables to be flushed from
        "Flushing tables" to "Waiting for table".
      mysql-test/r/flush.result:
        Added test which checks that "flush tables <list> with
        read lock" is compatible with active "flush tables with
        read lock" but not vice-versa. This test also covers
        bug #52044 "FLUSH TABLES WITH READ LOCK and FLUSH TABLES
        <list> WITH READ LOCK are incompatible".
      mysql-test/r/mdl_sync.result:
        Added scenarios in which wait for table to be flushed
        causes deadlocks to the coverage of MDL deadlock detector.
      mysql-test/suite/perfschema/r/dml_setup_instruments.result:
        Adjusted test results after removal of COND_refresh
        condition variable.
      mysql-test/suite/perfschema/r/server_init.result:
        Adjusted test and its results after removal of COND_refresh
        condition variable.
      mysql-test/suite/perfschema/t/server_init.test:
        Adjusted test and its results after removal of COND_refresh
        condition variable.
      mysql-test/t/flush.test:
        Added test which checks that "flush tables <list> with
        read lock" is compatible with active "flush tables with
        read lock" but not vice-versa. This test also covers
        bug #52044 "FLUSH TABLES WITH READ LOCK and FLUSH TABLES
        <list> WITH READ LOCK are incompatible".
      mysql-test/t/kill.test:
        Adjusted test case after changing status which is set
        when FLUSH TABLES waits for tables to be flushed from
        "Flushing tables" to "Waiting for table".
      mysql-test/t/lock_multi.test:
        Adjusted test case after changing status which is set
        when FLUSH TABLES waits for tables to be flushed from
        "Flushing tables" to "Waiting for table".
      mysql-test/t/mdl_sync.test:
        Added scenarios in which wait for table to be flushed
        causes deadlocks to the coverage of MDL deadlock detector.
      sql/ha_ndbcluster.cc:
        Adjusted code after adding one more parameter for
        close_cached_tables() call - timeout for waiting for
        table to be flushed.
      sql/ha_ndbcluster_binlog.cc:
        Adjusted code after adding one more parameter for
        close_cached_tables() call - timeout for waiting for
        table to be flushed.
      sql/lock.cc:
        Removed COND_refresh condition variable. See comment
        for sql_base.cc for details.
      sql/mdl.cc:
        Now MDL deadlock detector takes into account information
        about waits for table flushes when searching for deadlock.
        To implement this change:
        - Declaration of enum_deadlock_weight and
          Deadlock_detection_visitor were moved to mdl.h header
          to make them available to the code in table.cc which
          implements deadlock detector traversal through edges
          of waiters graph representing waiting for flush.
        - Since now MDL_context may wait not only for metadata
          lock but also for table to be flushed an abstract
          Wait_for_edge class was introduced. Its descendants
          MDL_ticket and Flush_ticket incapsulate specifics
          of inspecting waiters graph when following through
          edge representing wait of particular type.
        
        We no longer require global IX metadata lock when acquiring
        SNW or SNRW locks. Such locks are needed only when metadata
        locks of these types are upgraded to X locks. This allows
        to use SNW locks in FLUSH TABLES <list> WITH READ LOCK
        implementation and keep the latter compatible with global
        read lock.
      sql/mdl.h:
        Now MDL deadlock detector takes into account information
        about waits for table flushes when searching for deadlock.
        To implement this change:
        - Declaration of enum_deadlock_weight and
          Deadlock_detection_visitor were moved to mdl.h header
          to make them available to the code in table.cc which
          implements deadlock detector traversal through edges
          of waiters graph representing waiting for flush.
        - Since now MDL_context may wait not only for metadata
          lock but also for table to be flushed an abstract
          Wait_for_edge class was introduced. Its descendants
          MDL_ticket and Flush_ticket incapsulate specifics
          of inspecting waiters graph when following through
          edge representing wait of particular type.
        - Deadlock_detection_visitor now has m_table_shares_visited
          member which allows to support recursive locking for
          LOCK_open. This is required when deadlock detector
          inspects waiters graph which contains several edges
          representing waits for flushes or needs to come through
          the such edge more than once.
      sql/mysqld.cc:
        Removed COND_refresh condition variable. See comment
        for sql_base.cc for details.
      sql/mysqld.h:
        Removed COND_refresh condition variable. See comment
        for sql_base.cc for details.
      sql/sql_base.cc:
        Changed approach to how threads are waiting for table
        to be flushed. Now thread that wants to wait for old
        table to go away subscribes for notification by adding
        Flush_ticket to table's share and waits using
        MDL_context::m_wait object. Once table gets flushed
        (i.e. all tables are closed and table share is ready
        to be destroyed) all such waiters are notified
        individually.
        Thanks to this change MDL deadlock detector can take
        such waits into account.
        
        To implement this/as result of this change:
        - tdc_wait_for_old_versions() was replaced with
          tdc_wait_for_old_version() which waits for individual
          old share to go away and which is called by open_table()
          after finding out that share is outdated. We don't
          need to perform back-off before such waiting thanks
          to the fact that deadlock detector now sees such waits.
        - As result Open_table_ctx::m_mdl_requests became
          unnecessary and was removed. We no longer allocate
          copies of MDL_request objects on MEM_ROOT when
          MYSQL_OPEN_FORCE_SHARED/SHARED_HIGH_PRIO flags are
          in effect.
        - close_cached_tables() and tdc_wait_for_old_version()
          share code which implements waiting for share to be
          flushed - the both use TABLE_SHARE::wait_until_flush()
          method. Thanks to this close_cached_tables() supports
          timeouts and has extra parameter for this.
        - Open_table_context::OT_MDL_CONFLICT enum element was
          renamed to OT_CONFLICT as it is now also used in cases
          when back-off is required to resolve deadlock caused
          by waiting for flush and not metadata lock.
        - In cases when we discover that current connection tries
          to open tables from different generation we now simply
          back-off and restart process of opening tables. To
          support this Open_table_context::OT_REOPEN_TABLES enum
          element was added.
        - COND_refresh condition variable became unnecessary and
          was removed.
        - mysql_notify_thread_having_shared_lock() no longer wakes
          up connections waiting for flush as all such connections
          can be waken up by deadlock detector if necessary.
      sql/sql_base.h:
        - close_cached_tables() now has one more parameter -
          timeout for waiting for table to be flushed.
        - Open_table_context::OT_MDL_CONFLICT enum element was
          renamed to OT_CONFLICT as it is now also used in cases
          when back-off is required to resolve deadlock caused
          by waiting for flush and not metadata lock.
          Added new OT_REOPEN_TABLES enum element to be used in
          cases when we need to restart open tables process even
          in the middle of transaction.
        - Open_table_ctx::m_mdl_requests became unnecessary and
          was removed.
      sql/sql_class.h:
        Added assert ensuring that we won't use LOCK_open mutex
        with THD::enter_cond(). Otherwise deadlocks can arise in
        MDL deadlock detector.
      sql/sql_parse.cc:
        Changed FLUSH TABLES <list> WITH READ LOCK to take SNW
        metadata locks instead of X locks on tables to be flushed.
        Since we no longer require global IX lock to be taken
        when SNW locks are taken this makes this statement
        compatible with FLUSH TABLES WITH READ LOCK statement.
        Since SNW locks allow other connections to have table
        opened FLUSH TABLES <list> WITH READ LOCK now has to
        wait during open_tables() for old version to go away.
        Such waits can lead to deadlocks which will be detected
        by MDL deadlock detector which now takes waits for table
        to be flushed into account.
        
        Also adjusted code after adding one more parameter for
        close_cached_tables() call - timeout for waiting for
        table to be flushed.
      sql/sql_yacc.yy:
        FLUSH TABLES <list> WITH READ LOCK now needs only SNW
        metadata locks on tables.
      sql/sys_vars.cc:
        Adjusted code after adding one more parameter for
        close_cached_tables() call - timeout for waiting for
        table to be flushed.
      sql/table.cc:
        Implemented new approach to how threads are waiting for
        table to be flushed. Now thread that wants to wait for
        old table to go away subscribes for notification by
        adding Flush_ticket to table's share and waits using
        MDL_context::m_wait object. Once table gets flushed
        (i.e. all tables are closed and table share is ready
        to be destroyed) all such waiters are notified
        individually. This change allows to make such waits
        visible inside of MDL deadlock detector.
        To do it:
        
        - Added list of waiters/Flush_tickets to TABLE_SHARE
          class.
        - Changed free_table_share() to postpone freeing of
          share memory until last waiter goes away and to
          wake up subscribed waiters.
        - Added TABLE_SHARE::wait_until_flushed() method which
          implements subscription to the list of waiters for
          table to be flushed and waiting for this event.
        
        Implemented interface which allows to expose waits for
        flushes to MDL deadlock detector:
        
        - Introduced Flush_ticket class a descendant of
          Wait_for_edge class.
        - Added TABLE_SHARE::find_deadlock() method which allows
          deadlock detector to find out what contexts are still
          using old version of table in question (i.e. to find
          out what contexts are waited for by owner of
          Flush_ticket).
      sql/table.h:
        In order to support new strategy of waiting for table flush
        (see comment for table.cc for details) added list of
        waiters/Flush_tickets to TABLE_SHARE class.
        
        Implemented interface which allows to expose waits for
        flushes to MDL deadlock detector:
        - Introduced Flush_ticket class a descendant of
          Wait_for_edge class.
        - Added TABLE_SHARE::find_deadlock() method which allows
          deadlock detector to find out what contexts are still
          using old version of table in question (i.e. to find
          out what contexts are waited for by owner of
          Flush_ticket).
      00496b7a
    • Konstantin Osipov's avatar
      A pre-requisite patch for the fix for Bug#52044. · 36290c09
      Konstantin Osipov authored
      This patch also fixes Bug#55452 "SET PASSWORD is
      replicated twice in RBR mode".
      
      The goal of this patch is to remove the release of 
      metadata locks from close_thread_tables().
      This is necessary to not mistakenly release
      the locks in the course of a multi-step
      operation that involves multiple close_thread_tables()
      or close_tables_for_reopen().
      
      On the same token, move statement commit outside 
      close_thread_tables().
      
      Other cleanups:
      Cleanup COM_FIELD_LIST.
      Don't call close_thread_tables() in COM_SHUTDOWN -- there
      are no open tables there that can be closed (we leave
      the locked tables mode in THD destructor, and this
      close_thread_tables() won't leave it anyway).
      
      Make open_and_lock_tables() and open_and_lock_tables_derived()
      call close_thread_tables() upon failure.
      Remove the calls to close_thread_tables() that are now
      unnecessary.
      
      Simplify the back off condition in Open_table_context.
      
      Streamline metadata lock handling in LOCK TABLES 
      implementation.
      
      Add asserts to ensure correct life cycle of 
      statement transaction in a session.
      
      Remove a piece of dead code that has also become redundant
      after the fix for Bug 37521.
      
      mysql-test/r/variables.result:
        Update results: set @@autocommit and statement transaction/
        prelocked mode.
      mysql-test/r/view.result:
        A harmless change in CHECK TABLE <view> status for a broken view.
        If previously a failure to prelock all functions used in a view 
        would leave the connection in LTM_PRELOCKED mode, now we call
        close_thread_tables() from open_and_lock_tables()
        and leave prelocked mode, thus some check in mysql_admin_table() that
        works only in prelocked/locked tables mode is no longer activated.
      mysql-test/suite/rpl/r/rpl_row_implicit_commit_binlog.result:
        Fixed Bug#55452 "SET PASSWORD is replicated twice in
        RBR mode": extra binlog events are gone from the
        binary log.
      mysql-test/t/variables.test:
        Add a test case: set autocommit and statement transaction/prelocked
        mode.
      sql/event_data_objects.cc:
        Simplify code in Event_job_data::execute().
        Move sp_head memory management to lex_end().
      sql/event_db_repository.cc:
        Move the release of metadata locks outside
        close_thread_tables().
        Make sure we call close_thread_tables() when
        open_and_lock_tables() fails and remove extra
        code from the events data dictionary.
        Use close_mysql_tables(), a new internal
        function to properly close mysql.* tables
        in the data dictionary.
        Contract Event_db_repository::drop_events_by_field,
        drop_schema_events into one function.
        When dropping all events in a schema,
        make sure we don't mistakenly release all
        locks acquired by DROP DATABASE. These
        include locks on the database name
        and the global intention exclusive
        metadata lock.
      sql/event_db_repository.h:
        Function open_event_table() does not require an instance 
        of Event_db_repository.
      sql/events.cc:
        Use close_mysql_tables() instead of close_thread_tables()
        to bootstrap events, since the latter no longer
        releases metadata locks.
      sql/ha_ndbcluster.cc:
        - mysql_rm_table_part2 no longer releases
        acquired metadata locks. Do it in the caller.
      sql/ha_ndbcluster_binlog.cc:
        Deploy the new protocol for closing thread
        tables in run_query() and ndb_binlog_index
        code.
      sql/handler.cc:
        Assert that we never call ha_commit_trans/
        ha_rollback_trans in sub-statement, which
        is now the case.
      sql/handler.h:
        Add an accessor to check whether THD_TRANS object
        is empty (has no transaction started).
      sql/log.cc:
        Update a comment.
      sql/log_event.cc:
        Since now we commit/rollback statement transaction in 
        mysql_execute_command(), we need a mechanism to communicate
        from Query_log_event::do_apply_event() to mysql_execute_command()
        that the statement transaction should be rolled back, not committed.
        Ideally it would be a virtual method of THD. I hesitate
        to make THD a virtual base class in this already large patch.
        Use a thd->variables.option_bits for now.
        
        Remove a call to close_thread_tables() from the slave IO
        thread. It doesn't open any tables, and the protocol
        for closing thread tables is more complicated now.
        
        Make sure we properly close thread tables, however, 
        in Load_data_log_event, which doesn't
        follow the standard server execution procedure
        with mysql_execute_command().
        @todo: this piece should use Server_runnable
        framework instead.
        Remove an unnecessary call to mysql_unlock_tables().
      sql/rpl_rli.cc:
        Update Relay_log_info::slave_close_thread_tables()
        to follow the new close protocol.
      sql/set_var.cc:
        Remove an unused header.
      sql/slave.cc:
        Remove an unnecessary call to
        close_thread_tables().
      sql/sp.cc:
        Remove unnecessary calls to close_thread_tables()
        from SP DDL implementation. The tables will
        be closed by the caller, in mysql_execute_command().
        When dropping all routines in a database, make sure
        to not mistakenly drop all metadata locks acquired
        so far, they include the scoped lock on the schema.
      sql/sp_head.cc:
        Correct the protocol that closes thread tables
        in an SP instruction.
        Clear lex->sphead before cleaning up lex
        with lex_end to make sure that we don't
        delete the sphead twice. It's considered
        to be "cleaner" and more in line with
        future changes than calling delete lex->sphead
        in other places that cleanup the lex.
      sql/sp_head.h:
        When destroying m_lex_keeper of an instruction,
        don't delete the sphead that all lex objects
        share. 
        @todo: don't store a reference to routine's sp_head
        instance in instruction's lex.
      sql/sql_acl.cc:
        Don't call close_thread_tables() where the caller will
        do that for us.
        Fix Bug#55452 "SET PASSWORD is replicated twice in RBR 
        mode" by disabling RBR replication in change_password()
        function.
        Use close_mysql_tables() in bootstrap and ACL reload
        code to make sure we release all metadata locks.
      sql/sql_base.cc:
        This is the main part of the patch:
        - remove manipulation with thd->transaction
        and thd->mdl_context from close_thread_tables().
        Now this function is only responsible for closing
        tables, nothing else.
        This is necessary to be able to easily use
        close_thread_tables() in procedures, that
        involve multiple open/close tables, which all
        need to be protected continuously by metadata
        locks.
        Add asserts ensuring that TABLE object
        is only used when is protected by a metadata lock.
        Simplify the back off condition of Open_table_context,
        we no longer need to look at the autocommit mode.
        Make open_and_lock_tables() and open_normal_and_derived_tables()
        close thread tables and release metadata locks acquired so-far 
        upon failure. This simplifies their usage.
        Implement close_mysql_tables().
      sql/sql_base.h:
        Add declaration for close_mysql_tables().
      sql/sql_class.cc:
        Remove a piece of dead code that has also become redundant
        after the fix for Bug 37521.
        The code became dead when my_eof() was made a non-protocol method,
        but a method that merely modifies the diagnostics area.
        The code became redundant with the fix for Bug#37521, when 
        we started to cal close_thread_tables() before
        Protocol::end_statement().
      sql/sql_do.cc:
        Do nothing in DO if inside a substatement
        (the assert moved out of trans_rollback_stmt).
      sql/sql_handler.cc:
        Add comments.
      sql/sql_insert.cc:
        Remove dead code. 
        Release metadata locks explicitly at the
        end of the delayed insert thread.
      sql/sql_lex.cc:
        Add destruction of lex->sphead to lex_end(),
        lex "reset" method called at the end of each statement.
      sql/sql_parse.cc:
        Move close_thread_tables() and other related
        cleanups to mysql_execute_command()
        from dispatch_command(). This has become
        possible after the fix for Bug#37521.
        Mark federated SERVER statements as DDL.
        
        Next step: make sure that we don't store
        eof packet in the query cache, and move
        the query cache code outside mysql_parse.
        
        Brush up the code of COM_FIELD_LIST.
        Remove unnecessary calls to close_thread_tables().
        
        When killing a query, don't report "OK"
        if it was a suicide.
      sql/sql_parse.h:
        Remove declaration of a function that is now static.
      sql/sql_partition.cc:
        Remove an unnecessary call to close_thread_tables().
      sql/sql_plugin.cc:
        open_and_lock_tables() will clean up
        after itself after a failure.
        Move close_thread_tables() above
        end: label, and replace with close_mysql_tables(),
        which will also release the metadata lock
        on mysql.plugin.
      sql/sql_prepare.cc:
        Now that we no longer release locks in close_thread_tables()
        statement prepare code has become more straightforward.
        Remove the now redundant check for thd->killed() (used
        only by the backup project) from Execute_server_runnable.
        Reorder code to take into account that now mysql_execute_command()
        performs lex->unit.cleanup() and close_thread_tables().
      sql/sql_priv.h:
        Add a new option to server options to interact
        between the slave SQL thread and execution
        framework (hack). @todo: use a virtual
        method of class THD instead.
      sql/sql_servers.cc:
        Due to Bug 25705 replication of 
        DROP/CREATE/ALTER SERVER is broken.
        Make sure at least we do not attempt to 
        replicate these statements using RBR,
        as this violates the assert in close_mysql_tables().
      sql/sql_table.cc:
        Do not release metadata locks in mysql_rm_table_part2,
        this is done by the caller.
        Do not call close_thread_tables() in mysql_create_table(),
        this is done by the caller. 
        Fix a bug in DROP TABLE under LOCK TABLES when,
        upon error in wait_while_table_is_used() we would mistakenly
        release the metadata lock on a non-dropped table.
        Explicitly release metadata locks when doing an implicit
        commit.
      sql/sql_trigger.cc:
        Now that we delete lex->sphead in lex_end(),
        zero the trigger's sphead in lex after loading
        the trigger, to avoid double deletion.
      sql/sql_udf.cc:
        Use close_mysql_tables() instead of close_thread_tables().
      sql/sys_vars.cc:
        Remove code added in scope of WL#4284 which would
        break when we perform set @@session.autocommit along
        with setting other variables and using tables or functions.
        A test case added to variables.test.
      sql/transaction.cc:
        Add asserts.
      sql/tztime.cc:
        Use close_mysql_tables() rather than close_thread_tables().
      36290c09
  22. 23 Jul, 2010 2 commits
  23. 20 Jul, 2010 1 commit
    • Davi Arnaut's avatar
      Bug#45288: pb2 returns a lot of compilation warnings on linux · 9a5fa17f
      Davi Arnaut authored
      Fix warnings flagged by the new warning option -Wunused-but-set-variable
      that was added to GCC 4.6 and that is enabled by -Wunused and -Wall. The
      option causes a warning whenever a local variable is assigned to but is
      later unused. It also warns about meaningless pointer dereferences.
      
      client/mysql.cc:
        Meaningless pointer dereferences.
      client/mysql_upgrade.c:
        Check whether reading from the file succeeded.
      extra/comp_err.c:
        Unused.
      extra/yassl/src/yassl_imp.cpp:
        Skip instead of reading data that is discarded.
      include/my_pthread.h:
        Variable is only used in debug builds.
      include/mysys_err.h:
        Add new error messages.
      mysys/errors.c:
        Add new error message for permission related functions.
      mysys/mf_iocache.c:
        Variable is only checked under THREAD.
      mysys/my_copy.c:
        Raise a error if chmod or chown fails.
      mysys/my_redel.c:
        Raise a error if chmod or chown fails.
      regex/engine.c:
        Use a equivalent variable for the assert.
      server-tools/instance-manager/instance_options.cc:
        Unused.
      sql/field.cc:
        Unused.
      sql/item.cc:
        Unused.
      sql/log.cc:
        Do not ignore the return value of freopen: only set buffer if
        reopening succeeds.
        
        Adjust doxygen comment to the right function.
        
        Pass message lenght to log function.
      sql/mysqld.cc:
        Do not ignore the return value of freopen: only set buffer if
        reopening succeeds.
      sql/partition_info.cc:
        Unused.
      sql/slave.cc:
        No need to set pointer to the address of '\0'.
      sql/spatial.cc:
        Unused. Left for historical purposes.
      sql/sql_acl.cc:
        Unused.
      sql/sql_base.cc:
        Pointers are always set to the same variables.
      sql/sql_parse.cc:
        End statement if reading fails.
        
        Store the buffer after it has actually been updated.
      sql/sql_repl.cc:
        No need to set pointer to the address of '\0'.
      sql/sql_show.cc:
        Put variable under the same ifdef block.
      sql/udf_example.c:
        Set null pointer flag appropriately.
      storage/csv/ha_tina.cc:
        Meaningless dereferences.
      storage/example/ha_example.cc:
        Return the error since it's available.
      storage/myisam/mi_locking.c:
        Remove unused and dead code.
      9a5fa17f
  24. 08 Jul, 2010 1 commit
    • Davi Arnaut's avatar
      Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled · f56dd32b
      Davi Arnaut authored
      Essentially, the problem is that safemalloc is excruciatingly
      slow as it checks all allocated blocks for overrun at each
      memory management primitive, yielding a almost exponential
      slowdown for the memory management functions (malloc, realloc,
      free). The overrun check basically consists of verifying some
      bytes of a block for certain magic keys, which catches some
      simple forms of overrun. Another minor problem is violation
      of aliasing rules and that its own internal list of blocks
      is prone to corruption.
      
      Another issue with safemalloc is rather the maintenance cost
      as the tool has a significant impact on the server code.
      Given the magnitude of memory debuggers available nowadays,
      especially those that are provided with the platform malloc
      implementation, maintenance of a in-house and largely obsolete
      memory debugger becomes a burden that is not worth the effort
      due to its slowness and lack of support for detecting more
      common forms of heap corruption.
      
      Since there are third-party tools that can provide the same
      functionality at a lower or comparable performance cost, the
      solution is to simply remove safemalloc. Third-party tools
      can provide the same functionality at a lower or comparable
      performance cost. 
      
      The removal of safemalloc also allows a simplification of the
      malloc wrappers, removing quite a bit of kludge: redefinition
      of my_malloc, my_free and the removal of the unused second
      argument of my_free. Since free() always check whether the
      supplied pointer is null, redudant checks are also removed.
      
      Also, this patch adds unit testing for my_malloc and moves
      my_realloc implementation into the same file as the other
      memory allocation primitives.
      
      client/mysqldump.c:
        Pass my_free directly as its signature is compatible with the
        callback type -- which wasn't the case for free_table_ent.
      f56dd32b
  25. 07 Jul, 2010 1 commit
    • Jon Olav Hauglid's avatar
      Bug #37521 Row inserted through view not always visible in base · 7f0f32d6
      Jon Olav Hauglid authored
                 table immediately after
      
      The problem was that rows inserted in a table by one connection was
      not immediately visible if another connection queried the table,
      even if the insert had committed.
      
      The reason for the problem was that the server sent a status reply
      to the client before it actually did the commit. Therefore it was
      possible to get an OK from the server before the changes were made
      permanent and visible to other connections.
      
      This patch fixes the problem by not sending status messages to the
      server until any changes made have been committed. No test case added
      as reproducing the error requires very specific timing betweeen the
      server and two or more clients.
      
      This patch also fixes the following (duplicate) bugs:
      Bug #29334 pseudo-finished SHOW GLOBAL STATUS
      Bug #36618 myisam insert not immediately visible to select from another client
      Bug #45864 insert on one connection, immediate query on another produces no result
      Bug #51329 Inserts from one connection not immediately visible in second
                 connection
      Bug #41516 Assertion fails when error returned from
                 handler::external_lock(thd, F_UNLCK)
      7f0f32d6
  26. 04 Jul, 2010 1 commit
    • unknown's avatar
      The following statements support the CURRENT_USER() where a user is needed. · 1a17d7e8
      unknown authored
      DROP USER 
      RENAME USER CURRENT_USER() ...
      GRANT ... TO CURRENT_USER()
      REVOKE ... FROM CURRENT_USER()
      ALTER DEFINER = CURRENT_USER() EVENTbut, When these statements are binlogged, CURRENT_USER() just is binlogged
      as 'CURRENT_USER()', it is not expanded to the real user name. When slave 
      executes the log event, 'CURRENT_USER()' is expand to the user of slave 
      SQL thread, but SQL thread's user name always NULL. This breaks the replication.
      
      After this patch, session's user will be written into query log events 
      if these statements call CURREN_USER() or 'ALTER EVENT' does not assign a definer.
      
      
      mysql-test/include/diff_tables.inc:
        Expend its abilities.
        Now it can diff not only in sessions of 'master' and 'slave', but 
        other sessions as well.
      sql/log_event.cc:
        session's user will be written into Query_log_event, if is_current_user_used() is TRUE.
        On slave SQL thread, Only thd->invoker is written into Query_log_event,
        if it exists.
      sql/sql_acl.cc:
        On slave SQL thread, grantor should copy from thd->invoker, if it exists
      sql/sql_class.h:
        On slave SQL thread, thd->invoker is used to store the applying event's
        invoker.
      1a17d7e8
  27. 01 Jul, 2010 1 commit
    • Jon Olav Hauglid's avatar
      A 5.5 version of the fix for Bug #54360 "Deadlock DROP/ALTER/CREATE · 9ff272fb
      Jon Olav Hauglid authored
      DATABASE with open HANDLER"
      
      Remove LOCK_create_db, database name locks, and use metadata locks instead.
      This exposes CREATE/DROP/ALTER DATABASE statements to the graph-based
      deadlock detector in MDL, and paves the way for a safe, deadlock-free
      implementation of RENAME DATABASE.
      
      Database DDL statements will now take exclusive metadata locks on
      the database name, while table/view/routine DDL statements take
      intention exclusive locks on the database name. This prevents race
      conditions between database DDL and table/view/routine DDL.
      (e.g. DROP DATABASE with concurrent CREATE/ALTER/DROP TABLE)
      
      By adding database name locks, this patch implements
      WL#4450 "DDL locking: CREATE/DROP DATABASE must use database locks" and
      WL#4985 "DDL locking: namespace/hierarchical locks".
      
      The patch also changes code to use init_one_table() where appropriate.
      The new lock_table_names() function requires TABLE_LIST::db_length to
      be set correctly, and this is taken care of by init_one_table().
      
      This patch also adds a simple template to help work with 
      the mysys HASH data structure.
      
      Most of the patch was written by Konstantin Osipov.
      9ff272fb
  28. 30 Jun, 2010 1 commit
    • Alfranio Correia's avatar
      BUG#53259 Unsafe statement binlogged in statement format w/MyIsam temp tables · c9221a2a
      Alfranio Correia authored
      BUG#54872 MBR: replication failure caused by using tmp table inside transaction 
            
      Changed criteria to classify a statement as unsafe in order to reduce the
      number of spurious warnings. So a statement is classified as unsafe when
      there is on-going transaction at any point of the execution if:
      
      1. The mixed statement is about to update a transactional table and
      a non-transactional table.
      
      2. The mixed statement is about to update a temporary transactional
      table and a non-transactional table.
            
      3. The mixed statement is about to update a transactional table and
      read from a non-transactional table.
      
      4. The mixed statement is about to update a temporary transactional
      table and read from a non-transactional table.
      
      5. The mixed statement is about to update a non-transactional table
      and read from a transactional table when the isolation level is
      lower than repeatable read.
      
      After updating a transactional table if:
      
      6. The mixed statement is about to update a non-transactional table
      and read from a temporary transactional table.
       
      7. The mixed statement is about to update a non-transactional table
       and read from a temporary transactional table.
      
      8. The mixed statement is about to update a non-transactionala table
         and read from a temporary non-transactional table.
           
      9. The mixed statement is about to update a temporary non-transactional
      table and update a non-transactional table.
           
      10. The mixed statement is about to update a temporary non-transactional
      table and read from a non-transactional table.
           
      11. A statement is about to update a non-transactional table and the
      option variables.binlog_direct_non_trans_update is OFF.
      
      The reason for this is that locks acquired may not protected a concurrent
      transaction of interfering in the current execution and by consequence in
      the result. So the patch reduced the number of spurious unsafe warnings.
      
      Besides we fixed a regression caused by BUG#51894, which makes temporary
      tables to go into the trx-cache if there is an on-going transaction. In
      MIXED mode, the patch for BUG#51894 ignores that the trx-cache may have
      updates to temporary non-transactional tables that must be written to the
      binary log while rolling back the transaction.
            
      So we fix this problem by writing the content of the trx-cache to the
      binary log while rolling back a transaction if a non-transactional
      temporary table was updated and the binary logging format is MIXED.
      c9221a2a
  29. 29 Jun, 2010 1 commit
    • Dmitry Shulga's avatar
      Fixed bug #51855. Race condition in XA START. If several threads · 7ccbf9b8
      Dmitry Shulga authored
      concurrently execute the statement XA START 'x', then mysqld
      server could crash.
      
      sql/sql_class.cc:
        xid_cache_insert: added checking for element in cache before
        insert it, return TRUE if such element already exists.
      sql/sql_parse.cc:
        mysql_execute_command modified:
        * sequence of calls to xid_cache_search(..)/xid_cache_insert(...)
        replaced by call to xid_cache_insert(...) in alternative
        'case SQLCOM_XA_START:'
        * added comment to alternative 'case SQLCOM_XA_COMMIT:'.
      7ccbf9b8
  30. 28 Jun, 2010 1 commit
  31. 27 Jun, 2010 1 commit
    • unknown's avatar
      The following statements support the CURRENT_USER() where a user is needed. · 451cea3f
      unknown authored
      DROP USER 
      RENAME USER CURRENT_USER() ...
      GRANT ... TO CURRENT_USER()
      REVOKE ... FROM CURRENT_USER()
      ALTER DEFINER = CURRENT_USER() EVENTbut, When these statements are binlogged, CURRENT_USER() just is binlogged
      as 'CURRENT_USER()', it is not expanded to the real user name. When slave 
      executes the log event, 'CURRENT_USER()' is expand to the user of slave 
      SQL thread, but SQL thread's user name always NULL. This breaks the replication.
      
      After this patch, session's user will be written into query log events 
      if these statements call CURREN_USER() or 'ALTER EVENT' does not assign a definer.
      
      
      mysql-test/include/diff_tables.inc:
        Expend its abilities.
        Now it can diff not only in sessions of 'master' and 'slave', but 
        other sessions as well.
      mysql-test/include/rpl_diff_tables.inc:
        Diff the same table between master and slaves.
      sql/log_event.cc:
        session's user will be written into Query_log_event, if is_current_user_used() is TRUE.
        On slave SQL thread, Only thd->variables.current_user is written into Query_log_event,
        if it exists.
      sql/sql_acl.cc:
        On slave SQL thread, grantor should copy from thd->variables.current_user, if it exists
      sql/sql_class.h:
        On slave SQL thread, thd->variables.current_user is used to store the applying event's
        invoker.
      451cea3f
  32. 23 Jun, 2010 1 commit
    • sunanda's avatar
      Backport into build-201006221614-5.1.46sp1 · c658c3ed
      sunanda authored
      > ------------------------------------------------------------
      > revno: 3367 [merge]
      > revision-id: joro@sun.com-20100504140328-srxf3c088j2twnq6
      > parent: kristofer.pettersson@sun.com-20100503172109-f9hracq5pqsaomb1
      > parent: joro@sun.com-20100503151651-nakknn8amrapmdp7
      > committer: Georgi Kodinov <joro@sun.com>
      > branch nick: B53371-5.1-bugteam
      > timestamp: Tue 2010-05-04 17:03:28 +0300
      > message:
      >   Bug #53371: COM_FIELD_LIST can be abused to bypass table level grants.
      >   
      >   This is the 5.1 merge and extension of the fix.
      >   The server was happily accepting paths in table name in all places a table
      >   name is accepted (e.g. a SELECT). This allowed all users that have some 
      >   privilege over some database to read all tables in all databases in all
      >   mysql server instances that the server file system has access to.
      >   Fixed by :
      >   1. making sure no path elements are allowed in quoted table name when
      >   constructing the path (note that the path symbols are still valid in table names
      >   when they're properly escaped by the server).
      >   2. checking the #mysql50# prefixed names the same way they're checked for
      >   path elements in mysql-5.0.
      > ------------------------------------------------------------
      > Use --include-merges or -n0 to see merged revisions.
      c658c3ed
  33. 22 Jun, 2010 1 commit
    • MySQL Build Team's avatar
      Backport into build-201006221614-5.1.46sp1 · 01490413
      MySQL Build Team authored
      > ------------------------------------------------------------
      > revno: 1810.3987.13
      > revision-id: ramil@mysql.com-20100429044232-f0pkyx8fnpszf142
      > parent: alexey.kopytov@sun.com-20100426200600-op06qy98llzpzgl1
      > committer: Ramil Kalimullin <ramil@mysql.com>
      > branch nick: b53237-5.0-bugteam
      > timestamp: Thu 2010-04-29 08:42:32 +0400
      > message:
      >   Fix for bug #53237: mysql_list_fields/COM_FIELD_LIST stack smashing
      >   
      >   Problem: "COM_FIELD_LIST is an old command of the MySQL server, before there was real move to only
      >   SQL. Seems that the data sent to COM_FIELD_LIST( mysql_list_fields() function) is not
      >   checked for sanity. By sending long data for the table a buffer is overflown, which can
      >   be used deliberately to include code that harms".
      >   
      >   Fix: check incoming data length.
      
      The patch did not apply cleanly:
      - Line numbers are completely off, roughly it is 2030 -> 1313
      - What is called "pend" in the patch, is "arg_end" in the source.
      01490413
  34. 10 Jun, 2010 1 commit
    • Davi Arnaut's avatar
      Bug#42733: Type-punning warnings when compiling MySQL -- · 0f9ddfa9
      Davi Arnaut authored
                  strict aliasing violations.
      
      One somewhat major source of strict-aliasing violations and
      related warnings is the SQL_LIST structure. For example,
      consider its member function `link_in_list` which takes
      a pointer to pointer of type T (any type) as a pointer to
      pointer to unsigned char. Dereferencing this pointer, which
      is done to reset the next field, violates strict-aliasing
      rules and might cause problems for surrounding code that
      uses the next field of the object being added to the list.
      
      The solution is to use templates to parametrize the SQL_LIST
      structure in order to deference the pointers with compatible
      types. As a side bonus, it becomes possible to remove quite
      a few casts related to acessing data members of SQL_LIST.
      
      sql/handler.h:
        Use the appropriate template type argument.
      sql/item.cc:
        Remove now-unnecessary cast.
      sql/item_subselect.cc:
        Remove now-unnecessary casts.
      sql/item_sum.cc:
        Use the appropriate template type argument.
        Remove now-unnecessary cast.
      sql/mysql_priv.h:
        Move SQL_LIST structure to sql_list.h
        Use the appropriate template type argument.
      sql/sp.cc:
        Remove now-unnecessary casts.
      sql/sql_delete.cc:
        Use the appropriate template type argument.
        Remove now-unnecessary casts.
      sql/sql_derived.cc:
        Remove now-unnecessary casts.
      sql/sql_lex.cc:
        Remove now-unnecessary casts.
      sql/sql_lex.h:
        SQL_LIST now takes a template type argument which must
        match the type of the elements of the list. Use forward
        declaration when the type is not available, it is used
        in pointers anyway.
      sql/sql_list.h:
        Rename SQL_LIST to SQL_I_List. The template parameter is
        the type of object that is stored in the list.
      sql/sql_olap.cc:
        Remove now-unnecessary casts.
      sql/sql_parse.cc:
        Remove now-unnecessary casts.
      sql/sql_prepare.cc:
        Remove now-unnecessary casts.
      sql/sql_select.cc:
        Remove now-unnecessary casts.
      sql/sql_show.cc:
        Remove now-unnecessary casts.
      sql/sql_table.cc:
        Remove now-unnecessary casts.
      sql/sql_trigger.cc:
        Remove now-unnecessary casts.
      sql/sql_union.cc:
        Remove now-unnecessary casts.
      sql/sql_update.cc:
        Remove now-unnecessary casts.
      sql/sql_view.cc:
        Remove now-unnecessary casts.
      sql/sql_yacc.yy:
        Remove now-unnecessary casts.
      storage/myisammrg/ha_myisammrg.cc:
        Remove now-unnecessary casts.
      0f9ddfa9