Tune bitmap scan cost model by updating to nonlinear cost per page
We had some customers reporting that planner generates plan using seqscan instead of bitmapscan, and the execution time of seqscan is 5x slower than using bitmapscan. The statistics were updated and quite accurate. Bitmap table scan uses some formula to interpolate between random_page_cost and seq_page_cost to determine the cost per page. But it turns out that the default value of random_page_cost is 100x of the value of seq_page_cost. With the original cost formula, random_page_cost predominates in the final cost result, even the formula is declared to be non-linear, but it is still more like linear, which can't reflect the real cost per page when a majority of pages are fetched. Therefore, the cost formula is updated to real non-linear function to reflect both random_page_cost and seq_page_cost for different percentage of pages fetched. For example, for the default value random_page_cost = 100, seq_page_cost = 1, if 80% pages are fetched, the cost per page in old formula is 11.45, which is 10x more than seqscan, because the cost is dominated by random_page_cost in the formula. With the new formula, the cost per page is 1.63, which can reflect the real cost better, in my opinion. [#151934601]
Showing
想要评论请 注册 或 登录