You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query: Translate Enumerable.Contains() with byte arrays #4601
We should translate Enumerable.Contains() for byte arrays, but when we do, we should be careful to update our SQL caching code:
We found while working on caching of FromSql() queries that we are special casing byte arrays so we skip structural comparisons for byte arrays (and also strings and object arrays) when comparing query cache entries. This probably because normally we treat byte arrays as a primitive type throughout our stack but for the case of using a byte array with Enumerable.Contains() each element in the byte array will become a literal in the SQL so we should consider it a different cache entry.
We should also understand if this can be a scenario for strings and object arrays.
A potential fix would be to swap to an approach that special cases Enumerable.Contains() so that we account for the fact that its first argument will not be parameterized.
@anpete@mikary could you please check what is the impact of the bug? I wonder if subsequent queries will just reuse the SQL from the first query, returning incorrect results or if it is something more benign.
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
The same operation with an int array produces two different cache entries:
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[OrderID] IN (1, 2, 3)
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[OrderID] IN (4, 5, 6)
changed the title [-]Query: Enumerable.Contains() with byte arrays[/-][+]Query: Enumerable.Contains() with byte arrays forces client eval[/+]on Feb 19, 2016
changed the title [-]Query: Enumerable.Contains() with byte arrays forces client eval[/-][+]Query: Translate Enumerable.Contains() with byte arrays[/+]on Feb 19, 2016
Activity
divega commentedon Feb 18, 2016
@anpete @mikary could you please check what is the impact of the bug? I wonder if subsequent queries will just reuse the SQL from the first query, returning incorrect results or if it is something more benign.
mikary commentedon Feb 19, 2016
Attempted to produce a false positive on the caching and it appears we client eval contains with byte arrays
The same operation with an int array produces two different cache entries:
mikary commentedon Feb 19, 2016
Opened #4605 to track caching and cache pollution aspect of this issue.
Updating this issue to address byte array client evaluation.
[-]Query: Enumerable.Contains() with byte arrays[/-][+]Query: Enumerable.Contains() with byte arrays forces client eval[/+][-]Query: Enumerable.Contains() with byte arrays forces client eval[/-][+]Query: Translate Enumerable.Contains() with byte arrays[/+]Support Contains on byte arrays
Support Contains on byte arrays
1 remaining item
Support Contains on byte arrays
Support Contains on byte arrays
Support Contains on byte arrays on Sqlite
Support Contains on byte arrays on Sqlite
Support Contains on byte arrays on Sqlite
Support Contains on byte arrays on Sqlite