• Sergei Petrunia's avatar
    MDEV-30218: Incorrect optimization for rowid_filtering · 87eccd78
    Sergei Petrunia authored
    (Patch from Monty, slightly amended)
    
    Fix rowid filtering optimization in best_access_path():
    
    == Ref access + rowid filtering ==
    The cost computations compare #records and index-only scan cost
    (keyread_tmp) to find out the per-record advantage one will get if
    they skip reading full table record.
    
    The computations produce wrong result when:
    
    - the #records are "clipped down" with s->worst_seeks or
      thd->variables.max_seeks_for_key. keyread_tmp is not clipped
      this way so the numbers are not comparable.
    
    - access_factor is negative. This means index_only read is
      cheaper than non-index-only read.
    
    This patch makes the optimizer not to consider Rowid Filtering in
    such cases.
    The decision is logged in the Optimizer Trace using
    "rowid_filter_skipped" name.
    
    == Range access + rowid filtering ==
    when considering to use Rowid Filter with range access, do multiply
    keyread_tmp by record_count. That way, it is comparable with the
    range access's estimate, which is multiplied by record_count.
    87eccd78
opt_trace.result 288 KB