Re: Index AM API cleanup
Peter Eisentraut <peter@eisentraut.org>
Attachments
- v17.1-0004-Add-amgettreeheight-index-AM-API-routine.patch (text/plain) patch v17-0004
On 26.08.24 17:10, Mark Dilger wrote: >> To make a dent, I picked out something that should be mostly harmless: Stop calling directly into _bt_getrootheight() (patch 0004). I think this patch is ok, but I might call the API function amgettreeheight instead of amgetrootheight. The former seems more general. > Peter, your proposed rename seems fine for the current implementation, but your suggestion below might indicate a different naming. > >> I notice that _bt_getrootheight() is called only to fill in the IndexOptInfo tree_height field, which is only used by btcostestimate(), so in some sense this is btree-internal data. But making it so that btcostestimate() calls _bt_getrootheight() directly to avoid all that intermediate business seems too complicated, and there was probably a reason that the cost estimation functions don't open the index. >> >> Interestingly, the cost estimation functions for gist and spgist also look at the tree_height field but nothing ever fills it on. So with your API restructuring, someone could provide the missing API functions for those index types. Might be interesting. >> >> That said, there might be value in generalizing this a bit. If you look at the cost estimation functions in pgvector (hnswcostestimate() and ivfflatcostestimate()), they both have this pattern that btcostestimate() tries to avoid: They open the index, look up some number, close the index, then make a cost estimate computation with the number looked up. So another idea would be to generalize the tree_height field to some "index size data" or even "internal data for cost estimation". This wouldn't need to change the API much, since these are all just integer values, but we'd label the functions and fields a bit differently. > Would they be just integers? They could also be void*, with amgetrootheight_function returning data allocated in the current memory context. For btree, that would just be a four byte integer, but other indexes could return whatever they like. If you like that idea, I can code that up for v18, naming the field something like amgetcostestimateinfo_function. Here is a cleaned-up version of the v17-0004 patch. I have applied the renaming discussed above. I have also made a wrapper function btgettreeheight() that calls _bt_getrootheight(). That way, if we ever want to change the API, we don't have to change _bt_getrootheight(), or disentangle it then. I've also added documentation and put in a source code comment that the API could be expanded for additional uses. Also, I have removed the addition to the IndexOptInfo struct; that didn't seem necessary.
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Relax ordering-related hardcoded btree requirements in planning
- a8025f544854 18.0 landed
-
Support non-btree indexes in get_actual_variable_range()
- 9ef1851685b7 18.0 landed
-
Convert PathKey to use CompareType
- 8123e91f5aeb 18.0 landed
-
Generalize index support in network support function
- be1cc9aaf5b7 18.0 landed
-
Update a code comment
- 190dc27998d5 18.0 landed
-
Allow non-btree unique indexes for matviews
- 9d6db8bec194 18.0 landed
-
Allow non-btree unique indexes for partition keys
- f278e1fe300a 18.0 landed
-
Add some opfamily support functions to lsyscache.c
- 7317e641268f 18.0 landed
-
Simplify and generalize PrepareSortSupportFromIndexRel()
- a359d3701991 18.0 landed
-
Generalize hash and ordering support in amapi
- ce62f2f2a0a4 18.0 landed
-
Drop opcintype from index AM strategy translation API
- 7d6d2c4bbd73 18.0 landed
-
Allow non-btree speculative insertion indexes
- b92c03342dcd 18.0 landed
-
Support non-btree indexes for foreign keys
- bfe21b760e03 18.0 landed
-
Integrate GistTranslateCompareType() into IndexAmTranslateCompareType()
- 622f678c1020 18.0 landed
-
Convert strategies to and from compare types
- c09e5a6a0165 18.0 landed
-
Move CompareType to separate header file
- 119fc30dd5bd 18.0 landed
-
Add get_opfamily_name() function
- 43493cceda2f 18.0 landed
-
Rename GistTranslateStratnum() to GistTranslateCompareType()
- a5709b5bb293 18.0 landed
-
Change gist stratnum function to use CompareType
- 630f9a43cece 18.0 landed
-
Rename RowCompareType to CompareType
- 6339f6468e82 18.0 landed
-
Improve slightly misleading internal error message
- 63e10988f870 18.0 landed
-
Track scan reversals in MergeJoin
- c594f1ad2ba7 18.0 landed
-
Track sort direction in SortGroupClause
- 0d2aa4d4937b 18.0 landed
-
Add stratnum GiST support function
- 7406ab623fee 18.0 cited
-
Add amgettreeheight index AM API routine
- 56fead44dcc7 18.0 landed