1

When the MYSQL calculate the scan cost by the method Optimize_table_order::calculate_scan_cost(const JOIN_TAB *tab,....), we know cost does not include the CPU cost during execution for rows that are not filtered out based on the method comments. So the cost calculated by subtracting the rows_after_filtering ,such as below:

scan_and_filter_cost= prefix_rowcount *
  (tab->quick()->cost_est.total_cost() +
   cost_model->row_evaluate_cost(tab->found_records -
                                 *rows_after_filtering));

  scan_and_filter_cost= prefix_rowcount *
    (single_scan_read_cost +
     cost_model->row_evaluate_cost(tab->records() - *rows_after_filtering));

My question is why the cost does not include the CPU cost during execution for rows that are not filtered out? It should be include it in my mind.

https://github.com/mysql/mysql-server/blob/5.7/sql/sql_planner.cc#L712

YuFeng Shen
  • 1,475
  • 1
  • 17
  • 41
  • That time is indeed included, just at other places (that handle the "remaining rows"). – Solarflare Aug 07 '17 at 19:19
  • Can you kindly point out which other places already include the row evaluate cost for the "rows_after_filtering"? – YuFeng Shen Aug 08 '17 at 02:04
  • See e.g. here: `https://github.com/mysql/mysql-server/blob/5.7/sql/sql_planner.cc#L1083`. It will use the result of your function (cost for everything - cost for the remaining "rows_after_filtering") and then add just the cost for "rows_after_filtering", so you have the total cost again (including cpu). – Solarflare Aug 08 '17 at 07:17
  • Thanks, BTW, why do the separation? That is to say why not using cost_model->row_evaluate_cost(tab->records()) directly? – YuFeng Shen Aug 08 '17 at 07:39
  • I guess the simple answer is: as somebody defined scanning costs that way. – Solarflare Aug 08 '17 at 08:39
  • Thank you for your answer.BTW, if you have any idea for my another MYSQL source code related question ? https://stackoverflow.com/questions/45528370/how-was-this-records-fanout-logic-derived-for-the-no-statistics-case-in-mysql – YuFeng Shen Aug 08 '17 at 09:05

0 Answers0