forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitbb5ae8f
committed
Use a hash table to de-duplicate NOTIFY events faster.
Previously, async.c got rid of duplicate notifications by scanningthe list of pending events to compare each one to the proposed newevent. This works okay for very small numbers of distinct events,but degrades as O(N^2) for many events. We can improve matters byusing a hash table to probe for duplicates. So as not to add alot of overhead for the simple cases that the code did handle wellbefore, create the hash table only once a (sub)transaction hasqueued more than 16 distinct notify events.A downside is that we now have to do per-event work to propagatea successful subtransaction's notify events up to its parent.(But this isn't significant unless the subtransaction had manyevents, in which case the O(N^2) behavior would have been inplay already, so we still come out ahead.)We can make some lemonade out of this lemon, though: since we mustexamine each event anyway, it's now possible to de-duplicate eventsfully, rather than skipping that for events merged up fromsubtransactions. Hence, remove the old weasel wording in notify.sgmlabout whether de-duplication happens or not, and adjust the testcase in async-notify.spec that exhibited the old behavior.While at it, rearrange the definition of struct Notification to makeit more compact and require just one palloc per event, rather thantwo or three. This saves space when there are a lot of events,in fact more than enough to buy back the space needed for the hashtable.Patch by me, based on discussions around a different patchsubmitted by Filip Rembiałkowski.Discussion:https://postgr.es/m/17822.1564186806@sss.pgh.pa.us1 parent45aaaa4 commitbb5ae8f
File tree
3 files changed
+250
-89
lines changed- doc/src/sgml/ref
- src
- backend/commands
- test/isolation/expected
3 files changed
+250
-89
lines changedLines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
94 | 94 |
| |
95 | 95 |
| |
96 | 96 |
| |
97 |
| - | |
98 |
| - | |
99 |
| - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
100 | 100 |
| |
101 | 101 |
| |
102 | 102 |
| |
|
0 commit comments
Comments
(0)