Skip to content

Commit 5962d84

Browse files
committed
string.Intern is applied to command texts only if domain uses parameters for type identifiers
this reduces number of string variations
1 parent 04a77f9 commit 5962d84

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

Orm/Xtensive.Orm/Orm/Providers/StorageDriver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2009-2022 Xtensive LLC.
1+
// Copyright (C) 2009-2025 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Denis Krjuchkov
@@ -84,6 +84,7 @@ public SqlCompilationResult Compile(ISqlCompileUnit statement)
8484
var options = new SqlCompilerConfiguration {
8585
DatabaseQualifiedObjects = configuration.IsMultidatabase,
8686
CommentLocation = configuration.TagsLocation.ToCommentLocation(),
87+
TypeIndentifiersAsParameters = configuration.PreferTypeIdsAsQueryParameters
8788
};
8889
return underlyingDriver.Compile(statement, options);
8990
}

Orm/Xtensive.Orm/Sql/Compiler/SqlCompilationResult.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44

55
using System;
66
using System.Collections.Generic;
@@ -15,6 +15,7 @@ public sealed class SqlCompilationResult
1515
private readonly IReadOnlyList<Node> resultNodes;
1616
private readonly string resultText;
1717
private readonly IDictionary<object, string> parameterNames;
18+
private readonly bool internCommandResult;
1819
private volatile int lastResultLength;
1920

2021
/// <inheritdoc/>
@@ -59,16 +60,18 @@ public string GetCommandText()
5960
public string GetCommandText(SqlPostCompilerConfiguration configuration)
6061
{
6162
if (resultText!=null)
62-
return string.Intern(resultText);
63-
string result = string.Intern(PostCompiler.Process(resultNodes, configuration, lastResultLength));
63+
return (internCommandResult) ? string.Intern(resultText) : resultText;
64+
string result = PostCompiler.Process(resultNodes, configuration, lastResultLength);
65+
if (internCommandResult)
66+
result = string.Intern(result);
6467
lastResultLength = result.Length;
6568
return result;
6669
}
6770

6871

6972
// Constructors
7073

71-
internal SqlCompilationResult(IReadOnlyList<Node> result, IDictionary<object, string> parameterNames)
74+
internal SqlCompilationResult(IReadOnlyList<Node> result, IDictionary<object, string> parameterNames, bool internCommandResult = false)
7275
{
7376
switch (result.Count) {
7477
case 0:
@@ -82,6 +85,7 @@ internal SqlCompilationResult(IReadOnlyList<Node> result, IDictionary<object, st
8285
break;
8386
}
8487
this.parameterNames = parameterNames.Count > 0 ? parameterNames : null;
88+
this.internCommandResult = internCommandResult;
8589
}
8690
}
8791
}

Orm/Xtensive.Orm/Sql/Compiler/SqlCompiler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2008-2021 Xtensive LLC.
1+
// Copyright (C) 2008-2025 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44

@@ -43,7 +43,7 @@ public SqlCompilationResult Compile(ISqlCompileUnit unit, SqlCompilerConfigurati
4343
configuration = compilerConfiguration;
4444
context = new SqlCompilerContext(configuration);
4545
unit.AcceptVisitor(this);
46-
return new SqlCompilationResult(context.Output.Children, context.ParameterNameProvider.NameTable);
46+
return new SqlCompilationResult(context.Output.Children, context.ParameterNameProvider.NameTable, compilerConfiguration.TypeIndentifiersAsParameters);
4747
}
4848

4949
#region Visitors

Orm/Xtensive.Orm/Sql/Compiler/SqlCompilerConfiguration.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2009-2022 Xtensive LLC.
1+
// Copyright (C) 2009-2025 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Denis Krjuchkov
@@ -35,6 +35,11 @@ public sealed class SqlCompilerConfiguration
3535
/// </summary>
3636
public SqlCommentLocation CommentLocation { get; set; } = SqlCommentLocation.Nowhere;
3737

38+
/// <summary>
39+
/// Type identifiers presented as parameters instead of constant values.
40+
/// </summary>
41+
public bool TypeIndentifiersAsParameters { get; set; }
42+
3843
/// <summary>
3944
/// Clones this instance.
4045
/// </summary>
@@ -44,6 +49,7 @@ public SqlCompilerConfiguration Clone()
4449
return new SqlCompilerConfiguration {
4550
ParameterNamePrefix = ParameterNamePrefix,
4651
DatabaseQualifiedObjects = DatabaseQualifiedObjects,
52+
TypeIndentifiersAsParameters = TypeIndentifiersAsParameters,
4753
};
4854
}
4955
}

0 commit comments

Comments
 (0)