This repository has been archived by the owner on Jul 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,216 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
using System.Data; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
|
||
namespace DNTProfiler.Common.Profiler | ||
{ | ||
public class DbCommandContext : DbContextBase | ||
{ | ||
public DataTable DataTable { set; get; } | ||
|
||
public long? ElapsedMilliseconds { set; get; } | ||
|
||
public object Result { set; get; } | ||
|
||
public ISet<string> Keys { set; get; } | ||
|
||
public DbCommandContext() | ||
{ | ||
Keys = new HashSet<string>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
DNTProfiler.Infrastructure/ScriptDomVisitors/UseFirstLevelCacheVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using Microsoft.SqlServer.TransactSql.ScriptDom; | ||
using System.Collections.Generic; | ||
|
||
namespace DNTProfiler.Infrastructure.ScriptDomVisitors | ||
{ | ||
public class UseFirstLevelCacheVisitor : SqlFragmentVisitorBase | ||
{ | ||
private int _comparisonCount; | ||
private bool _hasTopRowFilter; | ||
|
||
public ISet<string> Keys { set; get; } | ||
|
||
public override void ExplicitVisit(BooleanComparisonExpression node) | ||
{ | ||
if (!_hasTopRowFilter) | ||
{ | ||
IsSuspected = false; | ||
base.ExplicitVisit(node); | ||
return; | ||
} | ||
|
||
_comparisonCount++; | ||
if (_comparisonCount > 1) | ||
{ | ||
IsSuspected = false; | ||
base.ExplicitVisit(node); | ||
return; | ||
} | ||
|
||
if (node.ComparisonType != BooleanComparisonType.Equals) | ||
{ | ||
IsSuspected = false; | ||
base.ExplicitVisit(node); | ||
return; | ||
} | ||
|
||
var secondExpression = node.SecondExpression.FirstNoneParenthesisExpression(); | ||
var firstExpression = node.FirstExpression.FirstNoneParenthesisExpression(); | ||
|
||
if (isCastOrFunctionCall(firstExpression) || isCastOrFunctionCall(secondExpression)) | ||
{ | ||
IsSuspected = false; | ||
base.ExplicitVisit(node); | ||
return; | ||
} | ||
|
||
var firstColumnReferenceExpression = firstExpression as ColumnReferenceExpression; | ||
if (firstColumnReferenceExpression != null) | ||
{ | ||
var firstColumnResolved = resolveMultiPartIdentifier(firstColumnReferenceExpression.MultiPartIdentifier); | ||
if (Keys != null && Keys.Contains(firstColumnResolved)) | ||
{ | ||
IsSuspected = true; | ||
_comparisonCount--; | ||
base.ExplicitVisit(node); | ||
return; | ||
} | ||
|
||
if (IsSuspected) | ||
{ | ||
IsSuspected = false; | ||
base.ExplicitVisit(node); | ||
return; | ||
} | ||
} | ||
|
||
var secondColumnReferenceExpression = secondExpression as ColumnReferenceExpression; | ||
if (secondColumnReferenceExpression != null) | ||
{ | ||
var secondColumnResolved = resolveMultiPartIdentifier(secondColumnReferenceExpression.MultiPartIdentifier); | ||
if (Keys != null && Keys.Contains(secondColumnResolved)) | ||
{ | ||
IsSuspected = true; | ||
_comparisonCount--; | ||
base.ExplicitVisit(node); | ||
return; | ||
} | ||
|
||
if (IsSuspected) | ||
{ | ||
IsSuspected = false; | ||
base.ExplicitVisit(node); | ||
return; | ||
} | ||
} | ||
|
||
base.ExplicitVisit(node); | ||
} | ||
|
||
public override void ExplicitVisit(TopRowFilter node) | ||
{ | ||
_hasTopRowFilter = true; | ||
base.ExplicitVisit(node); | ||
} | ||
|
||
private static bool isCastOrFunctionCall(ScalarExpression expression) | ||
{ | ||
return expression is CastCall || expression is FunctionCall; | ||
} | ||
|
||
private static string resolveMultiPartIdentifier(MultiPartIdentifier identifier) | ||
{ | ||
return identifier.Identifiers.Count == 2 ? identifier.Identifiers[1].Value : identifier.AsObjectName(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Iesi.Collections" version="4.0.1.4000" targetFramework="net40" /> | ||
<package id="NHibernate" version="4.0.3.4000" targetFramework="net40" /> | ||
<package id="NHibernate" version="4.0.4.4000" targetFramework="net40" /> | ||
<package id="NHibernate.Validator" version="1.3.2.4000" targetFramework="net40" /> | ||
</packages> |
Oops, something went wrong.