Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dsql/Nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,8 @@ class AggNode : public TypedNode<ValueExprNode, ExprNode::TYPE_AGGREGATE>
static constexpr unsigned CAP_WANTS_AGG_CALLS = 0x04;
// wants winPass call in a window
static constexpr unsigned CAP_WANTS_WIN_PASS_CALL = 0x08;
// depends on the window frame boundaries, even when not respecting a user-defined frame
static constexpr unsigned CAP_USES_WINDOW_FRAME = 0x10;

protected:
struct AggInfo
Expand Down
2 changes: 1 addition & 1 deletion src/dsql/WinNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class CumeDistWinNode final : public WinFuncNode

unsigned getCapabilities() const override
{
return CAP_SUPPORTS_WINDOW_FRAME | CAP_WANTS_WIN_PASS_CALL;
return CAP_SUPPORTS_WINDOW_FRAME | CAP_USES_WINDOW_FRAME | CAP_WANTS_WIN_PASS_CALL;
}

void getChildren(NodeRefsHolder& holder, bool dsql) const override
Expand Down
5 changes: 5 additions & 0 deletions src/jrd/recsrc/AggregatedStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ bool BaseAggWinStream<ThisType, NextType>::evaluateGroup(thread_db* tdbb) const
}
}
else
{
cacheValues(tdbb, request, m_group, impure->groupValues, DummyAdjustFunctor());
static_cast<const ThisType*>(this)->groupRecord(tdbb, request, true);
}

// Loop thru records until either a value change or EOF

Expand All @@ -193,6 +196,8 @@ bool BaseAggWinStream<ThisType, NextType>::evaluateGroup(thread_db* tdbb) const

if (lookForChange(tdbb, request, m_group, NULL, impure->groupValues))
impure->state = STATE_FETCHED;
else
static_cast<const ThisType*>(this)->groupRecord(tdbb, request, false);
}
else
impure->state = STATE_EOF;
Expand Down
20 changes: 20 additions & 0 deletions src/jrd/recsrc/RecordSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,12 @@ namespace Jrd
protected:
void internalGetPlan(thread_db* tdbb, PlanEntry& planEntry, unsigned level, bool recurse) const override;
bool internalGetRecord(thread_db* tdbb) const override;

public:
// Called by evaluateGroup for each record that belongs to the group being evaluated.
void groupRecord(thread_db* /*tdbb*/, Request* /*request*/, bool /*first*/) const
{
}
};

class WindowedStream : public RecordSource
Expand Down Expand Up @@ -1143,6 +1149,14 @@ namespace Jrd
SINT64 partitionPending, rangePending;
Block partitionBlock, windowBlock;
impure_value_ex startOffset, endOffset;

// Last positions of the peer groups of the partition, found when it is evaluated.
// Bit n is set when the record at position peerBase + n ends its peer group.
FB_UINT64* peerBits;
ULONG peerCapacity; // allocated words
ULONG peerUsed; // words that may have bits set
SINT64 peerBase;
bool peerOverflow; // the partition is too big for the bitmap
};

public:
Expand All @@ -1161,6 +1175,8 @@ namespace Jrd
bool isDependent(const StreamList& streams) const override;
void nullRecords(thread_db* tdbb) const override;

void groupRecord(thread_db* tdbb, Request* request, bool first) const;

protected:
void internalGetPlan(thread_db* tdbb, PlanEntry& planEntry, unsigned level, bool recurse) const override;
void internalOpen(thread_db* tdbb) const override;
Expand All @@ -1186,6 +1202,8 @@ namespace Jrd
SINT64 locateFrameGroups(thread_db* tdbb, Request* request, Impure* impure,
const Frame* frame, const impure_value_ex* offsetValue, SINT64 position,
bool startFrame) const;
SINT64 locatePeerGroupEnd(thread_db* tdbb, Request* request, Impure* impure,
SINT64 position) const;

private:
NestConst<SortNode> m_order;
Expand All @@ -1196,6 +1214,8 @@ namespace Jrd
NestValueArray m_winPassSources, m_winPassTargets;
Exclusion m_exclusion;
UCHAR m_invariantOffsets; // 0x1 | 0x2 bitmask
bool m_needsFrame = false; // some function depends on the frame
bool m_usesPeerGroupEnd = false; // peer group ends are found when evaluating the partition
};

public:
Expand Down
Loading
Loading