Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lnkuiper
Copy link
Collaborator

Fixes https://github.com/duckdblabs/duckdb-internal/issues/5975

The offending lines are just under if (!op.perform_delim) {, which assume that op.correlated_columns[0] is the delim_index, but the test case that I've added has a different column there. I've fixed this by looping through the columns to find the delim_index, and now the test succeeds.

Not sure if this is the right way to do it @kryonix

@kryonix
Copy link
Contributor

kryonix commented Sep 23, 2025

The !op.perform_delim case is always used when the system detects correlation with hard to duplicate eliminate types string, list, etc. In that case, the window function is pushed instead of doing the deduplication. In the existing test cases, it was always the case, that the window function and corresponding correlated column was added as the first element. Therefore the code just assumed, that we always have to just consider the first column.

I think your fix is sane, because we can assume that the order of correlated columns remains unchanged. As there might be multiple "delim_index"es, the linear scan should preserve the intended semantics—I think.

@lnkuiper
Copy link
Collaborator Author

Thanks for the feedback! I understand the problem a bit better now, and I've created a wrapper instead:

struct CorrelatedColumns {
private:
	using container_type = vector<CorrelatedColumnInfo>;

public:
	CorrelatedColumns() : delim_index(1ULL << 63) {
	}

	void AddColumn(container_type::value_type info) {
		// Add to beginning
		correlated_columns.insert(correlated_columns.begin(), std::move(info));
		delim_index++;
	}

	void SetDelimIndexToZero() {
		delim_index = 0;
	}

	idx_t GetDelimIndex() const {
		return delim_index;
	}

	// ...

private:
	container_type correlated_columns;
	idx_t delim_index;
};

This keeps track of how the delim_index is pushed around the vector, which seems to work as it passes the test.

@duckdb-draftbot duckdb-draftbot marked this pull request as draft September 24, 2025 08:35
@lnkuiper lnkuiper marked this pull request as ready for review September 24, 2025 11:07
@Mytherin Mytherin merged commit 8f570dd into duckdb:v1.4-andium Sep 25, 2025
98 checks passed
@Mytherin
Copy link
Collaborator

Thanks!

@lnkuiper lnkuiper deleted the internal_issue_5975 branch September 26, 2025 07:12
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants