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 TruncateTime canonical function performance #467

Closed
wants to merge 1 commit into from

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Feb 14, 2018

Ported from CodePlex

{
if (isDateTimeOffset)
{
throw new NotSupportedException(Strings.SqlGen_CanonicalFunctionNotSupportedPriorSql10(e.Function.Name));
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a break.

Copy link
Contributor

Choose a reason for hiding this comment

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

For PreKatamai, the sql produced is CONVERT(datetimeoffset, CONVERT(VARCHAR(255), expression, 102) + ' 00:00:00 ' + Right(convert(varchar(255), @arg, 121), 6), 102), which is invalid for PreKatamai because the datetimeoffset data type didn't exist in Sql Server < 2008.

Because of this I don't believe that this is actually a break.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree this should be fine. It is also possible that this just caused an error on the server, but it is also possible that it is blocked by something upstream in the query pipeline.

Copy link
Contributor

@ajcvickers ajcvickers left a comment

Choose a reason for hiding this comment

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

We would need to understand which versions of SQL Server are broken by this change and why that's okay.

@ajcvickers ajcvickers self-assigned this Aug 14, 2018
@divega divega changed the title Improve TruncateTime canonical function performance. Improve TruncateTime canonical function performance May 8, 2019
@divega
Copy link
Contributor

divega commented May 8, 2019

I believe the original CodePlex PR was submitted by @brandondahler, in case he is interested in following up.

@brandondahler
Copy link
Contributor

Thanks for the tag, answered inline.

@ajcvickers ajcvickers requested a review from divega June 25, 2019 23:02
@ajcvickers
Copy link
Contributor

@divega This look okay to you?

Copy link
Contributor

@divega divega left a comment

Choose a reason for hiding this comment

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

@ajcvickers I think we could take it as it is, but I spent a few minutes and came back with some minor suggestions.

isDateTimeOffset = true;
}
else
if (!isDateTimeOffset && typeKind != PrimitiveTypeKind.DateTime)
{
Debug.Assert(true, "Unexpected type to TruncateTime" + typeKind.ToString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: move the condition inside the Debug.Assert call. Before this was free because it was the else part of an if we already had, but that is removed, no reason to evaluate the condition in a release build.

Copy link
Contributor

Choose a reason for hiding this comment

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

Funnily enough, Debug.Assert(true, ...) is also a GNDN. Will be properly fixed as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Missed that.

{
result.Append("+ ' 00:00:00 ' + Right(convert(varchar(255), ");
if (!isDateTimeOffset)
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer code clarity: I don't think the few lines that are common are worth the entanglement of the two translations.

@@ -514,7 +514,7 @@ public void CanonicalFunction_truncatetime_translated_properly_to_sql_function()
using (var context = GetArubaCeContext())
{
var query = context.CreateQuery<DateTime>(@"SELECT VALUE Edm.TruncateTime(A.c5_datetime) FROM ArubaCeContext.AllTypes AS A");
Assert.Contains("CONVERT", query.ToTraceString().ToUpperInvariant());
Assert.Contains("DATEADD(D, DATEDIFF(D,", query.ToTraceString().ToUpperInvariant());
Copy link
Contributor

Choose a reason for hiding this comment

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

We only have canonical function tests for SQL CE? 🤦‍♂️ Glad we have coverage for this in https://github.com/aspnet/EntityFramework6/blob/master/test/EntityFramework/FunctionalTests/ProductivityApi/DbFunctionScenarios.cs.

@brandondahler
Copy link
Contributor

Changes made in https://github.com/brandondahler/EntityFramework6/tree/truncate_time, unable to actually update this pull request because it migrated from @maumar from CodePlex.

Let me know if you'd like me to open a new PR or if one of the members of the repository will take care of it. Was able to find a good place to put a net-new test for the updated code.

@divega
Copy link
Contributor

divega commented Jun 27, 2019

I think a new PR would be good. That way the commits will be correctly assigned to you.

@divega
Copy link
Contributor

divega commented Jun 27, 2019

Superseded by #948.

@divega divega closed this Jun 27, 2019
@ajcvickers ajcvickers deleted the truncate_time branch April 22, 2021 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants