forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit7170268
committed
Improve ANALYZE's handling of concurrent-update scenarios.
This patch changes the rule for whether or not a tuple seen by ANALYZEshould be included in its sample.When we last touched this logic, in commit51e1445, we weren'tthinking very hard about tuples being UPDATEd by a long-runningconcurrent transaction. In such a case, we might see the pre-image aseither LIVE or DELETE_IN_PROGRESS depending on timing; and we might seethe post-image not at all, or as INSERT_IN_PROGRESS. Since the existingcode will not sample either DELETE_IN_PROGRESS or INSERT_IN_PROGRESStuples, this leads to concurrently-updated rows being omitted from thesample entirely. That's not very helpful, and it's especially the wrongthing if the concurrent transaction ends up rolling back.The right thing seems to be to sample DELETE_IN_PROGRESS rows just as ifthey were live. This makes the "sample it" and "count it" decisions thesame, which seems good for consistency. It's clearly the right thingif the concurrent transaction ends up rolling back; in effect, we aresampling as though IN_PROGRESS transactions haven't happened yet.Also, this combination of choices ensures maximum robustness againstthe different combinations of whether and in which state we might see thepre- and post-images of an update.It's slightly annoying that we end up recording immediately-out-of-datestats in the case where the transaction does commit, but on the otherhand the stats are fine for columns that didn't change in the update.And the alternative of sampling INSERT_IN_PROGRESS rows instead seemslike a bad idea, because then the sampling would be inconsistent withthe way rows are counted for the stats report.Per report from Mark Chambers; thanks to Jeff Janes for diagnosingwhat was happening. Back-patch to all supported versions.Discussion:https://postgr.es/m/CAFh58O_Myr6G3tcH3gcGrF-=OExB08PJdWZcSBcEcovaiPsrHA@mail.gmail.com1 parent68a13f2 commit7170268
1 file changed
+18
-3
lines changedLines changed: 18 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1124 | 1124 |
| |
1125 | 1125 |
| |
1126 | 1126 |
| |
1127 |
| - | |
1128 |
| - | |
1129 |
| - | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
1130 | 1131 |
| |
1131 | 1132 |
| |
1132 | 1133 |
| |
1133 | 1134 |
| |
1134 | 1135 |
| |
1135 | 1136 |
| |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
1136 | 1148 |
| |
1137 | 1149 |
| |
1138 | 1150 |
| |
1139 | 1151 |
| |
| 1152 | + | |
| 1153 | + | |
1140 | 1154 |
| |
| 1155 | + | |
1141 | 1156 |
| |
1142 | 1157 |
| |
1143 | 1158 |
| |
|
0 commit comments
Comments
(0)