提交 982bcd4e 编写于 作者: H Haisheng Yuan

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]
上级 a7d11627
......@@ -716,8 +716,8 @@ cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
* cost per page.
*/
if (pages_fetched >= 2.0)
cost_per_page = random_page_cost -
(random_page_cost - seq_page_cost) * sqrt(pages_fetched / T);
cost_per_page = seq_page_cost *
pow(random_page_cost / seq_page_cost, 1 - sqrt(pages_fetched / T));
else
cost_per_page = random_page_cost;
......@@ -817,8 +817,8 @@ cost_bitmap_appendonly_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
* cost per page.
*/
if (pages_fetched >= 2.0)
cost_per_page = random_page_cost -
(random_page_cost - seq_page_cost) * sqrt(pages_fetched / T);
cost_per_page = seq_page_cost *
pow(random_page_cost / seq_page_cost, 1 - sqrt(pages_fetched / T));
else
cost_per_page = random_page_cost;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册