| 8753 | |
| 8754 | |
| 8755 | void |
| 8756 | best_access_path(JOIN *join, |
| 8757 | JOIN_TAB *s, |
| 8758 | table_map remaining_tables, |
| 8759 | const POSITION *join_positions, |
| 8760 | uint idx, |
| 8761 | bool disable_jbuf, |
| 8762 | double record_count, |
| 8763 | POSITION *pos, |
| 8764 | POSITION *loose_scan_pos) |
| 8765 | { |
| 8766 | THD *thd= join->thd; |
| 8767 | uint use_cond_selectivity= |
| 8768 | thd->variables.optimizer_use_condition_selectivity; |
| 8769 | TABLE *table= s->table; |
| 8770 | handler *file= table->file; |
| 8771 | my_bool found_constraint= 0; |
| 8772 | /* |
| 8773 | key_dependent is 0 if all key parts could be used or if there was an |
| 8774 | EQ_REF table found (which uses all key parts). In other words, we cannot |
| 8775 | find a better key for the table even if remaining_tables is reduced. |
| 8776 | Otherwise it's a bitmap of tables that could improve key usage. |
| 8777 | */ |
| 8778 | table_map key_dependent= 0; |
| 8779 | ALL_READ_COST tmp; |
| 8780 | ha_rows rec; |
| 8781 | MY_BITMAP *eq_join_set= &s->table->eq_join_set; |
| 8782 | KEYUSE *hj_start_key= 0; |
| 8783 | table_map spl_pd_boundary= 0; |
| 8784 | Loose_scan_opt loose_scan_opt; |
| 8785 | struct best_plan best; |
| 8786 | Json_writer_object trace_wrapper(thd, "best_access_path"); |
| 8787 | DBUG_ENTER("best_access_path"); |
| 8788 | |
| 8789 | /* |
| 8790 | Assume that there is at least one accepted row from previous table |
| 8791 | combinations. |
| 8792 | This fixes a problem when the selectivity for the preceding table |
| 8793 | combinations becomes so high that record_count becomes << 1.0, |
| 8794 | which makes the cost for the current table so low that it does not |
| 8795 | matter when calculating the best plans. |
| 8796 | */ |
| 8797 | set_if_bigger(record_count, 1.0); |
| 8798 | |
| 8799 | best.cost= DBL_MAX; |
| 8800 | best.records= DBL_MAX; |
| 8801 | best.records_read= DBL_MAX; |
| 8802 | best.records_out= MY_MIN(table->stat_records() * table->cond_selectivity, |
| 8803 | table->opt_range_condition_rows); |
| 8804 | best.identical_keys= 0; |
| 8805 | best.filter= 0; |
| 8806 | best.key= 0; |
| 8807 | best.max_key_part= 0; |
| 8808 | best.type= JT_UNKNOWN; |
| 8809 | best.forced_index= MAX_KEY; |
| 8810 | best.found_ref= 0; |
| 8811 | best.ref_depends_map= 0; |
| 8812 | best.refills= 0; |
no test coverage detected