Rewrite the rbtree routines so that an RBNode is the first field of the
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 1 Aug 2010 02:12:42 +0000 (02:12 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 1 Aug 2010 02:12:42 +0000 (02:12 +0000)
commit0454f131616ecafcc9289da919ab9acdabd0aad7
treeb6c3826d75e6da94f6e8ff82dbdf36ee9133d2b7
parentafc2900ffd988a858aeab896f028a4fee549cbc9
Rewrite the rbtree routines so that an RBNode is the first field of the
struct representing a tree entry, rather than being a separately allocated
piece of storage.  This API is at least as clean as the old one (if not
more so --- there were some bizarre choices in there) and it permits a
very substantial memory savings, on the order of 2X in ginbulk.c's usage.

Also, fix minor memory leaks in code called by ginEntryInsert, in
particular in ginInsertValue and entryFillRoot, as well as ginEntryInsert
itself.  These leaks resulted in the GIN index build context continuing
to bloat even after we'd filled it to maintenance_work_mem and started
to dump data out to the index.

In combination these fixes restore the GIN index build code to honoring
the maintenance_work_mem limit about as well as it did in 8.4.  Speed
seems on par with 8.4 too, maybe even a bit faster, for a non-pathological
case in which HEAD was formerly slower.

Back-patch to 9.0 so we don't have a performance regression from 8.4.
src/backend/access/gin/ginbtree.c
src/backend/access/gin/ginbulk.c
src/backend/access/gin/ginentrypage.c
src/backend/access/gin/ginfast.c
src/backend/access/gin/gininsert.c
src/backend/utils/misc/rbtree.c
src/include/access/gin.h
src/include/utils/rbtree.h