summaryrefslogtreecommitdiff
path: root/src/include/utils/tuplestore.h
diff options
context:
space:
mode:
authorTom Lane2014-04-13 17:59:17 +0000
committerTom Lane2014-04-13 17:59:17 +0000
commite0c91a7ff015fab0ccbb0f75b6819f29ae00295e (patch)
tree77fefd1afb935e9fd742261f14d660eeeb21de1e /src/include/utils/tuplestore.h
parent46a60abfe9fa13087dbbe15953c20df35f006968 (diff)
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.
Diffstat (limited to 'src/include/utils/tuplestore.h')
-rw-r--r--src/include/utils/tuplestore.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/include/utils/tuplestore.h b/src/include/utils/tuplestore.h
index 1e22feecee8..16eca871cd1 100644
--- a/src/include/utils/tuplestore.h
+++ b/src/include/utils/tuplestore.h
@@ -72,8 +72,12 @@ extern bool tuplestore_in_memory(Tuplestorestate *state);
extern bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward,
bool copy, TupleTableSlot *slot);
+
extern bool tuplestore_advance(Tuplestorestate *state, bool forward);
+extern bool tuplestore_skiptuples(Tuplestorestate *state,
+ int64 ntuples, bool forward);
+
extern bool tuplestore_ateof(Tuplestorestate *state);
extern void tuplestore_rescan(Tuplestorestate *state);