Skip to content

Commit 641a51c

Browse files
committed
Postgresql 9.0+: Better version of IntervalToMilliseconds expression
Based on epoch extraction, it is less complicated than sum of several parts expecially when base expression is complicated so it required many copies of base expression. New approach is also lest costy.
1 parent 4d4bfb9 commit 641a51c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v8_0/Compiler.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public override void Visit(SqlFunctionCall node)
122122
((node.Arguments[0] / SqlDml.Literal(nanosecondsPerSecond)) * OneSecondInterval).AcceptVisitor(this);
123123
return;
124124
case SqlFunctionType.IntervalToMilliseconds:
125-
SqlHelper.IntervalToMilliseconds(node.Arguments[0]).AcceptVisitor(this);
125+
VisitIntervalToMilliseconds(node);
126126
return;
127127
case SqlFunctionType.IntervalToNanoseconds:
128128
SqlHelper.IntervalToNanoseconds(node.Arguments[0]).AcceptVisitor(this);
@@ -296,6 +296,11 @@ public override void Visit(SqlCustomFunctionCall node)
296296
base.Visit(node);
297297
}
298298

299+
protected virtual void VisitIntervalToMilliseconds(SqlFunctionCall node)
300+
{
301+
SqlHelper.IntervalToMilliseconds(node.Arguments[0]).AcceptVisitor(this);
302+
}
303+
299304
private static SqlExpression DateTimeToStringIso(SqlExpression dateTime, in string isoFormat) =>
300305
SqlDml.FunctionCall("TO_CHAR", dateTime, isoFormat);
301306

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v9_0/Compiler.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
// Created by: Denis Krjuchkov
55
// Created: 2012.06.06
66

7+
using Xtensive.Sql.Dml;
8+
79
namespace Xtensive.Sql.Drivers.PostgreSql.v9_0
810
{
911
internal class Compiler : v8_4.Compiler
1012
{
1113
// Constructors
14+
protected override void VisitIntervalToMilliseconds(SqlFunctionCall node)
15+
{
16+
AppendSpaceIfNecessary();
17+
_ = context.Output.Append("(EXTRACT(EPOCH FROM (");
18+
node.Arguments[0].AcceptVisitor(this);
19+
_ = context.Output.Append(")) * 1000)");
20+
21+
}
1222

1323
public Compiler(SqlDriver driver)
1424
: base(driver)

0 commit comments

Comments
 (0)