-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load string parameters column sizes to reduce SqlServer query plans c…
…ount (#197) * Load string parameters column sizes to reduce SqlServer query plans count * Updated to include column size loading logic * Added constant size support for query executors * Added HOCON configuration and documentation for that * Fixed typo * Updated method name according to plugin Co-authored-by: Aaron Stannard <[email protected]>
- Loading branch information
1 parent
ee613a9
commit fd501c9
Showing
10 changed files
with
332 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,3 +221,5 @@ resetdev.bat | |
|
||
# FAKE build folder | ||
.fake/ | ||
|
||
.idea/ |
87 changes: 87 additions & 0 deletions
87
src/Akka.Persistence.SqlServer/Helpers/ColumnSizeLoader.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,87 @@ | ||
// //----------------------------------------------------------------------- | ||
// // <copyright file="ColumnSizeLoader.cs" company="Akka.NET Project"> | ||
// // Copyright (C) 2009-2021 Lightbend Inc. <http://www.lightbend.com> | ||
// // Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// // </copyright> | ||
// //----------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using Akka.Persistence.Sql.Common.Journal; | ||
|
||
namespace Akka.Persistence.SqlServer.Helpers | ||
{ | ||
/// <summary> | ||
/// Helper class that can load column sizes from SqlServer table | ||
/// </summary> | ||
internal static class ColumnSizeLoader | ||
{ | ||
/// <summary> | ||
/// Loads column sizes for Journal | ||
/// </summary> | ||
/// <returns></returns> | ||
public static JournalColumnSizesInfo LoadJournalColumnSizes(QueryConfiguration conventions, DbConnection connection) | ||
{ | ||
using (var command = connection.CreateCommand()) | ||
{ | ||
connection.Open(); | ||
command.CommandText = $"SELECT * FROM {conventions.FullJournalTableName}"; | ||
|
||
// start reading - no need to load the table's content | ||
using (var reader = command.ExecuteReader()) | ||
{ | ||
// load columns metadata | ||
var results = LoadSchemaTableInfo(reader); | ||
|
||
return new JournalColumnSizesInfo( | ||
persistenceIdColumnSize: (int)results.First(r => r["ColumnName"].ToString() == conventions.PersistenceIdColumnName)["ColumnSize"], | ||
tagsColumnSize: (int)results.First(r => r["ColumnName"].ToString() == conventions.TagsColumnName)["ColumnSize"], | ||
manifestColumnSize: (int)results.First(r => r["ColumnName"].ToString() == conventions.ManifestColumnName)["ColumnSize"] | ||
); | ||
} | ||
} | ||
} | ||
|
||
public static SnapshotColumnSizesInfo LoadSnapshotColumnSizes(Sql.Common.Snapshot.QueryConfiguration conventions, DbConnection connection) | ||
{ | ||
using (var command = connection.CreateCommand()) | ||
{ | ||
connection.Open(); | ||
command.CommandText = $"SELECT * FROM {conventions.FullSnapshotTableName}"; | ||
|
||
// start reading - no need to load the table's content | ||
using (var reader = command.ExecuteReader()) | ||
{ | ||
// load columns metadata | ||
var results = LoadSchemaTableInfo(reader); | ||
|
||
return new SnapshotColumnSizesInfo( | ||
persistenceIdColumnSize: (int)results.First(r => r["ColumnName"].ToString() == conventions.PersistenceIdColumnName)["ColumnSize"], | ||
manifestColumnSize: (int)results.First(r => r["ColumnName"].ToString() == conventions.ManifestColumnName)["ColumnSize"] | ||
); | ||
} | ||
} | ||
} | ||
|
||
private static List<Dictionary<string, object>> LoadSchemaTableInfo(DbDataReader reader) | ||
{ | ||
var results = new List<Dictionary<string, object>>(); | ||
|
||
// iterate through the table schema and extract metadata | ||
DataTable schemaTable = reader.GetSchemaTable(); | ||
foreach (DataRow row in schemaTable.Rows) | ||
{ | ||
var dict = new Dictionary<string, object>(); | ||
foreach (DataColumn col in schemaTable.Columns) | ||
{ | ||
dict.Add(col.ColumnName, row[col.Ordinal]); | ||
} | ||
results.Add(dict); | ||
} | ||
|
||
return results; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Akka.Persistence.SqlServer/Helpers/JournalColumnSizesInfo.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,35 @@ | ||
// //----------------------------------------------------------------------- | ||
// // <copyright file="ColumnSizesInfo.cs" company="Akka.NET Project"> | ||
// // Copyright (C) 2009-2021 Lightbend Inc. <http://www.lightbend.com> | ||
// // Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// // </copyright> | ||
// //----------------------------------------------------------------------- | ||
|
||
namespace Akka.Persistence.SqlServer.Helpers | ||
{ | ||
/// <summary> | ||
/// Represents information about SQL Journal Column sizes | ||
/// </summary> | ||
internal class JournalColumnSizesInfo | ||
{ | ||
public JournalColumnSizesInfo(int persistenceIdColumnSize, int tagsColumnSize, int manifestColumnSize) | ||
{ | ||
PersistenceIdColumnSize = persistenceIdColumnSize; | ||
TagsColumnSize = tagsColumnSize; | ||
ManifestColumnSize = manifestColumnSize; | ||
} | ||
|
||
/// <summary> | ||
/// Size of PersistenceId column | ||
/// </summary> | ||
public int PersistenceIdColumnSize { get; } | ||
/// <summary> | ||
/// Size of Tags column | ||
/// </summary> | ||
public int TagsColumnSize { get; } | ||
/// <summary> | ||
/// Size of manifest column | ||
/// </summary> | ||
public int ManifestColumnSize { get; } | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Akka.Persistence.SqlServer/Helpers/SnapshotColumnSizesInfo.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,30 @@ | ||
// //----------------------------------------------------------------------- | ||
// // <copyright file="SnapshotColumnSizesInfo.cs" company="Akka.NET Project"> | ||
// // Copyright (C) 2009-2021 Lightbend Inc. <http://www.lightbend.com> | ||
// // Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// // </copyright> | ||
// //----------------------------------------------------------------------- | ||
|
||
namespace Akka.Persistence.SqlServer.Helpers | ||
{ | ||
/// <summary> | ||
/// Represents information about SQL SnapshotStore Column sizes | ||
/// </summary> | ||
internal class SnapshotColumnSizesInfo | ||
{ | ||
public SnapshotColumnSizesInfo(int persistenceIdColumnSize, int manifestColumnSize) | ||
{ | ||
PersistenceIdColumnSize = persistenceIdColumnSize; | ||
ManifestColumnSize = manifestColumnSize; | ||
} | ||
|
||
/// <summary> | ||
/// Size of PersistenceId column | ||
/// </summary> | ||
public int PersistenceIdColumnSize { get; } | ||
/// <summary> | ||
/// Size of manifest column | ||
/// </summary> | ||
public int ManifestColumnSize { get; } | ||
} | ||
} |
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
Oops, something went wrong.