• unknown's avatar
    BUG#30590 - delete from memory table with composite btree primary key · cf5762b4
    unknown authored
    DELETE query against memory table with btree index may remove
    not all matching rows. This happens only when DELETE uses
    index read method to find matching rows. E.g. for queries
    like DELETE FROM t1 WHERE a=1.
    
    Fixed by reverting fix for BUG9719 and applying proper solution.
    
    
    heap/hp_delete.c:
      Reverted fix for BUG9719 as it makes queries like
      DELETE FROM t1 WHERE a=1 to remove not all matching
      rows (assuming this is memory table and there is btree
      key over `a`).
      
      This happens because we calculate info->lastkey_len in
      heap_rkey(). When we enter heap_rnext(), info->lastkey_len
      is 0 (set by hp_rb_delete_key()). We need to preserve
      info->lastkey_len in this situation, otherwise
      tree_search_key() will always return smallest value in
      a tree.
    heap/hp_rfirst.c:
      If we're performing index_first on a table that was taken from
      table cache, info->lastkey_len is initialized to previous query.
      Thus we set info->lastkey_len to proper value for subsequent
      heap_rnext() calls.
      This is needed for DELETE queries only, otherwise this variable is
      not used.
      Note that the same workaround may be needed for heap_rlast(), but
      for now heap_rlast() is never used for DELETE queries.
    heap/hp_rnext.c:
      An optimization for DELETE queries that use index_first()/index_next().
      Use faster tree_search_edge() instead of tree_search_key().
    mysql-test/r/heap_btree.result:
      A test case for BUG#30590.
    mysql-test/t/heap_btree.test:
      A test case for BUG#30590.
    cf5762b4
heap_btree.result 8.33 KB