Install a search tree depth limit in GIN bulk-insert operations, to prevent
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 24 Mar 2009 22:06:03 +0000 (22:06 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 24 Mar 2009 22:06:03 +0000 (22:06 +0000)
commitab0ec9767579d7fe8db8cb34528c3e265911aec5
tree832403ba8f9df142f67735c51f4f93ee8b79d34e
parent7b77f24e9f26c3e5945bf819ec2860a33031d618
Install a search tree depth limit in GIN bulk-insert operations, to prevent
them from degrading badly when the input is sorted or nearly so.  In this
scenario the tree is unbalanced to the point of becoming a mere linked list,
so insertions become O(N^2).  The easiest and most safely back-patchable
solution is to stop growing the tree sooner, ie limit the growth of N.  We
might later consider a rebalancing tree algorithm, but it's not clear that
the benefit would be worth the cost and complexity.  Per report from Sergey
Burladyan and an earlier complaint from Heikki.

Back-patch to 8.2; older versions didn't have GIN indexes.
src/backend/access/gin/ginfast.c
src/backend/access/gin/gininsert.c
src/include/access/gin.h