- Notifications
You must be signed in to change notification settings - Fork5
Commitfccebe4
committed
Use SnapshotDirty rather than an active snapshot to probe index endpoints.
If there are lots of uncommitted tuples at the end of the index range,get_actual_variable_range() ends up fetching each one and doing an MVCCvisibility check on it, until it finally hits a visible tuple. This isbad enough in isolation, considering that we don't need an exact answeronly an approximate one. But because the tuples are not yet committed,each visibility check does a TransactionIdIsInProgress() test, whichinvolves scanning the ProcArray. When multiple sessions do thisconcurrently, the ensuing contention results in horrid performance loss.20X overall throughput loss on not-too-complicated queries is easy todemonstrate in the back branches (though someone's made it noticeablyless bad in HEAD).We can dodge the problem fairly effectively by using SnapshotDirty ratherthan a normal MVCC snapshot. This will cause the index probe to takeuncommitted tuples as good, so that we incur only one tuple fetch and testeven if there are many such tuples. The extent to which this degrades theestimate is debatable: it's possible the result is actually a more accurateprediction than before, if the endmost tuple has become committed by thetime we actually execute the query being planned. In any case, it's notvery likely that it makes the estimate a lot worse.SnapshotDirty will still reject tuples that are known committed dead, sowe won't give bogus answers if an invalid outlier has been deleted but notyet vacuumed from the index. (Because btrees know how to mark such tuplesdead in the index, we shouldn't have a big performance problem in the casethat there are many of them at the end of the range.) This considerationmotivates not using SnapshotAny, which was also considered as a fix.Note: the back branches were using SnapshotNow instead of an MVCC snapshot,but the problem and solution are the same.Per performance complaints from Bartlomiej Romanski, Josh Berkus, andothers. Back-patch to 9.0, where the issue was introduced (by commit40608e7).1 parentcf6aa68 commitfccebe4
1 file changed
+21
-5
lines changedLines changed: 21 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
133 | 133 |
| |
134 | 134 |
| |
135 | 135 |
| |
136 |
| - | |
137 | 136 |
| |
138 | 137 |
| |
139 | 138 |
| |
| |||
4962 | 4961 |
| |
4963 | 4962 |
| |
4964 | 4963 |
| |
| 4964 | + | |
4965 | 4965 |
| |
4966 | 4966 |
| |
4967 | 4967 |
| |
| |||
4984 | 4984 |
| |
4985 | 4985 |
| |
4986 | 4986 |
| |
| 4987 | + | |
4987 | 4988 |
| |
4988 | 4989 |
| |
4989 | 4990 |
| |
| |||
5000 | 5001 |
| |
5001 | 5002 |
| |
5002 | 5003 |
| |
5003 |
| - | |
5004 |
| - | |
| 5004 | + | |
| 5005 | + | |
| 5006 | + | |
| 5007 | + | |
| 5008 | + | |
| 5009 | + | |
| 5010 | + | |
| 5011 | + | |
| 5012 | + | |
| 5013 | + | |
| 5014 | + | |
| 5015 | + | |
| 5016 | + | |
| 5017 | + | |
| 5018 | + | |
| 5019 | + | |
| 5020 | + | |
5005 | 5021 |
| |
5006 | 5022 |
| |
5007 | 5023 |
| |
| |||
5032 | 5048 |
| |
5033 | 5049 |
| |
5034 | 5050 |
| |
5035 |
| - | |
5036 |
| - | |
| 5051 | + | |
| 5052 | + | |
5037 | 5053 |
| |
5038 | 5054 |
| |
5039 | 5055 |
| |
|
0 commit comments
Comments
(0)