* Adjust the cost estimates of a foreign grouping path to include the cost of * generating properly-sorted output. */
| 3631 | * generating properly-sorted output. |
| 3632 | */ |
| 3633 | static void |
| 3634 | adjust_foreign_grouping_path_cost(PlannerInfo *root, |
| 3635 | List *pathkeys, |
| 3636 | double retrieved_rows, |
| 3637 | double width, |
| 3638 | double limit_tuples, |
| 3639 | Cost *p_startup_cost, |
| 3640 | Cost *p_run_cost) |
| 3641 | { |
| 3642 | /* |
| 3643 | * If the GROUP BY clause isn't sort-able, the plan chosen by the remote |
| 3644 | * side is unlikely to generate properly-sorted output, so it would need |
| 3645 | * an explicit sort; adjust the given costs with cost_sort(). Likewise, |
| 3646 | * if the GROUP BY clause is sort-able but isn't a superset of the given |
| 3647 | * pathkeys, adjust the costs with that function. Otherwise, adjust the |
| 3648 | * costs by applying the same heuristic as for the scan or join case. |
| 3649 | */ |
| 3650 | if (!grouping_is_sortable(root->parse->groupClause) || |
| 3651 | !pathkeys_contained_in(pathkeys, root->group_pathkeys)) |
| 3652 | { |
| 3653 | Path sort_path; /* dummy for result of cost_sort */ |
| 3654 | |
| 3655 | cost_sort(&sort_path, |
| 3656 | root, |
| 3657 | pathkeys, |
| 3658 | *p_startup_cost + *p_run_cost, |
| 3659 | retrieved_rows, |
| 3660 | width, |
| 3661 | 0.0, |
| 3662 | work_mem, |
| 3663 | limit_tuples); |
| 3664 | |
| 3665 | *p_startup_cost = sort_path.startup_cost; |
| 3666 | *p_run_cost = sort_path.total_cost - sort_path.startup_cost; |
| 3667 | } |
| 3668 | else |
| 3669 | { |
| 3670 | /* |
| 3671 | * The default extra cost seems too large for foreign-grouping cases; |
| 3672 | * add 1/4th of that default. |
| 3673 | */ |
| 3674 | double sort_multiplier = 1.0 + (DEFAULT_FDW_SORT_MULTIPLIER |
| 3675 | - 1.0) * 0.25; |
| 3676 | |
| 3677 | *p_startup_cost *= sort_multiplier; |
| 3678 | *p_run_cost *= sort_multiplier; |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | /* |
| 3683 | * Detect whether we want to process an EquivalenceClass member. |
no test coverage detected