It seems quite strange to me that we calculate total_pages before any partition pruning and constraint exclusion is performed during set_base_rel_sizes(). Wouldn't it be better to wait until after that's done so we don't mistakenly count relations we're not going to scan?
Delaying the calculation until after set_base_rel_sizes() means it's still done in time before it's needed in set_base_rel_pathlists(). The attached patch implements the change. There are no visible plan changes in the regression tests, but the change can affect the plans for larger partitioned tables. -- David Rowley http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
total_pages_after_pruning.patch
Description: Binary data