An error occurred fetching the project authors.
  1. 15 Dec, 2011 1 commit
  2. 18 Aug, 2011 1 commit
    • Sergey Vojtovich's avatar
      BUG#11763712 - 56458: KILLING A FLUSH TABLE FOR A MERGE/CHILD · ef84b24d
      Sergey Vojtovich authored
                            CRASHES SERVER
      
      Flushing of MERGE table or one of its child tables, which was
      locked by flushing thread using LOCK TABLES, might have caused
      crashes or assertion failures if the thread failed to reopen
      child or parent table.
      Particularly, this might have happened when another connection
      killed this FLUSH TABLE statement/connection.
      Also this problem might have occurred when we failed to reopen
      MERGE table or one of its children when executing DDL statement
      under LOCK TABLES.
      
      The problem was caused by the fact that reopen_tables() might
      have failed to reopen child table but still tried to reopen,
      reattach children for and re-lock its parent. Vice versa it
      might have failed to reopen parent but kept references from
      children to parent around. Since reopen_tables() closes table
      it has failed to reopen and therefore frees all associated
      memory such dangling references led to crashes when followed.
      
      This patch solves this problem by ensuring that we always close
      parent table and all its children if we fail to reopen this
      table or one of its children. Same happens if we fail to reattach
      children to parent.
      
      Affects 5.1 only.
      
      mysql-test/r/merge.result:
        A test case for BUG#11763712.
      mysql-test/t/merge.test:
        A test case for BUG#11763712.
      sql/sql_base.cc:
        When flushing tables under LOCK TABLES, all locked
        and flushed tables are released and then reopened.
        It may happen that we failed to reopen some tables,
        in this case we reopen as much tables as possible.
        
        If it was not possible to reopen MERGE child, MERGE
        parent is unusable and must be removed from thread
        open tables list.
        
        If it was not possible to reopen MERGE parent, all
        MERGE child table objects are unusable as well, at
        least because their locks are handled by MERGE parent.
        They must also be removed from thread open tables
        list.
        
        In other words if it was impossible to reopen any
        object of a MERGE table or reattach child tables,
        all objects of this MERGE table must be considered
        unusable and closed.
      ef84b24d
  3. 22 Jul, 2011 1 commit
    • Dmitry Lenev's avatar
      Fix for bug #11754210 - "45777: CHECK TABLE DOESN'T · f3c1f797
      Dmitry Lenev authored
      SHOW ALL PROBLEMS FOR MERGE TABLE COMPLIANCE IN 5.1".
      
      The problem was that CHECK/REPAIR TABLE for a MERGE table which
      had several children missing or in wrong engine reported only
      issue with the first such table in its result-set. While in 5.0
      this statement returned the whole list of problematic tables.
      
      Ability to report problems for all children was lost during
      significant refactorings of MERGE code which were done as part
      of work on 5.1 and 5.5 releases.
      
      This patch restores status quo ante refactorings by changing
      code in such a way that:
      1) Failure to open child table due to its absence during CHECK/
         REPAIR TABLE for a MERGE table is not reported immediately
         when its absence is discovered in open_tables(). Instead
         handling/error reporting in such a situation is postponed
         until the moment when children are attached.
      2) Code performing attaching of children no longer stops when
         it encounters first problem with one of the children during
         CHECK/REPAIR TABLE. Instead it continues iteration through
         the child list until all problems caused by child absence/
         wrong engine are reported.
      
      Note that even after this change problem with mismatch of
      child/parent definition won't be reported if there is also
      another child missing, but this is how it was in 5.0 as well.
      
      mysql-test/r/merge.result:
        Added test case for bug #11754210 - "45777: CHECK TABLE DOESN'T
        SHOW ALL PROBLEMS FOR MERGE TABLE COMPLIANCE IN 5.1".
        Adjusted results of existing tests to the fact that CHECK/REPAIR
        TABLE statements now try to report problems about missing table/
        wrong engine for all underlying tables, and to the fact that
        mismatch of parent/child definitions is always reported as an
        error and not a warning.
      mysql-test/t/merge.test:
        Added test case for bug #11754210 - "45777: CHECK TABLE DOESN'T
        SHOW ALL PROBLEMS FOR MERGE TABLE COMPLIANCE IN 5.1".
      sql/sql_base.cc:
        Changed code responsible for opening tables to ignore the fact
        that underlying tables of a MERGE table are missing, if this
        table is opened for CHECK/REPAIR TABLE.
        The absence of underlying tables in this case is now detected and
        appropriate error is reported at the point when child tables are
        attached. At this point we can produce full list of problematic
        child tables/errors to be returned as part of CHECK/REPAIR TABLE
        result-set.
      storage/myisammrg/ha_myisammrg.cc:
        Changed myisammrg_attach_children_callback() to handle new
        situation, when during CHECK/REPAIR TABLE we do not report 
        error about missing child immediately when this fact is 
        discovered during open_tables() but postpone error-reporting
        till the time when children are attached. 
        Also this callback is now responsible for pushing an error
        mentioning problematic child table to the list of errors to 
        be reported by CHECK/REPAIR TABLE statements.
        Finally, since now myrg_attach_children() no longer relies on
        return value from callback to determine the end of the children
        list, callback no longer needs to set my_errno value and can
        be simplified.
        
        Changed myrg_print_wrong_table() to always report a problem
        with child table as an error and not as a warning. This makes
        reporting for different types of issues with child tables
        more consistent and compatible with 5.0 behavior.
      storage/myisammrg/myrg_open.c:
        Changed code in myrg_attach_children() not to abort on the
        first problem with a child table when attaching children to
        parent MERGE table during CHECK/REPAIR TABLE statement 
        execution. This allows CHECK/REPAIR TABLE to report problems 
        about absence/wrong engine for all underlying tables as
        part of their result-set.
      f3c1f797
  4. 06 Oct, 2010 1 commit
    • Jon Olav Hauglid's avatar
      Bug #57002 Assert in upgrade_shared_lock_to_exclusive() · d12145e8
      Jon Olav Hauglid authored
                 for ALTER TABLE + MERGE tables
      
      The patch for Bug#56292 changed how metadata locks are taken for MERGE
      tables. After the patch, locking the MERGE table will also lock the
      children tables with the same metadata lock type. This means that 
      LOCK TABLES on a MERGE table also will implicitly do LOCK TABLES on
      the children tables.
      
      A consequence of this change, is that it is possible to do LOCK TABLES
      on a child table both explicitly and implicitly with the same statement
      and that these two locks can be of different strength. For example,
      LOCK TABLES child READ, merge WRITE.
      
      In LOCK TABLES mode, we are not allowed to take new locks and each
      statement must therefore try to find an existing TABLE instance with
      a suitable lock. The code that searched for a suitable TABLE instance,
      only considered table level locks. If a child table was locked twice,
      it was therefore possible for this code to find a TABLE instance with
      suitable table level locks but without suitable metadata lock.
      
      This problem caused the assert in upgrade_shared_lock_to_exclusive()
      to be triggered as it tried to upgrade a MDL_SHARED lock to
      EXCLUSIVE. The problem was a regression caused by the patch for
      Bug#56292.
      
      This patch fixes the problem by partially reverting the changes
      done by Bug#56292. Now, the children tables will only use the
      same metadata lock as the MERGE table for MDL_SHARED_NO_WRITE
      when not in locked tables mode. This means that LOCK TABLE
      on a MERGE table will not implicitly lock the children tables.
      This still fixes the original problem in Bug#56292 without
      causing a regression.
      
      Test case added to merge.test.
      d12145e8
  5. 22 Sep, 2010 1 commit
    • Jon Olav Hauglid's avatar
      Bug #56494 Segfault in upgrade_shared_lock_to_exclusive() for · 71db556a
      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.
      71db556a
  6. 16 Sep, 2010 1 commit
    • Dmitry Lenev's avatar
      Fix for merge.test failures in mysql-5.5-runtime · 2d557a86
      Dmitry Lenev authored
      tree for embedded server
      
      Test case for bug #56251 "Deadlock with INSERT
      DELAYED and MERGE tables" can't be run against
      embedded server. Embedded server converts all
      DELAYED INSERTs into ordinary INSERTs and this
      test can't work properly if such conversion
      happens.
      
      Moved this test from merge.test to delayed.test
      which is skipped if test suite is run with
      --embedded-server option.
      2d557a86
  7. 15 Sep, 2010 1 commit
    • Dmitry Lenev's avatar
      Fix for bug #56251 "Deadlock with INSERT DELAYED and MERGE · 9062d320
      Dmitry Lenev authored
      tables".
      
      Attempting to issue an INSERT DELAYED statement for a MERGE
      table might have caused a deadlock if it happened as part of
      a transaction or under LOCK TABLES, and there was a concurrent
      DDL or LOCK TABLES ... WRITE statement which tried to lock one
      of its underlying tables.
      
      The problem occurred when a delayed insert handler thread tried
      to open a MERGE table and discovered that to do this it had also
      to open all underlying tables and hence acquire metadata
      locks on them. Since metadata locks on the underlying tables were
      not pre-acquired by the connection thread executing INSERT DELAYED,
      attempts to do so might lead to waiting. In this case the
      connection thread had to wait for the delayed insert thread.
      If the thread which was preventing the lock on the underlying table
      from being acquired had to wait for the connection thread (due to
      this or other metadata locks), a deadlock occurred. 
      This deadlock was not detected by the MDL deadlock detector since 
      waiting for the handler thread by the connection thread is not
      represented in the wait-for graph.
      
      This patch solves the problem by ensuring that the delayed
      insert handler thread never tries to open underlying tables 
      of a MERGE table. Instead open_tables() is aborted right after
      the parent table is opened and a ER_DELAYED_NOT_SUPPORTED 
      error is emitted (which is passed to the connection thread and
      ultimately to the user).
      
      mysql-test/r/merge.result:
        Added test for bug #56251 "Deadlock with INSERT DELAYED and
        MERGE tables".
      mysql-test/t/merge.test:
        Added test for bug #56251 "Deadlock with INSERT DELAYED and
        MERGE tables".
      sql/sql_base.cc:
        Changed open_n_lock_single_table() to take prelocking strategy
        as an argument instead of always using DML_prelocking_strategy.
      sql/sql_base.h:
        Changed open_n_lock_single_table() to take prelocking strategy
        as an argument instead of always using DML_prelocking_strategy.
        Added a version of this function which is compatible with old
        signature.
      sql/sql_insert.cc:
        When opening MERGE table in delayed insert thread stop and emit
        ER_DELAYED_NOT_SUPPORTED right after opening main table and
        before opening underlying tables. This ensures that we won't
        try to acquire metadata lock on underlying tables which might
        lead to a deadlock.
        This is achieved by using special prelocking strategy which
        abort open_tables() process as soon as we discover that we
        have opened table with engine which doesn't support delayed
        inserts.
      9062d320
  8. 08 Sep, 2010 1 commit
    • Jon Olav Hauglid's avatar
      Bug #56292 Deadlock with ALTER TABLE and MERGE tables · 46ab297f
      Jon Olav Hauglid authored
      ALTER TABLE on a MERGE table could cause a deadlock with two
      other connections if we reached a situation where:
      
      1) A connection doing ALTER TABLE can't upgrade to MDL_EXCLUSIVE on the
      parent table, but holds TL_READ_NO_INSERT on the child tables.
      2) A connection doing DELETE on a child table can't get TL_WRITE on it
      since ALTER TABLE holds TL_READ_NO_INSERT.
      3) A connection doing SELECT on the parent table can't get TL_READ on 
      the child tables since TL_WRITE is ahead in the lock queue, but holds
      MDL_SHARED_READ on the parent table preventing ALTER TABLE from upgrading.
      
      For regular tables, this deadlock is avoided by having ALTER TABLE
      take a MDL_SHARED_NO_WRITE metadata lock on the table. This prevents
      DELETE from acquiring MDL_SHARED_WRITE on the table before ALTER TABLE
      tries to upgrade to MDL_EXCLUSIVE. In the example above, SELECT would
      therefore not be blocked by the pending DELETE as DELETE would not be
      able to enter TL_WRITE in the table lock queue.
      
      This patch fixes the problem for merge tables by using the same metadata
      lock type for child tables as for the parent table. The child tables will
      in this case therefore be locked with MDL_SHARED_NO_WRITE, preventing
      DELETE from acquiring a metadata lock and enter into the table lock queue.
      
      Change in behavior: By taking the same metadata lock for child tables
      as for the parent table, LOCK TABLE on the parent table will now also
      implicitly lock the child tables. Since LOCK TABLE on the parent table
      now takes more than one metadata lock, it is possible for LOCK TABLE
      ... WRITE on the parent table or child tables to give ER_LOCK_DEADLOCK
      error.
      
      Test case added to mdl_sync.test.
      Merge.test/.result has been updated to reflect the change to LOCK TABLE.
      46ab297f
  9. 18 Aug, 2010 1 commit
    • unknown's avatar
      WL#5370 Keep forward-compatibility when changing · f5fc4fd8
      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.
      f5fc4fd8
  10. 02 Jul, 2010 1 commit
    • Konstantin Osipov's avatar
      A fix and a test case for Bug#36171 "CREATE TEMPORARY TABLE and · 975515b5
      Konstantin Osipov authored
      MERGE engine".
      Backport the patch from 6.0 by Ingo Struewing:
      revid:ingo.struewing@sun.com-20091028183659-6kmv1k3gdq6cpg4d
      Bug#36171 - CREATE TEMPORARY TABLE and MERGE engine
      
      In former MySQL versions, up to 5.1.23/6.0.4 it was possible to create
      temporary MERGE tables with non-temporary MyISAM tables.
              
      This has been changed in the mentioned version due to Bug 19627
      (temporary merge table locking). MERGE children were locked through
      the parent table. If the parent was temporary, it was not locked and
      so the children were not locked either. Parallel use of the MyISAM
      tables corrupted them.
             
      Since 6.0.6 (WL 4144 - Lock MERGE engine children), the children are
      locked independently from the parent. Now it is possible to allow
      non-temporary children with a temporary parent. Even though the
      temporary MERGE table itself is not locked, each non-temporary
      MyISAM table is locked anyway.
              
      NOTE: Behavior change: In 5.1.23/6.0.4 we prohibited non-temporary
      children with a temporary MERGE table. Now we re-allow it.
      An important side-effect is that temporary tables, which overlay
      non-temporary MERGE children, overlay the children in the MERGE table.
      
      
      mysql-test/r/merge.result:
        Update results (Bug#36171).
      mysql-test/r/merge_mmap.result:
        Update results (Bug#36171).
      mysql-test/t/merge.test:
        Add tests for Bug#36171
      mysql-test/t/merge_mmap.test:
        Add tests for Bug#36171.
      storage/myisammrg/ha_myisammrg.cc:
        Changed constraint for temporary state of tables.
      975515b5
  11. 29 Jun, 2010 1 commit
    • Konstantin Osipov's avatar
      A fix for Bug#54811 "Assert in mysql_lock_have_duplicate()". · ef27df51
      Konstantin Osipov authored
      Remove mysql_lock_have_duplicate(), since now we always
      have TABLE_LIST objects for MyISAMMRG children
      in lex->query_tables and keep it till the end of the
      statement (sub-statement).
      
      
      mysql-test/r/merge.result:
        Update results (Bug#54811).
      mysql-test/t/merge-big.test:
        Update to new wait state.
      mysql-test/t/merge.test:
        Add a test case for Bug#54811.
      sql/lock.cc:
        Remove a function that is now unused.
      sql/lock.h:
        Remove a function that is now unused.
      sql/sql_base.cc:
        Don't try to search for duplicate table among THR_LOCK objects, TABLE_LIST list contains all used tables.
      ef27df51
  12. 25 Jun, 2010 1 commit
    • Alexander Nozdrin's avatar
      Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111 · 5879001b
      Alexander Nozdrin authored
         Bug#47633 - assert in ha_myisammrg::info during OPTIMIZE
       
         The server crashed on an attempt to optimize a MERGE table with
         non-existent child table.
       
         mysql_admin_table() relied on the table to be successfully open
         if a table object had been allocated.
       
         Changed code to check return value of the open function before
         calling a handler:: function on it.
      
      mysql-test/r/merge.result:
        Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111
            Bug#47633 - assert in ha_myisammrg::info during OPTIMIZE
            Updated result file.
      mysql-test/t/merge.test:
        Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111
            Bug#47633 - assert in ha_myisammrg::info during OPTIMIZE
            Changed tests to respect changed TEMPORARY MERGE locking (unrelated).
            Changed tests to respect changed CREATE TABLE ... LIKE (unrelated).
            Changed tests to respect that no new tables can be created
            under LOCK TABLE (unrelated).
            Added test for Bug#47633.
        Changed error numbers to symbolic names.
        Added test for child locking for ALTER under LOCK TABLE.
        
        Since Bug 36171 is not pushed yet, not the whole patch has been backported.
      mysys/my_delete.c:
        Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111
            Bug#47633 - assert in ha_myisammrg::info during OPTIMIZE
            Fixed error reporting.
            Fixed indentation.
      mysys/my_mmap.c:
        Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111
            Bug#47633 - assert in ha_myisammrg::info during OPTIMIZE
            Added DBUG.
      sql/item_func.cc:
        Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111
        Added Debug Sync point, required by merge_sync.test.
      sql/sql_table.cc:
        Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111
            Bug#47633 - assert in ha_myisammrg::info during OPTIMIZE
            Do not call handler:: functions if the table was not opened
            successfully.
        Added Debug Sync point, required by merge_sync.test.
      storage/myisam/mi_check.c:
        Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111
            Bug#47633 - assert in ha_myisammrg::info during OPTIMIZE
            Unmap memory before exchanging data files. Needed on Windows.
      storage/myisammrg/ha_myisammrg.cc:
        Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111
        Added Debug Sync point, required by merge_sync.test.
        
        merge_sync.test will be introduced by a patch for Bug 36171,
        which is not pushed yet.
      5879001b
  13. 11 Jun, 2010 1 commit
    • Jon Olav Hauglid's avatar
      This patch backports test coverage for: · e2be4d6d
      Jon Olav Hauglid authored
      Bug #22909 Using CREATE ... LIKE is possible to create
                 field with invalid default value
      Bug #35935 CREATE TABLE under LOCK TABLES ignores FLUSH
                 TABLES WITH READ LOCK
      Bug #37371 CREATE TABLE LIKE merge loses UNION parameter
      
      These bugs were originally fixed in the 6.1-fk tree and the fixes
      were backported as part of the fix for Bug #42546 "Backup: RESTORE
      fails, thinking it finds an existing table". This patch backports
      test coverage missing in the original backport. The patch contains
      no code changes.
      
      e2be4d6d
  14. 31 May, 2010 1 commit
    • Alexander Nozdrin's avatar
      Backport of · 4bab253d
      Alexander Nozdrin authored
        - revid:sp1r-svoj@mysql.com/june.mysql.com-20080324111246-00461
        - revid:sp1r-svoj@mysql.com/june.mysql.com-20080414125521-40866
      
        BUG#35274 - merge table doesn't need any base tables, gives
                    error 124 when key accessed
      
        SELECT queries that use index against a merge table with empty
        underlying tables list may return with error "Got error 124 from
        storage engine".
      
        The problem was that wrong error being returned.
      
      mysql-test/r/merge.result:
        Backport of
          - revid:sp1r-svoj@mysql.com/june.mysql.com-20080324111246-00461
          - revid:sp1r-svoj@mysql.com/june.mysql.com-20080414125521-40866
        
          A test case for BUG#35274.
        
          Modified a test case according to fix for BUG#35274. Key based
          reads are now allowed for merge tables with no underlying tables
          defined.
      mysql-test/t/merge.test:
        Backport of
          - revid:sp1r-svoj@mysql.com/june.mysql.com-20080324111246-00461
          - revid:sp1r-svoj@mysql.com/june.mysql.com-20080414125521-40866
        
          A test case for BUG#35274.
        
          Modified a test case according to fix for BUG#35274. Key based
          reads are now allowed for merge tables with no underlying tables
          defined.
      storage/myisammrg/myrg_queue.c:
        Backport of
          - revid:sp1r-svoj@mysql.com/june.mysql.com-20080324111246-00461
          - revid:sp1r-svoj@mysql.com/june.mysql.com-20080414125521-40866
        
          Return "end of file" error instead of "wrong index" error when
          we got a merge table with empty underlying tables list.
        
          In 5.1 we cannot rely on info->open_tables value when checking
          if a merge table has no underlying tables defined.
          Use info->tables instead.
      4bab253d
  15. 26 Apr, 2010 1 commit
    • Ingo Struewing's avatar
      Bug#46339 - crash on REPAIR TABLE merge table USE_FRM · a417f198
      Ingo Struewing authored
      REPAIR TABLE ... USE_FRM crashed debug servers.
      
      A wrong assert assumed that this operation would not be executed
      for MERGE tables.
      
      Removed the assert.
      
      
      mysql-test/r/merge.result:
        Bug#46339 - crash on REPAIR TABLE merge table USE_FRM
        Added test result.
      mysql-test/t/merge.test:
        Bug#46339 - crash on REPAIR TABLE merge table USE_FRM
        Added test.
      sql/sql_table.cc:
        Bug#46339 - crash on REPAIR TABLE merge table USE_FRM
        Removed false assert.
      a417f198
  16. 19 Mar, 2010 1 commit
    • Sergey Glukhov's avatar
      Bug#51494 crash with join, explain and 'sounds like' operator · 895cf531
      Sergey Glukhov authored
      The crash happens because of discrepancy between values of
      conts_tables and join->const_table_map(make_join_statisctics).
      Calculation of conts_tables used condition with
      HA_STATS_RECORDS_IS_EXACT flag check. Calculation of
      join->const_table_map does not use this flag check.
      In case of MERGE table without union with index
      the table does not become const table and
      thus join_read_const_table() is not called
      for the table. join->const_table_map supposes
      this table is const and later in make_join_select
      this table is used for making&calculation const
      condition. As table record buffer is not populated
      it leads to crash.
      The fix is adding a check if an engine supports
      HA_STATS_RECORDS_IS_EXACT flag before updating
      join->const_table_map.
      
      
      mysql-test/r/merge.result:
        test result
      mysql-test/t/merge.test:
        test case
      sql/sql_select.cc:
        adding a check if an engine supports
        HA_STATS_RECORDS_IS_EXACT flag before updating
        join->const_table_map.
      895cf531
  17. 03 Mar, 2010 1 commit
    • Sergey Vojtovich's avatar
      BUG#48265 - MRG_MYISAM problem (works in 5.0.85, does't · 05b1ed4c
      Sergey Vojtovich authored
                  work in 5.1.40)
      
      MERGE engine fails to open child table from a different
      database if child table/database name contains characters
      that are subject for table name to filename encoding
      (WL1324).
      
      Another problem is that MERGE engine didn't properly open
      child table from the same database if child table name
      contains characters like '/', '#'.
      
      The problem was that table name to file name encoding was
      applied inconsistently:
      * On CREATE: encode table name + database name if child
        table is in different database; do not encode table
        name if child table is in the same database;
      * No decoding on open.
      
      With this fix child table/database names are always
      encoded on CREATE and decoded on open. Compatibility
      with older tables preserved.
      
      Along with this patch comes fix for SHOW CREATE TABLE,
      which used to show child table/database path instead
      of child table/database names.
      
      mysql-test/r/merge.result:
        A test case for BUG#48265.
      mysql-test/std_data/bug48265.frm:
        MERGE table from 5.0 to test fix for BUG#48265 compatibility.
      mysql-test/t/merge.test:
        A test case for BUG#48265.
      storage/myisammrg/ha_myisammrg.cc:
        On CREATE always write child table/database name encoded
        by table name to filename encoding to dot-MRG file.
        
        On open decode child table/database name.
        Compatibilty with previous versions preserved.
        
        Fixed ::append_create_info() to return child
        table/database name instead of path.
      storage/myisammrg/myrg_open.c:
        Move if (has_path) branch from myrg_parent_open() to
        myisammrg_parent_open_callback. The callback function
        needs to know if child table was written along with
        database name to dot-MRG file. Needed for compatibility
        reasons.
      05b1ed4c
  18. 26 Feb, 2010 1 commit
    • Jon Olav Hauglid's avatar
      Bug #51240 ALTER TABLE of a locked MERGE table fails · 1dbdb338
      Jon Olav Hauglid authored
      The problem was that ALTER TABLE on a merge table which was locked 
      using LOCK TABLE ... WRITE, by mistake gave 
      ER_TABLE_NOT_LOCKED_FOR_WRITE.
      
      During opening of the table to be ALTERed, open_table() tried to
      get an upgradable metadata lock. In LOCK TABLEs mode, this lock
      must already exist (i.e. taken by LOCK TABLE) as new locks of this
      type cannot be acquired for fear of deadlock. So in LOCK TABLEs
      mode, open_table() tried to find an existing upgradable lock for
      the table to be altered.
      
      The problem was that open_table() also tried to find upgradable
      metadata locks for children of merge tables even if no such
      locks are needed to execute ALTER TABLE on merge tables.
      
      This patch fixes the problem by making sure that open tables code
      only searches for upgradable metadata locks for the merge table
      and not for the merge children tables. 
      
      The patch also fixes a related bug where an upgradable metadata
      lock was aquired outside of LOCK TABLEs mode even if the table in
      question was temporary. This bug meant that LOCK TABLES or DDL on
      temporary tables by mistake could be blocked/aborted by locks held
      on base tables with the same table name by other connections.
      
      Test cases added to merge.test and lock_multi.test.
      1dbdb338
  19. 15 Feb, 2010 1 commit
    • Konstantin Osipov's avatar
      A fix and a test case for Bug#47648 "main.merge fails sporadically". · 5f9ac42b
      Konstantin Osipov authored
      If a prepared statement used both a MyISAMMRG table and a stored 
      function or trigger, execution could fail with "No such table"
      error or crash. 
      The error would come from a failure of the MyISAMMRG engine
      to meet the expectations of the prelocking algorithm, 
      in particular maintain lex->query_tables_own_last pointer
      in sync with lex->query_tables_last pointer/the contents
      of lex->query_tables. When adding merge children, the merge
      engine would extend the table list. Then, when adding 
      prelocked tables, the prelocking algorithm would use a pointer
      to the last merge child to assign to lex->query_tables_own_last.
      Then, when merge children were removed at the end of
      open_tables(), lex->query_tables_own_last
      was not updated, and kept pointing
      to a removed merge child.
      
      The fix ensures that query_tables_own_last is always in
      sync with lex->query_tables_last.
      
      This is a regression introduced by WL#4144 and present only
      in next-4284 tree and 6.0.
      
      mysql-test/r/merge.result:
        Update results (Bug#47648).
      mysql-test/t/merge.test:
        Add a test case for Bug#47648.
        Update the result file to reflect a fix of another bug
        in MyISAMMRG code: not maintaining lex->query_tables_own_last
        allowed a stored function or trigger to modify a merge table
        which was already updated by the main statement.
        It is not allowed for other storage engines, and should
        not be allowed for MyISAMMRG.
      storage/myisammrg/ha_myisammrg.cc:
        When adding children to the list of tables to open,
        make sure that we properly set lex->query_tables_own_last.
        When removing the children, update lex->query_tables_own_last
        if necessary.
      5f9ac42b
  20. 11 Dec, 2009 1 commit
    • Konstantin Osipov's avatar
      Backport of: · e4127942
      Konstantin Osipov authored
      ------------------------------------------------------------
       2599.161.3 Ingo Struewing      2009-07-21
       Bug#20667 - Truncate table fails for a write locked table
      
       TRUNCATE TABLE was not allowed under LOCK TABLES.
      
       The patch removes this restriction. mysql_truncate()
       does now handle that case.
      
      
      mysql-test/r/merge.result:
        Bug#20667 - Truncate table fails for a write locked table
        Updated test result.
      mysql-test/r/truncate.result:
        Bug#20667 - Truncate table fails for a write locked table
        Updated test result.
      mysql-test/r/truncate_coverage.result:
        Bug#20667 - Truncate table fails for a write locked table
        New test result.
      mysql-test/t/merge.test:
        Bug#20667 - Truncate table fails for a write locked table
        Updated test case due to now working TRUNCATE under LOCK TABLES.
        Added some SELECTs to show that child tables are truncated.
      mysql-test/t/truncate.test:
        Bug#20667 - Truncate table fails for a write locked table
        Added test cases for TRUNCATE under LOCK TABLE.
      mysql-test/t/truncate_coverage.test:
        Bug#20667 - Truncate table fails for a write locked table
        New test file. Coverage tests for TRUNCATE.
      sql/sql_delete.cc:
        Bug#20667 - Truncate table fails for a write locked table
        Added branches for thd->locked_tables_mode.
      sql/sql_parse.cc:
        Bug#20667 - Truncate table fails for a write locked table
        Deleted rejection of TRUNCATE in case of LOCK TABLES.
      e4127942
  21. 10 Dec, 2009 1 commit
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.71.1 · 1f09da44
      Jon Olav Hauglid authored
      Bug#42546 Backup: RESTORE fails, thinking it finds an existing table
      
      The problem occured when a MDL locking conflict happened for a non-existent 
      table between a CREATE and a INSERT statement. The code for CREATE 
      interpreted this lock conflict to mean that the table existed, 
      which meant that the statement failed when it should not have.
      The problem could occur for CREATE TABLE, CREATE TABLE LIKE and
      ALTER TABLE RENAME.
      
      This patch fixes the problem for CREATE TABLE and CREATE TABLE LIKE.
      It is based on code backported from the mysql-6.1-fk tree written
      by Dmitry Lenev. CREATE now uses normal open_and_lock_tables() code 
      to acquire exclusive locks. This means that for the test case in the bug 
      description, CREATE will wait until INSERT completes so that it can 
      get the exclusive lock. This resolves the reported bug.
      
      The patch also prohibits CREATE TABLE and CREATE TABLE LIKE under 
      LOCK TABLES. Note that this is an incompatible change and must 
      be reflected in the documentation. Affected test cases have been
      updated.
      
      mdl_sync.test contains tests for CREATE TABLE and CREATE TABLE LIKE.
      
      Fixing the issue for ALTER TABLE RENAME is beyond the scope of this
      patch. ALTER TABLE cannot be prohibited from working under LOCK TABLES
      as this could seriously impact customers and a proper fix would require
      a significant rewrite.
      1f09da44
  22. 09 Dec, 2009 1 commit
    • unknown's avatar
      Backport of revno: 2617.68.36 · 3386aa46
      unknown authored
      ---------------------------------------------
      
      This is a patch for bug#47098 assert in MDL_context::destroy on
      HANDLER <damaged merge table> OPEN.
            
      The assert occurs in MDL_context::destroy when the connection is terminated,
      because all mdl_tickets have not been released.
      MERGE tables do not support being opened using the HANDLER ... OPEN command,
      and trying to do so will result in an error. In the event of an error, all
      tables that are opened, should be closed again. The fix for bug#45781 made
      sure that this also works for MERGE tables, which causes multiple tables to
      be opened.
      This fix extends the fix for bug#45781, by ensuring that also all locks are
      released, when MERGE tables are involved.
      
      mysql-test/r/merge.result:
        The result of the test.
      mysql-test/t/merge.test:
        Added a test based on the bug report, as well as a test of the more general
        scenario.
      sql/sql_handler.cc:
        Added code to release all the locks.
      3386aa46
  23. 02 Dec, 2009 1 commit
    • Konstantin Osipov's avatar
      Backport of: · 416f7c34
      Konstantin Osipov authored
      ----------------------------------------------------------
      revno: 2630.4.38
      committer: Konstantin Osipov <konstantin@mysql.com>
      branch nick: mysql-6.0-4144
      timestamp: Wed 2008-06-25 22:07:06 +0400
      message:
        WL#4144 - Lock MERGE engine children.
        Committing a version of the patch merged with WL#3726
        on behalf of Ingo.
      
        Step #1: Move locking from parent to children.
      
        MERGE children are now left in the query list of tables
        after inserted there in open_tables(). So they are locked
        by lock_tables() as all other tables are.
      
        The MERGE parent does not store locks any more. It appears
        in a MYSQL_LOCK with zero lock data. This is kind of a "dummy"
        lock.
      
        All other lock handling is also done directly on the children.
        To protect against parent or child modifications during LOCK
        TABLES, the children are detached after every statement and
        attached before every statement, even under LOCK TABLES.
      
        The children table list is removed from the query list of tables
        on every detach and on close of the parent.
      
        Step #2: Move MERGE specific functionality from SQL layer
        into table handler.
      
        Functionality moved from SQL layer (mainly sql_base.cc)
        to the table handler (ha_myisammrg.cc).
      
        Unnecessary code is removed from the SQL layer.
      
        Step #3: Moved all MERGE specific members from TABLE
        to ha_myisammrg.
      
        Moved members from TABLE to ha_myisammrg.
        Renamed some mebers.
        Fixed comments.
      
        Step #4: Valgrind and coverage testing
      
        Valgrind did not uncover new problems.
        Added purecov comments.
      
        Added a new test for DATA/INDEX DIRECTORY options.
        Changed handling of ::reset() for non-attached children.
        Fixed the merge-big test.
      
        Step #5: Fixed crashes detected during review
        Changed detection when to attach/detach.
        Added new tests.
      
      Backport also the fix for Bug#44040 "MySQL allows creating a 
      MERGE table upon VIEWs but crashes when using it"
      
      
      include/my_base.h:
        WL#4144 - Lock MERGE engine children
        Added HA_EXTRA_ADD_CHILDREN_LIST and HA_EXTRA_IS_ATTACHED_CHILDREN
        for MERGE table support
      mysql-test/r/merge.result:
        WL#4144 - Lock MERGE engine children
        Fixed test result.
      mysql-test/t/disabled.def:
        Enable merge.test, which now is working again (WL#4144).
      mysql-test/t/merge-big.test:
        Fix the messages for wait_condition (merge with WL#3726).
      mysql-test/t/merge.test:
        WL#4144 - Lock MERGE engine children
        Fixed one test to meet coding standards for tests
        (upper case keywords, engine names as in SHOW ENGINES).
        Fixed error codes.
        Added a test for DATA/INDEX DIRECTORY.
      mysys/thr_lock.c:
        WL#4144 - Lock MERGE engine children
        Added purecov comments.
      sql/ha_partition.cc:
        WL#4144 - Lock MERGE engine children
        Added MERGE specific extra operations to ha_partition::extra().
        Extended comments.
        Changed function comment to doxygen style.
        Fixed nomenclature: 'parameter' -> 'operation'.
      sql/mysql_priv.h:
        WL#4144 - Lock MERGE engine children
        Removed declarations for removed functions.
      sql/sql_base.cc:
        WL#4144 - Lock MERGE engine children
        Leave the children in the query list of tables after open_tables().
        Set proper back links (prev_global).
        Attach MERGE children before and detach them after every
        statement. Even under LOCK TABLES.
        Remove children from the query list when they are detached.
        Remove lock forwarding from children to parent.
        Moved MERGE specific functions to ha_myisammrg.cc.
        Added purecov comments.
        Backport the fix for Bug#44040 "MySQL allows creating a MERGE table upon VIEWs but crashes when using it"
      sql/sql_table.cc:
        WL#4144 - Lock MERGE engine children
        Changed detection of MERGE tables.
      sql/table.cc:
        WL#4144 - Lock MERGE engine children
        Moved is_children_attached() method from TABLE to ha_myisammrg.
      sql/table.h:
        WL#4144 - Lock MERGE engine children
        Moved all MERGE specific members from TABLE to ha_myisammrg.
      storage/myisammrg/ha_myisammrg.cc:
        WL#4144 - Lock MERGE engine children
        Set proper back links in the child list (prev_global).
        Added a function for removal of the child list from the query list.
        Remove children from the query list when the parent is closed.
        Make parent lock handling a dummy (zero locks).
        Moved MERGE specific functionality from SQL layer to here.
        Moved all MERGE specific members from TABLE to ha_myisammrg.
        Renamed children list pointers.
        Added initialization and free for the children list mem_root.
        Fixed comments.
        Added purecov comments.
      storage/myisammrg/ha_myisammrg.h:
        WL#4144 - Lock MERGE engine children
        Added method add_children_list().
        Moved all MERGE specific members from TABLE to ha_myisammrg.
        Renamed children list pointers.
        Added a mem_root for the children list.
      storage/myisammrg/myrg_extra.c:
        WL#4144 - Lock MERGE engine children
        Changed handling of ::reset() for non-attached children.
      416f7c34
  24. 13 Oct, 2009 1 commit
    • Konstantin Osipov's avatar
      Backport of: · 17515010
      Konstantin Osipov authored
      -----------------------------------------------------------
      revno: 2630.2.4
      committer: Konstantin Osipov <konstantin@mysql.com>
      branch nick: mysql-6.0-runtime
      timestamp: Fri 2008-05-23 02:42:32 +0400
      message:
        Bug#27430 "Crash in subquery code when in PS and table DDL changed after
        PREPARE"
        Add a test case for the situation with small TDC and many merge children.
      
      from 6.0-codebase.
      
      mysql-test/r/merge.result:
        Update results (Bug#27430)
      mysql-test/t/merge.test:
        Add test case (Bug#27430)
      17515010
  25. 22 Sep, 2009 1 commit
    • MySQL Build Team's avatar
      Backport into build-200909221805-5.1.37sp1 · af2dc73f
      MySQL Build Team authored
      > ------------------------------------------------------------
      > revno: 3068
      > revision-id: ramil@mysql.com-20090813194928-3djdqvpock0pxhgp
      > parent: li-bing.song@sun.com-20090813024857-1emgf5lhj0zikoj8
      > committer: Ramil Kalimullin <ramil@mysql.com>
      > branch nick: mysql-5.1-bugteam
      > timestamp: Fri 2009-08-14 00:49:28 +0500
      > message:
      >   Fix for bug #46614: Assertion in show_create_trigger() 
      >   on SHOW CREATE TRIGGER + MERGE table
      >   
      >   Problem: SHOW CREATE TRIGGER erroneously relies on fact
      >   that we have the only underlying table for a trigger
      >   (wrong for merge tables).
      >   
      >   Fix: remove erroneous assert().
      af2dc73f
  26. 13 Aug, 2009 1 commit
    • Ramil Kalimullin's avatar
      Fix for bug #46614: Assertion in show_create_trigger() · bf9e9f67
      Ramil Kalimullin authored
      on SHOW CREATE TRIGGER + MERGE table
      
      Problem: SHOW CREATE TRIGGER erroneously relies on fact
      that we have the only underlying table for a trigger
      (wrong for merge tables).
      
      Fix: remove erroneous assert().
      
      
      mysql-test/r/merge.result:
        Fix for bug #46614: Assertion in show_create_trigger() 
        on SHOW CREATE TRIGGER + MERGE table
          - test result.
      mysql-test/t/merge.test:
        Fix for bug #46614: Assertion in show_create_trigger() 
        on SHOW CREATE TRIGGER + MERGE table
          - test case.
      sql/sql_show.cc:
        Fix for bug #46614: Assertion in show_create_trigger() 
        on SHOW CREATE TRIGGER + MERGE table
          - unnecessary assert() removed as we may have more than 1 
        tables open e.g. for a merge table.
      bf9e9f67
  27. 30 Jul, 2009 1 commit
    • V Narayanan's avatar
      Bug#45800 crash when replacing into a merge table and there is a duplicate · 0c7528df
      V Narayanan authored
            
      A REPLACE in the MERGE engine is actually a REPLACE
      into one (FIRST or LAST) of the underlying MyISAM
      tables. So in effect the server works on the meta
      data of the MERGE table, while the real insert happens
      in the MyISAM table.
      
      The MERGE table has no index, while MyISAM has a
      unique index. When a REPLACE into a MERGE table (
      and the REPLACE conflicts with a duplicate in a
      child table) is done, we try to access the duplicate
      key information for the MERGE table. This information
      actually does not exist, hence this results in a crash.
      
      The problem can be resolved by modifying the MERGE
      engine to provide us the duplicate key information
      directly, instead of just returning the MyISAM index
      number as the error key. Then the SQL layer (or "the
      server") does not try to access the key_info of the
      MERGE table, which does not exist.
      
      The current patch modifies the MERGE engine to provide
      the position for a record where a unique key violation
      occurs.
      
      include/myisammrg.h:
        Bug#45800 crash when replacing into a merge table and there is a duplicate
        
        Add a member to the st_mymerge_info structure that will
        store the duplicate key offset in the MERGE table. This
        offset will be the sum of the record offset of the MyISAM
        table within the MERGE table and the offset of the record
        within the MyISAM table.
      mysql-test/r/merge.result:
        Bug#45800 crash when replacing into a merge table and there is a duplicate
        
        Result file for the test case.
      mysql-test/t/merge.test:
        Bug#45800 crash when replacing into a merge table and there is a duplicate
        
        Added test case for both REPLACE and INSERT...ON DUPLICATE UPDATE.
      storage/myisammrg/ha_myisammrg.cc:
        Bug#45800 crash when replacing into a merge table and there is a duplicate
        
        The info method now will process the HA_STATUS_ERRKEY flag
        and will return the index and the offset of the duplicate
        key.
      storage/myisammrg/ha_myisammrg.h:
        Bug#45800 crash when replacing into a merge table and there is a duplicate
        
        Set the HA_DUPLICATE_POS flag to indicate that the duplicate
        key information is now available in the MERGE storage engine.
      storage/myisammrg/myrg_info.c:
        Bug#45800 crash when replacing into a merge table and there is a duplicate
        
        We modify the myrg_status function to return the position of the
        duplicate key. The duplicate key position in the MERGE table will
        be the MyISAM file_offset and the offset within the MyISAM table
        of the start position of the records.
      0c7528df
  28. 15 Jul, 2009 1 commit
    • Kristofer Pettersson's avatar
      Bug#45781 infinite hang/crash in "opening tables" after handler tries to open merge · cd2d6adf
      Kristofer Pettersson authored
                table
      
      The MERGE table storage engine does not support the HA_CAN_SQL_HANDLE feature
      and any attempt to open the merge table will fail with ER_ILLEGAL_HA.
      
      After an error occurred the tables that was opened must be closed again
      or they will be left in an inconsistent state. However, the assumption
      made in the code for closing and register handler tables was that only
      one table will be opened, and this is not true for MERGE tables which
      will cause multiple tables to open.
      
      The next time a SELECT operation was issued on the merge table it
      caused the system to freeze.
      
      This patch fixes this issue by making sure that all tables which
      are opened also are closed in the event of an error.
      
      
      mysql-test/r/merge.result:
        Added test case for bug 45781
      mysql-test/t/merge.test:
        Added test case for bug 45781
      sql/sql_handler.cc:
        * mysql_ha_open() was never ment to open more than one table. If we encounter more tables, we should
          close all tables related to the current substatement and raise an exception.
      cd2d6adf
  29. 10 Jul, 2009 1 commit
    • Alexey Kopytov's avatar
      Bug #45796: invalid memory reads and writes when altering merge · 71197947
      Alexey Kopytov authored
                  and base tables 
      
      myrg_attach_children() could reuse a buffer that was allocated 
      previously based on a definition of a child table. The problem 
      was that the child's definition might have been changed, so 
      reusing the buffer could lead to crashes or valgrind errors 
      under some circumstances. 
       
      Fixed by changing myrg_attach_children() so that the 
      rec_per_key_part buffer is reused only when the child table
      have not changed, and reallocated otherwise (the old buffer is 
      deallocated if necessary).
      
      
      include/myisammrg.h:
        Added a pointer to need_compat_check as an argument to
        myrg_attach_children().
      mysql-test/r/merge.result:
        Added a test case for bug #45796.
      mysql-test/t/merge.test:
        Added a test case for bug #45796.
      storage/myisammrg/ha_myisammrg.cc:
        Pass a pointer to need_compat_check to myrg_attach_children().
      storage/myisammrg/myrg_open.c:
        Changed myrg_attach_children() so that the 
        rec_per_key_part buffer is reused only when the child table
        have not changed, and reallocated otherwise (the old buffer 
        is deallocated if necessary).
      71197947
  30. 17 Apr, 2009 1 commit
    • Anurag Shekhar's avatar
      Bug#44040 MySQL allows creating a MERGE table upon VIEWs but crashes when · f8f60edd
      Anurag Shekhar authored
              using it.
      The crash was due to a null pointer present for select_lex while 
      processing the view.
      Adding a check while opening the view to see if its a child of a 
      merge table fixed this problem.
      
      mysql-test/r/merge.result:
        Updated result for the new test case.
      mysql-test/t/merge.test:
        Added test case based on the bug description.
      sql/sql_base.cc:
        Added a check to check if the view being opened is a child table of a
        merge table and return error if it is.
      f8f60edd
  31. 04 Mar, 2009 1 commit
    • Anurag Shekhar's avatar
      Bug#41305 server crashes when inserting duplicate row into a merge table · ce3fd03c
      Anurag Shekhar authored
      This problem comes while inserting a duplicate row in merge table 
      without key but the child table has a primary key. 
      While forming the error message handler tries to locate the key field
      which is creating this problem but as there is no key on the merge
      table there is a segmentation fault.
      
      mysql-test/r/merge.result:
        Updated results with new test for this bug.
      mysql-test/t/merge.test:
        Added new test to test error generated from a key on child table 
        where merge table doesn't have any key.
      storage/myisammrg/ha_myisammrg.cc:
        Added a new check to see if the value of error key is higher than 
        the number of key in merge table and if it is the error key set 
        to MAX_KEY. The error message generation routine treats MAX_KEY as 
        unknown key and doesn't tries to access this in key_info.
      ce3fd03c
  32. 12 Feb, 2009 1 commit
    • V Narayanan's avatar
      Bug#40675 MySQL 5.1 crash with index merge algorithm and Merge tables · e9302e2f
      V Narayanan authored
                  
      A Query in the MyISAM merge table was crashing 
      if the index merge algorithm was being used
      
      Index Merge optimization requires the reading of 
      multiple indexes at the same time. Reading multiple 
      indexes at once with current SE API means that we 
      need to have handler instance for each to-be-read 
      index. This is done by creating clones of the handlers 
      instances. The clone internally does a open of the handler.
      
      The open for a MERGE engine is handled in the following 
      phases
      
      1) open parent table
      2) generate list of underlying
         table
      3) attach underlying tables
      
      But the current implementation does only the first 
      phase (i.e.) open parent table.
      
      The current patch fixes this at the MERGE engine level, 
      by handling the clone operation within the MERGE engine 
      rather than in the storage engine API. It opens and 
      attaches the MyISAM tables on the MyISAM storage engine 
      interface directly within the MERGE engine. The new MyISAM 
      table instances, as well as the MERGE clone itself, are not 
      visible in the table cache. This is not a problem because
      all locking is handled by the original MERGE table from which
      this is cloned of.
      
      mysql-test/r/merge.result:
        updated the result file to reflect the new tests
        added to test the fix
      mysql-test/t/merge.test:
        Added new tests to verify that the index merge
        algorithm does not crash in the merge engine.
      storage/myisammrg/ha_myisammrg.cc:
        Implement the clone method, that handles
        
        1) Cloning the handler
        2) Opening underlying MYISAM child tables
        3) Copies the state of the original handler and the children
           into the cloned instances
        4) Sets the appropriate flags
      storage/myisammrg/ha_myisammrg.h:
        Added a flag that is set to indicate that the current 
        instance is cloned. Also added the prototype or the clone 
        method.
      storage/myisammrg/myrg_open.c:
        Since we do now again use myrg_open() in the server
        removed the comments marking this as deadcode.
      e9302e2f
  33. 05 Feb, 2009 1 commit
    • Sergey Vojtovich's avatar
      BUG#39185 - Cardinality for merge tables calculated incorrectly. · 5f76630f
      Sergey Vojtovich authored
      Every subsequent query to a merge table with indexes was lowering
      down cardinality.
      
      The problem was that key statistics was not cleared when merge
      children were detached. Causing next attach children perform
      incremental key statistics calculation.
      
      Fixed by clearing key statistics when attaching first child.
      
      mysql-test/r/merge.result:
        A test case for BUG#39185.
      mysql-test/t/merge.test:
        A test case for BUG#39185.
      storage/myisammrg/myrg_open.c:
        Clear key statistics when we're attaching first child, even
        if it's buffer was allocated before. This is needed because
        detach_children() doesn't clear statistics, causing incremental
        statistics calculation.
      5f76630f
  34. 04 Feb, 2009 1 commit
    • Sergey Vojtovich's avatar
      BUG#32047 - 'Spurious' errors while opening MERGE tables · 8819e71c
      Sergey Vojtovich authored
      Accessing well defined MERGE table may return an error
      stating that the merge table is incorrectly defined. This
      happens if MERGE child tables were accessed before and we
      failed to open another incorrectly defined MERGE table in
      this connection.
      
      myrg_open() internally used my_errno as a variable for determining
      failure, and thus could be tricked into a wrong decision by other
      uses of my_errno.
      
      With this fix we use function local boolean flag instead of my_errno
      to determine failure.
      
      myisammrg/myrg_open.c:
        There are two requirement for accessing/setting my_errno variable,
        which were not followed by myrg_open():
        - it must be checked immediately after a function returned an error. There
          must be no calls to other functions that may change it's value between.
        - my_errno value must be set right before a function is going to return an
          error. There must be no calls to other functions that may change it's
          value between (that's why we have these tricks with save_errno at the
          bottom of myrg_open()).
        
        myrg_open() internally used my_errno as a variable for determining
        failure, and thus could be tricked into a wrong decision by other
        uses of my_errno.
      mysql-test/r/merge.result:
        A test case for BUG#32047.
      mysql-test/t/merge.test:
        A test case for BUG#32047.
      8819e71c
  35. 09 Oct, 2008 1 commit
  36. 03 Jun, 2008 1 commit
    • Mattias Jonsson's avatar
      Bug#31210: INSERT DELAYED crashes server when used on partitioned tables · 4eace597
      Mattias Jonsson authored
        
      Problem was an unclear error message since it could suggest that
      MyISAM did not support INSERT DELAYED.
      Changed the error message to say that DELAYED is not supported by the
      table, instead of the table's storage engine.
      The confusion is that a partitioned table is in somewhat sense using
      the partitioning storage engine, which in turn uses the ordinary
      storage engine. By saying that the table does not support DELAYED we
      do not give any extra informantion about the storage engine or if it
      is partitioned.
      
      mysql-test/r/innodb-replace.result:
        Bug#31210: INSERT DELAYED crashes server when used on partitioned tables
        
        changed error message
      mysql-test/t/innodb-replace.test:
        Bug#31210: INSERT DELAYED crashes server when used on partitioned tables
        
        changed error message
      mysql-test/t/merge.test:
        Bug#31210: INSERT DELAYED crashes server when used on partitioned tables
        
        changed error message
      mysql-test/t/partition_hash.test:
        Bug#31210: INSERT DELAYED crashes server when used on partitioned tables
        
        changed error message
      sql/share/errmsg.txt:
        Bug#31210: INSERT DELAYED crashes server when used on partitioned tables
        
        added error message for tables not supporting DELAYED
      sql/sql_insert.cc:
        Bug#31210: INSERT DELAYED crashes server when used on partitioned tables
        
        changed error message
      4eace597
  37. 25 Apr, 2008 1 commit
    • unknown's avatar
      Fixed bug#36006: Optimizer does table scan for SELECT COUNT(*) · bbcf9847
      unknown authored
                       for ENGINE=MRG_MYISAM (should be optimized out).
      
      Before WL#3281 MERGE engine had the HA_NOT_EXACT_COUNT flag
      unset, and it worked with COUNT optimization as desired.
      After the removal of the HA_NOT_EXACT_COUNT flag neither
      HA_STATS_RECORDS_IS_EXACT (opposite to former HA_NOT_EXACT_COUNT
      flag) nor modern HA_HAS_RECORDS flag were not added to MERGE
      table flag mask.
      
      1. The HA_HAS_RECORDS table flag has been set.
      2. The ha_myisammrg::records method has been overridden to
         calculate total number of records in underlying tables.
      
      
      
      storage/myisammrg/myrg_records.c:
        Fixed bug#36006: Optimizer does table scan for select count(*).
        The myrg_records function has been added to calculate total number
        of records in underlying tables.
      include/myisammrg.h:
        Fixed bug#36006: Optimizer does table scan for select count(*).
        The myrg_records function declaration has been added.
      mysql-test/r/merge.result:
        Added test case for bug#36006.
      mysql-test/t/merge.test:
        Added test case for bug#36006.
      storage/myisammrg/CMakeLists.txt:
        Fixed bug#36006: Optimizer does table scan for select count(*).
        New myrg_records.c file has been added.
      storage/myisammrg/Makefile.am:
        Fixed bug#36006: Optimizer does table scan for select count(*).
        New myrg_records.c file has been added.
      storage/myisammrg/ha_myisammrg.cc:
        Fixed bug#36006: Optimizer does table scan for select count(*).
        The ha_myisammrg::records method has been overridden.
      storage/myisammrg/ha_myisammrg.h:
        Fixed bug#36006: Optimizer does table scan for select count(*).
        1. The HA_HAS_RECORDS table flag has been set.
        2. The ha_myisammrg::records method has been overridden.
      bbcf9847
  38. 14 Mar, 2008 1 commit
    • unknown's avatar
      BUG#28248 - mysqldump results with MERGE ... UNION=() cannot be executed · c0a50251
      unknown authored
      When there are no underlying tables specified for a merge table,
      SHOW CREATE TABLE outputs a statement that cannot be executed. The
      same is true for mysqldump (it generates dumps that cannot be
      executed).
      
      This happens because SQL parser does not accept empty UNION() clause.
      
      This patch changes the following:
      - it is now possible to execute CREATE/ALTER statement with
        empty UNION() clause.
      - the same as above, but still worth noting: it is now possible to
        remove underlying tables mapping using ALTER TABLE ... UNION=().
      - SHOW CREATE TABLE does not output UNION() clause if there are
        no underlying tables specified for a merge table. This makes
        mysqldump slightly smaller.
      
      
      mysql-test/r/merge.result:
        A test case for BUG#28248.
      mysql-test/t/merge.test:
        A test case for BUG#28248.
      sql/ha_myisammrg.cc:
        Do not output UNION clause in SHOW CREATE TABLE, when there are
        no underlying tables defined.
      sql/sql_yacc.yy:
        Make underlying table list for MERGE engine optional.
        
        As for MERGE engine empty underlying tables list is valid, it should
        be valid for the parser as well.
        
        This change is mostly needed to restore dumps made by earlier MySQL
        versions. Also with this fix it is possible to remove underlying
        tables mapping by using ALTER TABLE ... UNION=().
      c0a50251
  39. 12 Dec, 2007 1 commit
  40. 26 Nov, 2007 1 commit
    • unknown's avatar
      Fix for bug #28837: MyISAM storage engine error (134) doing delete with · 60a1e86c
      unknown authored
      self-join
      
      When doing DELETE with self-join on a MyISAM or MERGE table, it could
      happen that a record being retrieved in join_read_next_same() has
      already been deleted by previous iterations. That caused the engine's
      index_next_same() method to fail with HA_ERR_RECORD_DELETED error and
      the whole DELETE query to be aborted with an error.
      
      Fixed by suppressing the HA_ERR_RECORD_DELETED error in
      hy_myisam::index_next_same() and ha_myisammrg::index_next_same(). Since
      HA_ERR_RECORD_DELETED can only be returned by MyISAM, there is no point
      in filtering this error in the SQL layer.
      
      
      mysql-test/r/merge.result:
        Added a test case for bug #28837.
      mysql-test/r/myisam.result:
        Added a test case for bug #28837.
      mysql-test/t/merge.test:
        Added a test case for bug #28837.
      mysql-test/t/myisam.test:
        Added a test case for bug #28837.
      sql/ha_myisam.cc:
        Skip HA_ERR_RECORD_DELETED silently when calling mi_rnext_same().
      sql/ha_myisammrg.cc:
        Skip HA_ERR_RECORD_DELETED silently when calling mi_rnext_same().
      60a1e86c