1. 16 May, 2007 3 commits
    • kostja@vajra.(none)'s avatar
      Merge vajra.(none):/opt/local/work/mysql-5.0-21483 · e1218d0e
      kostja@vajra.(none) authored
      into  vajra.(none):/opt/local/work/mysql-5.1-21483
      e1218d0e
    • kostja@vajra.(none)'s avatar
      Merge bk-internal.mysql.com:/home/bk/mysql-5.0-runtime · f10effe4
      kostja@vajra.(none) authored
      into  vajra.(none):/opt/local/work/mysql-5.0-21483
      f10effe4
    • kostja@vajra.(none)'s avatar
      A fix and a test case for · 747842e1
      kostja@vajra.(none) authored
      Bug#21483 "Server abort or deadlock on INSERT DELAYED with another
      implicit insert"
      Also fixes and adds test cases for bugs:
      20497 "Trigger with INSERT DELAYED causes Error 1165"
      21714 "Wrong NEW.value and server abort on INSERT DELAYED to a
      table with a trigger".
      Post-review fixes.
      
      Problem:
      In MySQL INSERT DELAYED is a way to pipe all inserts into a
      given table through a dedicated thread. This is necessary for
      simplistic storage engines like MyISAM, which do not have internal
      concurrency control or threading and thus can not
      achieve efficient INSERT throughput without support from SQL layer.
      DELAYED INSERT works as follows:
      For every distinct table, which can accept DELAYED inserts and has
      pending data to insert, a dedicated thread is created to write data
      to disk. All user connection threads that attempt to
      delayed-insert into this table interact with the dedicated thread in
      producer/consumer fashion: all records to-be inserted are pushed
      into a queue of the dedicated thread, which fetches the records and 
      writes them.
      In this design, client connection threads never open or lock
      the delayed insert table.
      This functionality was introduced in version 3.23 and does not take 
      into account existence of triggers, views, or pre-locking.
      E.g. if INSERT DELAYED is called from a stored function, which,
      in turn, is called from another stored function that uses the delayed
      table, a deadlock can occur, because delayed locking by-passes
      pre-locking. Besides:
       * the delayed thread works directly with the subject table through
         the storage engine API and does not invoke triggers
       * even if it was patched to invoke triggers, if triggers,
         in turn, used other tables, the delayed thread would
         have to open and lock involved tables (use pre-locking).
       * even if it was patched to use pre-locking, without deadlock
         detection the delayed thread could easily lock out user 
         connection threads in case when the same table is used both
         in a trigger and on the right side of the insert query: 
         the delayed thread would not release locks until all inserts 
         are complete, and user connection can not complete inserts 
         without having locks on the tables used on the right side of the
         query.
      
      Solution:
      
      These considerations suggest two general alternatives for the
      future of INSERT DELAYED:
       * it is considered a full-fledged alternative to normal INSERT
       * it is regarded as an optimisation that is only relevant 
         for simplistic engines.
      Since we missed our chance to provide complete support of new
      features when 5.0 was in development, the first alternative
      currently renders infeasible.
      However, even the second alternative, which is to detect
      new features and convert DELAYED insert into a normal insert, 
      is not easy to implement.
      The catch-22 is that we don't know if the subject table has triggers
      or is a view before we open it, and we only open it in the
      delayed thread. We don't know if the query involves pre-locking
      until we have opened all tables, and we always first create
      the delayed thread, and only then open the remaining tables.
      This patch detects the problematic scenarios and converts
      DELAYED INSERT to a normal INSERT using the following approach:
       * if the statement is executed under pre-locking (e.g. from
         within a stored function or trigger) or the right
         side may require pre-locking, we detect the situation
         before creating a delayed insert thread and convert the statement
         to a conventional INSERT.
        * if the subject table is a view or has triggers, we shutdown
         the delayed thread and convert the statement to a conventional
         INSERT.
      747842e1
  2. 15 May, 2007 6 commits
  3. 14 May, 2007 9 commits
  4. 12 May, 2007 6 commits
  5. 11 May, 2007 16 commits
    • evgen@moonbone.local's avatar
      Merge epotemkin@bk-internal.mysql.com:/home/bk/mysql-5.0-opt · e3bd20b6
      evgen@moonbone.local authored
      into  moonbone.local:/mnt/gentoo64/work/27878-bug-5.0-opt-mysql
      e3bd20b6
    • evgen@moonbone.local's avatar
      grant.result, grant.test: · 6c8f5476
      evgen@moonbone.local authored
        Corrected test case for the bug#27878.
      6c8f5476
    • dlenev@mockturtle.local's avatar
      Merge mockturtle.local:/home/dlenev/src/mysql-5.0-cts-3 · 343eef67
      dlenev@mockturtle.local authored
      into  mockturtle.local:/home/dlenev/src/mysql-5.1-cts-3
      343eef67
    • dlenev@mockturtle.local's avatar
    • holyfoot/hf@mysql.com/hfmain.(none)'s avatar
      merging fix · 19b24f29
      holyfoot/hf@mysql.com/hfmain.(none) authored
      19b24f29
    • holyfoot/hf@hfmain.(none)'s avatar
      Merge mysql.com:/home/hf/work/27957/my50-27957 · 350c35a0
      holyfoot/hf@hfmain.(none) authored
      into  mysql.com:/home/hf/work/27957/my51-27957
      350c35a0
    • holyfoot/hf@mysql.com/hfmain.(none)'s avatar
      Merge bk@192.168.21.1:mysql-5.0-opt · 6fe0f52d
      holyfoot/hf@mysql.com/hfmain.(none) authored
      into  mysql.com:/home/hf/work/27957/my50-27957
      6fe0f52d
    • evgen@moonbone.local's avatar
      Merge epotemkin@bk-internal.mysql.com:/home/bk/mysql-5.0-opt · 9a427d8d
      evgen@moonbone.local authored
      into  moonbone.local:/mnt/gentoo64/work/27878-bug-5.0-opt-mysql
      9a427d8d
    • evgen@moonbone.local's avatar
      Bug#27878: Unchecked privileges on a view referring to a table from another · 34f47812
      evgen@moonbone.local authored
      database.
      
      If a user has a right to update anything in the current database then the 
      access was granted and further checks of access rights for underlying tables
      wasn't done correctly. The check is done before a view is opened and thus no
      check of access rights for underlying tables can be carried out.
      This allows a user to update through a view a table from another database for
      which he hasn't enough rights.
      
      Now the mysql_update() and the mysql_test_update() functions are forces
      re-checking of access rights after a view is opened.
      34f47812
    • holyfoot/hf@mysql.com/hfmain.(none)'s avatar
      merging fixes · ba3d60b1
      holyfoot/hf@mysql.com/hfmain.(none) authored
      ba3d60b1
    • dlenev@mockturtle.local's avatar
      Merge mockturtle.local:/home/dlenev/src/mysql-5.0-cts-3 · 86e91a0a
      dlenev@mockturtle.local authored
      into  mockturtle.local:/home/dlenev/src/mysql-5.1-cts-3
      86e91a0a
    • dlenev@mockturtle.local's avatar
      Merge bk-internal.mysql.com:/home/bk/mysql-5.0-runtime · d5dbdd98
      dlenev@mockturtle.local authored
      into  mockturtle.local:/home/dlenev/src/mysql-5.0-cts-3
      d5dbdd98
    • dlenev@mockturtle.local's avatar
      Merge bk-internal.mysql.com:/home/bk/mysql-5.1-runtime · 3b195fd6
      dlenev@mockturtle.local authored
      into  mockturtle.local:/home/dlenev/src/mysql-5.1-cts-3
      3b195fd6
    • dlenev@mockturtle.local's avatar
      Fix for: · 4cafc8ee
      dlenev@mockturtle.local authored
        Bug #20662 "Infinite loop in CREATE TABLE IF NOT EXISTS ... SELECT
                    with locked tables"
        Bug #20903 "Crash when using CREATE TABLE .. SELECT and triggers"
        Bug #24738 "CREATE TABLE ... SELECT is not isolated properly"
        Bug #24508 "Inconsistent results of CREATE TABLE ... SELECT when
                    temporary table exists"
      
      Deadlock occured when one tried to execute CREATE TABLE IF NOT
      EXISTS ... SELECT statement under LOCK TABLES which held
      read lock on target table.
      Attempt to execute the same statement for already existing
      target table with triggers caused server crashes.
      Also concurrent execution of CREATE TABLE ... SELECT statement
      and other statements involving target table suffered from
      various races (some of which might've led to deadlocks).
      Finally, attempt to execute CREATE TABLE ... SELECT in case
      when a temporary table with same name was already present
      led to the insertion of data into this temporary table and
      creation of empty non-temporary table.
       
      All above problems stemmed from the old implementation of CREATE
      TABLE ... SELECT in which we created, opened and locked target
      table without any special protection in a separate step and not
      with the rest of tables used by this statement.
      This underminded deadlock-avoidance approach used in server
      and created window for races. It also excluded target table
      from prelocking causing problems with trigger execution.
      
      The patch solves these problems by implementing new approach to
      handling of CREATE TABLE ... SELECT for base tables.
      We try to open and lock table to be created at the same time as
      the rest of tables used by this statement. If such table does not
      exist at this moment we create and place in the table cache special
      placeholder for it which prevents its creation or any other usage
      by other threads.
      We still use old approach for creation of temporary tables.
      
      Note that we have separate fix for 5.0 since there we use slightly
      different less intrusive approach.
      4cafc8ee
    • dlenev@mockturtle.local's avatar
      Fix for: · 8b93e52e
      dlenev@mockturtle.local authored
        Bug #20662 "Infinite loop in CREATE TABLE IF NOT EXISTS ... SELECT
                    with locked tables"
        Bug #20903 "Crash when using CREATE TABLE .. SELECT and triggers"
        Bug #24738 "CREATE TABLE ... SELECT is not isolated properly"
        Bug #24508 "Inconsistent results of CREATE TABLE ... SELECT when
                    temporary table exists"
       
      Deadlock occured when one tried to execute CREATE TABLE IF NOT
      EXISTS ... SELECT statement under LOCK TABLES which held
      read lock on target table.
      Attempt to execute the same statement for already existing
      target table with triggers caused server crashes.
      Also concurrent execution of CREATE TABLE ... SELECT statement
      and other statements involving target table suffered from
      various races (some of which might've led to deadlocks).
      Finally, attempt to execute CREATE TABLE ... SELECT in case
      when a temporary table with same name was already present
      led to the insertion of data into this temporary table and
      creation of empty non-temporary table.
       
      All above problems stemmed from the old implementation of CREATE
      TABLE ... SELECT in which we created, opened and locked target
      table without any special protection in a separate step and not
      with the rest of tables used by this statement.
      This underminded deadlock-avoidance approach used in server
      and created window for races. It also excluded target table
      from prelocking causing problems with trigger execution.
        
      The patch solves these problems by implementing new approach to
      handling of CREATE TABLE ... SELECT for base tables.
      We try to open and lock table to be created at the same time as
      the rest of tables used by this statement. If such table does not
      exist at this moment we create and place in the table cache special
      placeholder for it which prevents its creation or any other usage
      by other threads.
      
      We still use old approach for creation of temporary tables.
      
      Also note that we decided to postpone introduction of some tests
      for concurrent behaviour of CREATE TABLE ... SELECT till 5.1.
      The main reason for this is absence in 5.0 ability to set @@debug
      variable at runtime, which can be circumvented only by using several
      test files with individual .opt files. Since the latter is likely
      to slowdown test-suite unnecessary we chose not to push this tests
      into 5.0, but run them manually for this version and later push
      their optimized version into 5.1
      8b93e52e
    • holyfoot/hf@hfmain.(none)'s avatar
      Merge mysql.com:/home/hf/work/27957/my50-27957 · 7b6a467c
      holyfoot/hf@hfmain.(none) authored
      into  mysql.com:/home/hf/work/27957/my51-27957
      7b6a467c