Skip to content

Do not use null when padding parameter collection buckets - #39756

Open
lqkhanh295 wants to merge 4 commits into
dotnet:mainfrom
lqkhanh295:fix/parameter-collection-padding-null-last
Open

lqkhanh295 wants to merge 4 commits into
dotnet:mainfrom
lqkhanh295:fix/parameter-collection-padding-null-last

Conversation

@lqkhanh295

Copy link
Copy Markdown

Fixes #39705

Description

In SqlNullabilityProcessor.ProcessInExpressionValues, parameterized collections under ParameterTranslationMode.MultipleParameters add padding up to the bucket size by repeating values[^1]. When removeNulls is true and the last element of the input collection is null, null was used as the padding value, adding NULL parameters to the IN list. For a negated Contains (NOT IN), having a NULL parameter in SQL means x NOT IN (..., NULL) evaluates to unknown/false, so no rows are returned.

This change uses the last non-null value from the collection for bucket padding when removeNulls is true. If all elements in the collection were null, padding is skipped so that case [] can simplify the expression (item IS NULL or false).

Added regression tests in PrimitiveCollectionsQueryRelationalTestBase and PrimitiveCollectionsQuerySqliteTest.

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow the required format
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

Copilot AI balanced review requested due to automatic review settings November 21, 2026 19:00
@lqkhanh295
lqkhanh295 requested a review from a team as a code owner November 21, 2026 19:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@cincuranet cincuranet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lqkhanh295 Also add test where all values are null.

@cincuranet cincuranet self-assigned this Nov 25, 2026
Copilot AI balanced review requested due to automatic review settings November 25, 2026 11:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lqkhanh295

Copy link
Copy Markdown
Author

@cincuranet Added Parameter_collection_Contains_all_null_values_with_bucket_padding (covering both non-nullable and nullable columns) along with the missing SQL Server test overrides that Check_all_tests_overridden caught.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Reusing the filtered and padded IN expansion as the original collection corrupts later count operations, returning 0 instead of 1 for a null match.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 25, 2026 14:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

- In SqlNullabilityProcessor.ProcessInExpressionValues, bucket padding was repeating values[^1]. When removeNulls was true and the last element of the collection was null, null parameters were added as padding, turning negated Contains into NOT IN (..., NULL) which matches no rows.
- Use the last non-null value from the collection for bucket padding when removeNulls is true, or skip padding if all elements were null so case [] can handle it.
- Added regression tests in PrimitiveCollectionsQueryRelationalTestBase and SQLite functional tests.

Fixes dotnet#39705
@lqkhanh295
lqkhanh295 force-pushed the fix/parameter-collection-padding-null-last branch from 51f341e to 06ecb7e Compare November 25, 2026 15:25
Copilot AI balanced review requested due to automatic review settings November 25, 2026 15:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the collection-padding fix.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 27, 2026 13:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

Negated Contains over a parameter collection ending in null returns no rows on SQL Server

3 participants