Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SQL Server IndexOf translation and change tests to use Where #28031

Merged
merged 2 commits into from
May 23, 2022

Conversation

roji
Copy link
Member

@roji roji commented May 16, 2022

After the discussion in #1625, it turns out the Npgsql provider didn't implement IndexOf with starting position (see #25396), but this didn't surface because the relevant test was calling the function in the top-most projection, and not in a Where clause (so it was client-evaled).

Changed the IndexOf/Replace tests to use Where - we should avoid testing translations in top-most projections except where we specifically need to test materialization etc.

Also tweaked SQL Server IndexOf translation to be better with constants.

@roji
Copy link
Member Author

roji commented May 16, 2022

OK, I see we have some duplication of testing between NorthwindWhere and NorthwindFunctions (e.g. Where_string_index_of)... Am I unaware of some reason we want to test the same function once in Where and once in top-most Select?

@smitpatel
Copy link
Member

Am I unaware of some reason we want to test the same function once in Where and once in top-most Select?

No hard-line about it but as you noticed. When we want to test exact translation we do Where and when we want to test that it works on client eval we do Select. In a way doing both gives providers possibility to check out if they don't have translation available. For functions where translation is available in all providers (generally through relational layer), we just do where.

@@ -443,7 +443,10 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress

if (startIndex is not null)
{
charIndexArguments.Add(_sqlExpressionFactory.Add(startIndex, _sqlExpressionFactory.Constant(1)));
charIndexArguments.Add(
startIndex is SqlConstantExpression { Value : int constantStartIndex }
Copy link
Member

Choose a reason for hiding this comment

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

nice, didn't know about this nested declaration.

Copy link
Member

Choose a reason for hiding this comment

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

To avoid this kind of missing things, probably we should do this as optimization in post-translation phase (arithmetic between 2 constant operations), can you file an issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah pattern matching has made some nice progress :)

#28036

@roji roji merged commit d6aba24 into dotnet:main May 23, 2022
@roji roji deleted the IndexOfTests branch May 23, 2022 08:15
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.

2 participants