"=?utf-8?B?WHVhbiBDaGVu?=" <cx0...@vip.qq.com> writes: > In some cases, I noticed that a parent path node's total cost is less than > that of one of its child path nodes. I initially expected that the total cost > of a node should be at least as large as the sum of its child nodes’ total > costs, or at least not smaller than any single child.
That is true if we expect the parent node to run its child node(s) to completion, but there are cases where we don't. An obvious example is a Limit node. In the case at hand, the planner is betting that the Merge will not need to run one side to completion because the other side's largest join key value is less than the first side's largest value. The merge can stop as soon as either input is exhausted. regards, tom lane