foreign-estimates.patch
application/octet-stream
Filename: foreign-estimates.patch
Type: application/octet-stream
Part: 0
Message:
Foreign table scan estimates
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/optimizer/path/costsize.c | 0 | 0 |
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
new file mode 100644
index e45bc12..f62a690
*** a/src/backend/optimizer/path/costsize.c
--- b/src/backend/optimizer/path/costsize.c
*************** set_cte_size_estimates(PlannerInfo *root
*** 3824,3831 ****
* is responsible for producing useful estimates. We can do a decent job
* of estimating baserestrictcost, so we set that, and we also set up width
* using what will be purely datatype-driven estimates from the targetlist.
! * There is no way to do anything sane with the rows value, so we just put
! * a default estimate and hope that the wrapper can improve on it. The
* wrapper's GetForeignRelSize function will be called momentarily.
*
* The rel's targetlist and restrictinfo list must have been constructed
--- 3824,3831 ----
* is responsible for producing useful estimates. We can do a decent job
* of estimating baserestrictcost, so we set that, and we also set up width
* using what will be purely datatype-driven estimates from the targetlist.
! * Calculate the rows value from the table statistics (or a default value
! * if there are none) and hope that the wrapper can improve on it. The
* wrapper's GetForeignRelSize function will be called momentarily.
*
* The rel's targetlist and restrictinfo list must have been constructed
*************** set_foreign_size_estimates(PlannerInfo *
*** 3837,3843 ****
/* Should only be applied to base relations */
Assert(rel->relid > 0);
! rel->rows = 1000; /* entirely bogus default estimate */
cost_qual_eval(&rel->baserestrictcost, rel->baserestrictinfo, root);
--- 3837,3856 ----
/* Should only be applied to base relations */
Assert(rel->relid > 0);
! if (rel->tuples == 0)
! rel->rows = 1000.0; /* default estimate */
! else
! {
! /* apply restriction clauses */
! double nrows = rel->tuples *
! clauselist_selectivity(root,
! rel->baserestrictinfo,
! 0,
! JOIN_INNER,
! NULL);
!
! rel->rows = clamp_row_est(nrows);
! }
cost_qual_eval(&rel->baserestrictcost, rel->baserestrictinfo, root);