]> granicus.if.org Git - postgresql/commit
Improve some O(N^2) behavior in window function evaluation.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 13 Apr 2014 17:59:17 +0000 (13:59 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 13 Apr 2014 17:59:17 +0000 (13:59 -0400)
commite0c91a7ff015fab0ccbb0f75b6819f29ae00295e
tree77fefd1afb935e9fd742261f14d660eeeb21de1e
parent46a60abfe9fa13087dbbe15953c20df35f006968
Improve some O(N^2) behavior in window function evaluation.

Repositioning the tuplestore seek pointer in window_gettupleslot() turns
out to be a very significant expense when the window frame is sizable and
the frame end can move.  To fix, introduce a tuplestore function for
skipping an arbitrary number of tuples in one call, parallel to the one we
introduced for tuplesort objects in commit 8d65da1f.  This reduces the cost
of window_gettupleslot() to O(1) if the tuplestore has not spilled to disk.
As in the previous commit, I didn't try to do any real optimization of
tuplestore_skiptuples for the case where the tuplestore has spilled to
disk.  There is probably no practical way to get the cost to less than O(N)
anyway, but perhaps someone can think of something later.

Also fix PersistHoldablePortal() to make use of this API now that we have
it.

Based on a suggestion by Dean Rasheed, though this turns out not to look
much like his patch.
src/backend/commands/portalcmds.c
src/backend/executor/nodeWindowAgg.c
src/backend/utils/sort/tuplestore.c
src/include/utils/tuplestore.h