Skip to content

Conversation

cincuranet
Copy link
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
Copy link

@Copilot Copilot AI left a comment

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

Copy link
Member

@roji roji left a comment

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.

@@ -857,6 +846,38 @@ InExpression ProcessInExpressionValues(
throw new UnreachableException();
}
}

// Bucketization is a process used to group parameters into "buckets" of a fixed size when generating parameterized collections.
Copy link
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
7 checks passed
@cincuranet cincuranet deleted the buckets branch July 28, 2025 15:16
@@ -280,6 +282,19 @@ protected override SqlExpression VisitIn(InExpression inExpression, bool allowOp
}
}

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

@IanKemp IanKemp Jul 28, 2025

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

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
4 participants