Skip to content

Bucketization for IN - #36370

Merged
cincuranet merged 2 commits into
dotnet:mainfrom
cincuranet:buckets
Jul 28, 2025
Merged

cincuranet merged 2 commits into
dotnet:mainfrom
cincuranet:buckets

Conversation

@cincuranet

Copy link
Copy Markdown
Contributor

Closes #36364.

@cincuranet
cincuranet force-pushed the buckets branch 4 times, most recently from 082b50e to d419b79 Compare July 15, 2025 09:10
@cincuranet
cincuranet marked this pull request as ready for review July 15, 2025 10:01
@cincuranet
cincuranet requested a review from a team as a code owner July 15, 2025 10:01
@cincuranet
cincuranet requested a review from roji July 15, 2025 10:01

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.

Pull Request Overview

This PR implements bucketization for IN-clause parameters to pad parameter lists to fixed sizes, reducing plan cache bloat, and updates tests to expect the new padded parameter counts.

  • Introduces bucketization logic in SqlNullabilityProcessor and a ParametersPadFactor strategy
  • Adds a helper ExpandParameterIfNeeded to consolidate parameter expansion code
  • Defines MaxParameterCount constant in SqlServerSqlNullabilityProcessor and updates the over-limit check
  • Updates/extends provider-specific functional tests to assert on the padded parameter lists
  • Adds a new relational baseline test for Parameter_collection_Contains_parameter_bucketization

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/EFCore.Relational/Query/SqlNullabilityProcessor.cs Added bucketization code, ParametersPadFactor, and ExpandParameterIfNeeded
src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs Introduced MaxParameterCount constant and replaced hardcoded threshold
test/EFCore.Relational.Specification.Tests/Query/NonSharedPrimitiveCollectionsQueryRelationalTestBase.cs Added new Parameter_collection_Contains_parameter_bucketization test
test/EFCore.Sqlite.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqliteTest.cs Updated expected SQL for padded parameters in SQLite tests
test/EFCore.SqlServer.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqlServerTest.cs Updated expected SQL for padded parameters in SQL Server tests
test/EFCore.Sqlite.FunctionalTests/... (GearsOfWarQuerySqliteTest.cs) Adjusted IN lists to include padded parameters
test/EFCore.SqlServer.FunctionalTests/... (GearsOfWarQuerySqlServerTest.cs, etc.) Adjusted IN lists to include padded parameters
test/EFCore.SqlServer.FunctionalTests/... (Northwind*QuerySqlServerTest.cs) Adjusted IN lists to include padded parameters
test/EFCore.SqlServer.FunctionalTests/Query/AdHocMiscellaneousQuerySqlServerTest.cs Updated a multi-IN clause to include padded date-time parameters

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks pretty straightforward and good! See some suggestions and one possible bug.

}
}

// Bucketization is a process used to group parameters into "buckets" of a fixed size when generating parameterized collections.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's... substantial :)

@cincuranet
cincuranet merged commit 069fc1f into dotnet:main Jul 28, 2025
@cincuranet
cincuranet deleted the buckets branch July 28, 2025 15:16

/// <inheritdoc />
protected override int CalculateParameterBucketSize(int count, RelationalTypeMapping elementTypeMapping)
=> count switch

@IanKemp IanKemp Jul 28, 2025 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  1. Is there any particular reason why the conditions of this switch differ from those in the same-named method in src/EFCore.Relational/Query/SqlNullabilityProcessor.cs?
  2. If the answer to the previous question is "no", can/should the two methods be consolidated into an abstraction that can be injected and used in both cases?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

NVM ignore me, this is the MSSQL-specific implementation.

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.

Bucketization for IN

5 participants