8000 Share null mask with constant null arg vector by iceTTTT · Pull Request #17234 · duckdb/duckdb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Share null mask with constant null arg vector #17234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 1, 2025
Merged

Conversation

iceTTTT
Copy link
Contributor
@iceTTTT iceTTTT commented Apr 24, 2025

Fixes #17217

When the constant_or_null function encounters a constant NULL input, it will set the null mask of result vector for row 0 to invalid.

If the null mask is shared with other function arg vector (due to a previous Combine() call), modifying the null mask for row 0 would incorrectly affect the arg vector. This leads to wrong query result.

Share the null mask with the constant NULL arg vector should fix the issue.

@duckdb-draftbot duckdb-draftbot marked this pull request as draft April 24, 2025 12:26
@iceTTTT iceTTTT changed the title deep copy validity mask before set null share null mask with constant null arg vector Apr 24, 2025
@iceTTTT iceTTTT marked this pull request as ready for review April 24, 2025 12:31
@iceTTTT iceTTTT changed the title share null mask with constant null arg vector Share null mask with constant null arg vector Apr 25, 2025
Copy link
Collaborator
@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Looks good - but perhaps it would be better to remove the reference altogether in this case:

@@ -43,6 +43,9 @@ static void ConstantOrNullFunction(DataChunk &args, ExpressionState &state, Vect
if (ConstantVector::IsNull(args.data[idx])) {
// input is constant null, return constant null
result.Reference(info.value);
auto &result_mask = ConstantVector::Validity(result);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove the reference altogether, and just set the result to a constant NULL? (i.e. result.SetVectorType(VectorType::CONSTANT_VECTOR);)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I've updated the code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The Initialize should not also not be necessary anymore now, i.e. we just need the two lines (SetVectorType and ConstantVector::SetNull).

Copy link
Contributor Author
@iceTTTT iceTTTT May 1, 2025

Choose a reason for hiding this comment

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

The constant_or_null function may accept three or more inputs (e.g., constant_or_null(true, c1, c2)).
In cases where: c1 is a flat vector, and c2 is a constant vector :
we first access c1 and share its mask with the result through result_mask.Combine(input_mask).

Later, when we access c2 and find it's a constant null. If we simply call SetNull at this stage, it would corrupt c1's mask (since we're still sharing c1's mask state from the earlier Combine operation).

So we should call Initialize to switch the mask reference to c2's mask (the constant null vector) before calling SetNull.And c2 will not be affected because it's already null.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see - makes sense. Thanks!

@duckdb-draftbot duckdb-draftbot marked this pull request as draft April 30, 2025 16:46
@iceTTTT iceTTTT marked this pull request as ready for review April 30, 2025 16:48
@iceTTTT iceTTTT requested a review from Mytherin May 1, 2025 08:14
@Mytherin Mytherin merged commit b641478 into duckdb:main May 1, 2025
48 of 49 checks passed
@Mytherin
Copy link
Collaborator
Mytherin commented May 1, 2025

Thanks!

krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 18, 2025
Share null mask with constant null arg vector (duckdb/duckdb#17234)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 18, 2025
Share null mask with constant null arg vector (duckdb/duckdb#17234)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 19, 2025
Share null mask with constant null arg vector (duckdb/duckdb#17234)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 19, 2025
Share null mask with constant null arg vector (duckdb/duckdb#17234)
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.

Wrong inner Join result
2 participants
0