• V Narayanan's avatar
    Bug#45800 crash when replacing into a merge table and there is a duplicate · 0d61bd9d
    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.
    0d61bd9d
merge.test 49.9 KB