diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 73f5cba..0b1d89f 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2611,12 +2611,15 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, { uint idx; double scan_time; + double origin_read_cost; + QUICK_SELECT_I* origin_quick= NULL; DBUG_ENTER("SQL_SELECT::test_quick_select"); DBUG_PRINT("enter",("keys_to_use: %lu prev_tables: %lu const_tables: %lu", (ulong) keys_to_use.to_ulonglong(), (ulong) prev_tables, (ulong) const_tables)); - set_quick(NULL); + origin_quick= quick; + quick= NULL; needed_reg.clear_all(); quick_keys.clear_all(); if (keys_to_use.is_clear_all()) @@ -2913,8 +2916,14 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, thd->mem_root= param.old_root; /* If we got a read plan, create a quick select from it. */ - if (best_trp) + if ((origin_quick && best_trp && (origin_quick->read_time < best_trp->read_cost)) || + ((best_trp == NULL) && (origin_quick != NULL))) + { + quick= origin_quick; + } + else if (best_trp) { + set_quick(NULL); records= best_trp->records; if (!(quick= best_trp->make_quick(¶m, TRUE)) || quick->init()) set_quick(NULL);