forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit76eccf0
committed
Add some more defenses against silly estimates to gincostestimate().
A report from Andy Colson showed that gincostestimate() was not beingnearly paranoid enough about whether to believe the statistics it finds inthe index metapage. The problem is that the metapage stats (other than thepending-pages count) are only updated by VACUUM, and in the worst casecould still reflect the index's original empty state even when it has grownto many entries. We attempted to deal with that by scaling up the stats tomatch the current index size, but if nEntries is zero then scaling it upstill gives zero. Moreover, the proportion of pages that are entry pagesvs. data pages vs. pending pages is unlikely to be estimated very well byscaling if the index is now orders of magnitude larger than before.We can improve matters by expanding the use of the rule-of-thumb estimatesI introduced in commit7fb008c: if the index has grown by morethan a cutoff amount (here set at 4X growth) since VACUUM, then use therule-of-thumb numbers instead of scaling. This might not be exactly rightbut it seems much less likely to produce insane estimates.I also improved both the scaling estimate and the rule-of-thumb estimateto account for numPendingPages, since it's reasonable to expect that thatis accurate in any case, and certainly pages that are in the pending listare not either entry or data pages.As a somewhat separate issue, adjust the estimation equations that areconcerned with extra fetches for partial-match searches. These equationssuppose that a fraction partialEntries / numEntries of the entry and datapages will be visited as a consequence of a partial-match search. Now,it's physically impossible for that fraction to exceed one, but ourestimate of partialEntries is mostly bunk, and our estimate of numEntriesisn't exactly gospel either, so we could arrive at a silly value. In theexample presented by Andy we were coming out with a value of 100, leadingto insane cost estimates. Clamp the fraction to one to avoid that.Like the previous patch, back-patch to all supported branches; thisproblem can be demonstrated in one form or another in all of them.1 parent12e116a commit76eccf0
1 file changed
+52
-29
lines changedLines changed: 52 additions & 29 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7083 | 7083 |
| |
7084 | 7084 |
| |
7085 | 7085 |
| |
| 7086 | + | |
7086 | 7087 |
| |
7087 | 7088 |
| |
7088 | 7089 |
| |
| |||
7109 | 7110 |
| |
7110 | 7111 |
| |
7111 | 7112 |
| |
7112 |
| - | |
| 7113 | + | |
| 7114 | + | |
| 7115 | + | |
| 7116 | + | |
| 7117 | + | |
| 7118 | + | |
| 7119 | + | |
| 7120 | + | |
| 7121 | + | |
| 7122 | + | |
| 7123 | + | |
| 7124 | + | |
| 7125 | + | |
| 7126 | + | |
| 7127 | + | |
| 7128 | + | |
| 7129 | + | |
| 7130 | + | |
| 7131 | + | |
7113 | 7132 |
| |
7114 | 7133 |
| |
7115 |
| - | |
7116 |
| - | |
7117 |
| - | |
| 7134 | + | |
| 7135 | + | |
| 7136 | + | |
7118 | 7137 |
| |
7119 | 7138 |
| |
7120 | 7139 |
| |
7121 |
| - | |
7122 |
| - | |
7123 |
| - | |
7124 |
| - | |
7125 |
| - | |
7126 |
| - | |
7127 |
| - | |
7128 |
| - | |
| 7140 | + | |
| 7141 | + | |
| 7142 | + | |
7129 | 7143 |
| |
7130 |
| - | |
7131 |
| - | |
| 7144 | + | |
| 7145 | + | |
| 7146 | + | |
7132 | 7147 |
| |
7133 | 7148 |
| |
7134 | 7149 |
| |
7135 | 7150 |
| |
7136 |
| - | |
7137 |
| - | |
7138 |
| - | |
7139 |
| - | |
7140 |
| - | |
7141 |
| - | |
7142 |
| - | |
| 7151 | + | |
| 7152 | + | |
| 7153 | + | |
| 7154 | + | |
| 7155 | + | |
| 7156 | + | |
| 7157 | + | |
| 7158 | + | |
| 7159 | + | |
| 7160 | + | |
| 7161 | + | |
7143 | 7162 |
| |
7144 | 7163 |
| |
7145 |
| - | |
7146 |
| - | |
7147 |
| - | |
| 7164 | + | |
| 7165 | + | |
7148 | 7166 |
| |
7149 | 7167 |
| |
7150 | 7168 |
| |
| |||
7272 | 7290 |
| |
7273 | 7291 |
| |
7274 | 7292 |
| |
7275 |
| - | |
| 7293 | + | |
| 7294 | + | |
| 7295 | + | |
7276 | 7296 |
| |
7277 |
| - | |
| 7297 | + | |
| 7298 | + | |
| 7299 | + | |
| 7300 | + | |
7278 | 7301 |
| |
7279 | 7302 |
| |
7280 | 7303 |
| |
7281 |
| - | |
7282 |
| - | |
| 7304 | + | |
| 7305 | + | |
7283 | 7306 |
| |
7284 |
| - | |
| 7307 | + | |
7285 | 7308 |
| |
7286 | 7309 |
| |
7287 | 7310 |
| |
|
0 commit comments
Comments
(0)