• Tom Lane's avatar
    Improve some O(N^2) behavior in window function evaluation. · e0c91a7f
    Tom Lane authored
    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.
    e0c91a7f
tuplestore.h 3.23 KB