=== modified file 'sql/sql_select.cc' --- sql/sql_select.cc 2010-04-21 12:51:53 +0000 +++ sql/sql_select.cc 2010-04-26 16:08:25 +0000 @@ -283,6 +283,11 @@ Item_equal *find_item_equal(COND_EQUAL *cond_equal, Field *field, bool *inherited_fl); +#ifndef DBUG_OFF +const double ARTIFICIAL_LOW_COST= 1e-20; +const double ARTIFICIAL_HIGH_COST= 1/ARTIFICIAL_LOW_COST; +#endif + /** This handles SELECT with and without UNION. @@ -7682,6 +7687,24 @@ advance_sj_state(join, remaining_tables, s, idx, ¤t_record_count, ¤t_read_time, &loose_scan_pos); + /* This prefers a plan where tables are listed in alphabetical order */ + DBUG_EXECUTE_IF("optimizer_force_alphab_sorted_plan", + { + uint i= 1; + while (i < (idx + 1) && + (strcmp(join->positions[i-1].table->table->alias, + join->positions[i].table->table->alias) + == -1)) + i++; + if (i == (idx + 1)) + { + DBUG_PRINT("info", ("found alphabetically sorted" + " plan with %u tables", idx + 1)); + current_read_time= current_record_count= + ARTIFICIAL_LOW_COST; // prefer this plan + } + } + ); /* Expand only partial plans with lower cost than the best QEP so far */ if ((current_read_time + current_record_count / (double) TIME_FOR_COMPARE) >= join->best_read) @@ -13718,6 +13741,13 @@ one_lookup_cost; dups_cost += write_cost + full_lookup_cost; + DBUG_EXECUTE_IF("optimizer_avoid_dups_weedout", + { + /* This gives a high cost to this strategy: */ + dups_cost= prefix_rec_count= ARTIFICIAL_HIGH_COST; + sj_outer_fanout= 1; + } + ); /* Use the strategy if * it is cheaper then what we've had, or