Skip to content

Commit d2839f4

Browse files
committed
Add information about parameterized collection padding (#5092)
1 parent d0eb41a commit d2839f4

File tree

1 file changed

+12
-2
lines changed
  • entity-framework/core/what-is-new/ef-core-10.0

1 file changed

+12
-2
lines changed

entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,19 @@ FROM [Blogs] AS [b]
291291
WHERE [b].[Id] IN (@ids1, @ids2, @ids3)
292292
```
293293

294-
This allows the collection values to change without resulting in different SQLs - solving the plan cache problem - but at the same time provides the query planner with information on the collection cardinality. Since different cardinalities still cause different SQLs to be generated, the final version of EF 10 will include a "bucketization" feature, where e.g. 10 parameters are sent even when the user only specifies 8, to reduce the SQL variations and optimize the query cache.
294+
This allows the collection values to change without resulting in different SQLs - solving the plan cache problem - but at the same time provides the query planner with information on the collection cardinality.
295295

296-
Unfortunately, parameterized collections are a case where EF simply cannot always make the right choice: selecting between multiple parameters (the new default), a single JSON array parameter or multiple inlined constants can require knowledge about the data in your database, and different choices may work better for different queries. As a result, EF exposes full control to the user to control the translation strategy, both at the global configuration level:
296+
Since different cardinalities still cause different SQLs to be generated, EF also "pads" parameter list. For example, if your `ids` list contains 8 values, EF generates SQL with 10 parameters:
297+
298+
```sql
299+
SELECT [b].[Id], [b].[Name]
300+
FROM [Blogs] AS [b]
301+
WHERE [b].[Id] IN (@ids1, @ids2, @ids3, @ids4, @ids5, @ids6, @ids7, @ids8, @ids9, @ids10)
302+
```
303+
304+
The last two parameters `@ids9` and `@ids10` are added by EF to reduce the number of SQLs generated, and contain the same value as `@ids8`, so that the query returns the same result.
305+
306+
Unfortunately, parameterized collections are a case where EF simply cannot always make the right choice: selecting between multiple parameters (the new default), a single JSON array parameter (with e.g. SQL Server `OPENJSON`) or multiple inlined constants can require knowledge about the data in your database, and different choices may work better for different queries. As a result, EF exposes full control to the user to control the translation strategy, both at the global configuration level:
297307

298308
```c#
299309
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

0 commit comments

Comments
 (0)