• Michael Widenius's avatar
    greedy_search() and best_extension_by_limited_search() scrambled table order · 64f24b77
    Michael Widenius authored
    best_extension_by_limited_search() assumes that tables should be sorted
    according to size to be able to quickly disregard bad plans. However the
    current usage of swap_variables() will change the table order to a not
    sorted one for the next recursive call. This breaks the assumtion and
    causes performance issues when using many tables (we have to examine
    many more plans).
    
    This patch fixes this by ensuring that the original table order is kept
    for the not yet used tables when best_extension_by_limited_search() is
    called.
    
    This was done by always calling swap_variables() for each table and
    restoring the original table order at exit.
    
    Some test changed:
    - In a majority of the test the change was that two "identical tables"
      where swapped and the optimzer is now using the first/smaller table
    - In few test the table order was changed. The new plan looks identical
      or slighly better than the original.
    64f24b77
sql_select.cc 985 KB