Skip to content

Conversation

Mytherin
Copy link
Collaborator

@Mytherin Mytherin commented Apr 8, 2023

This PR reworks how order-dependence of operators are tracked in pipelines - specifically, it adds an enum OrderPreservationType that tracks in which way operators emit/preserve order:

enum class OrderPreservationType : uint8_t {
	NO_ORDER,
	INSERTION_ORDER,
	FIXED_ORDER
};

The goal of this is to distinguish between operators that merely emit or maintain insertion order (e.g. table scans), and operators that emit a fixed order that must be maintained (e.g. ORDER BY, top-n). This fixes an issue found by @pdet (and also encountered in the test suite when increasing parallelism of aggregate scans) where ORDER BY information was incorrectly lost when preserve_insertion_order was set to false.

In addition in this PR we create separate more clear methods for order dependence depending on the stage of the operator: SinkOrderDependent, OperatorOrder and SourceOrder.

@Mytherin Mytherin requested a review from lnkuiper April 8, 2023 08:54
Copy link
Contributor

@lnkuiper lnkuiper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to distinguish between insertion order and the fixed order that an operator should return data in! LGTM

bool IsOrderPreserving() const override {
return true;
OrderPreservationType SourceOrder() const override {
return OrderPreservationType::NO_ORDER;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PhysicalWindow does not have batch indices, but maybe it should?

Not something to fix in this PR, but it would be nice to guarantee that the result of a window is returned with the groups together, and in order, and then this can be changed to FIXED_ORDER.

@Mytherin Mytherin merged commit 846a32b into duckdb:master Apr 10, 2023
@Mytherin Mytherin deleted the reworkorder branch April 24, 2023 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants