Re: brininsert optimization opportunity
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Tomas Vondra <tomas.vondra@enterprisedb.com>
Cc: Alexander Lakhin <exclusion@gmail.com>, Soumyadeep Chakraborty <soumyadeep2007@gmail.com>,
Matthias van de Meent <boekewurm+postgres@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>,
Ashwin Agrawal <ashwinstar@gmail.com>
Date: 2024-01-08T15:51:22Z
Lists: pgsql-hackers
On 2023-Dec-12, Tomas Vondra wrote: > I propose we do a much simpler thing instead - allow the cache may be > initialized / cleaned up repeatedly, and make sure it gets reset at > convenient place (typically after index_insert calls that don't go > through execIndexing). That'd mean the cleanup does not need to happen > very far from the index_insert(), which makes the reasoning much easier. > 0002 does this. I'm not in love with this 0002 patch; I think the layering after 0001 is correct in that the insert_cleanup call should remain in validate_index and called after the whole thing is done, but 0002 changes things so that now every table AM has to worry about doing this correctly; and a bug of omission will not be detected unless you have a BRIN index on such a table and happen to use CREATE INDEX CONCURRENTLY. So a developer has essentially zero chance to do things correctly, which I think we'd rather avoid. So I think we should do 0001 and perhaps some further tweaks to the original brininsert optimization commit: I think the aminsertcleanup callback should receive the indexRelation as first argument; and also I think it's not index_insert_cleanup() job to worry about whether ii_AmCache is NULL or not, but instead the callback should be invoked always, and then it's aminsertcleanup job to do nothing if ii_AmCache is NULL. That way, the index AM API doesn't have to worry about which parts of IndexInfo (or the indexRelation) is aminsertcleanup going to care about. If we decide to change this, then the docs also need a bit of tweaking I think. Lastly, I kinda disagree with the notion that only some of the callers of aminsert should call aminsertcleanup, even though btree doesn't have an aminsertcleanup and thus it can't affect TOAST or catalogs. Maybe we can turn index_insert_cleanup into an inline function, which can quickly do nothing if aminsertcleanup isn't defined. Then we no longer have the layering violation where we assume that btree doesn't care. But the proposed change in this paragraph can be maybe handled separately to avoid confusing things with the bugfix in the two paragraphs above. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ Essentially, you're proposing Kevlar shoes as a solution for the problem that you want to walk around carrying a loaded gun aimed at your foot. (Tom Lane)
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add missing index_insert_cleanup calls
- 41d2c6f952ed 17.0 landed
-
Fix a couple typos in BRIN code
- 95d14b7ae26d 17.0 landed
-
Check if ii_AmCache is NULL in aminsertcleanup
- a82ee7ef3aac 17.0 landed
-
Use fipshash in brin_multi test
- 86b64bafc19c 17.0 cited
-
Reuse BrinDesc and BrinRevmap in brininsert
- c1ec02be1d79 17.0 landed
-
Consider fillfactor when estimating relation size
- 29cf61ade3f2 17.0 cited
-
Postpone some stuff out of ExecInitModifyTable.
- c5b7ba4e67ae 14.0 cited