-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Correction of the return values of the DatabaseInfo methods for determining the insert, read and delete operations #1183
base: master
Are you sure you want to change the base?
Changes from 8 commits
b492cce
c39be07
1fd2464
9112e28
c00d785
124e5f3
c43a1bf
72ed318
aa0d9f7
2acda4a
7edc7ee
367af06
600fb37
3f1e72c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
//$Authors = Carlos Guzman Alvarez, Jiri Cincura (jiri@cincura.net) | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading; | ||
|
@@ -61,4 +62,119 @@ public void CompleteDatabaseInfoTest() | |
Assert.DoesNotThrowAsync(() => (Task)m.Invoke(dbInfo, new object[] { CancellationToken.None }), m.Name); | ||
} | ||
} | ||
|
||
[Test] | ||
public void PerformanceAnalysis_SELECT_Test() | ||
{ | ||
IDictionary<string, short> tableNameList = GetTableNameList(); | ||
short tableIdTest = tableNameList["TEST"]; | ||
|
||
var dbInfo = new FbDatabaseInfo(Connection); | ||
IDictionary<short, ulong> insertCount = dbInfo.GetInsertCount(); | ||
IDictionary<short, ulong> updateCount = dbInfo.GetUpdateCount(); | ||
IDictionary<short, ulong> readSeqCount = dbInfo.GetReadSeqCount(); | ||
IDictionary<short, ulong> readIdxCount = dbInfo.GetReadIdxCount(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
var fbCommand = new FbCommand("SELECT MAX(INT_FIELD) FROM TEST", Connection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
var maxIntField = fbCommand.ExecuteScalar() as int?; | ||
|
||
insertCount = GetAffectedTables(insertCount, dbInfo.GetInsertCount()); | ||
updateCount = GetAffectedTables(updateCount, dbInfo.GetUpdateCount()); | ||
readSeqCount = GetAffectedTables(readSeqCount, dbInfo.GetReadSeqCount()); | ||
readIdxCount = GetAffectedTables(readIdxCount, dbInfo.GetReadIdxCount()); | ||
|
||
Assert.That(insertCount.ContainsKey(tableIdTest), Is.False); | ||
Assert.That(updateCount.ContainsKey(tableIdTest), Is.False); | ||
Assert.That(readSeqCount.ContainsKey(tableIdTest), Is.True); | ||
Assert.That(readSeqCount[tableIdTest], Is.EqualTo(maxIntField + 1)); | ||
Assert.That(readIdxCount.ContainsKey(tableIdTest), Is.False); | ||
} | ||
|
||
[Test] | ||
public void PerformanceAnalysis_INSERT_Test() | ||
{ | ||
IDictionary<string, short> tableNameList = GetTableNameList(); | ||
short tableIdTest = tableNameList["TEST"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
var dbInfo = new FbDatabaseInfo(Connection); | ||
IDictionary<short, ulong> insertCount = dbInfo.GetInsertCount(); | ||
IDictionary<short, ulong> updateCount = dbInfo.GetUpdateCount(); | ||
IDictionary<short, ulong> readSeqCount = dbInfo.GetReadSeqCount(); | ||
IDictionary<short, ulong> readIdxCount = dbInfo.GetReadIdxCount(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
var fbCommand = new FbCommand("INSERT INTO TEST (INT_FIELD) VALUES (900)", Connection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
fbCommand.ExecuteNonQuery(); | ||
|
||
insertCount = GetAffectedTables(insertCount, dbInfo.GetInsertCount()); | ||
updateCount = GetAffectedTables(updateCount, dbInfo.GetUpdateCount()); | ||
readSeqCount = GetAffectedTables(readSeqCount, dbInfo.GetReadSeqCount()); | ||
readIdxCount = GetAffectedTables(readIdxCount, dbInfo.GetReadIdxCount()); | ||
|
||
Assert.That(insertCount.ContainsKey(tableIdTest), Is.True); | ||
Assert.That(insertCount[tableIdTest], Is.EqualTo(1)); | ||
Assert.That(updateCount.ContainsKey(tableIdTest), Is.False); | ||
Assert.That(readSeqCount.ContainsKey(tableIdTest), Is.False); | ||
Assert.That(readIdxCount.ContainsKey(tableIdTest), Is.False); | ||
} | ||
|
||
[Test] | ||
public void PerformanceAnalysis_UPDATE_Test() | ||
{ | ||
IDictionary<string, short> tableNameList = GetTableNameList(); | ||
short tableIdTest = tableNameList["TEST"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
var fbCommand = new FbCommand("INSERT INTO TEST (INT_FIELD) VALUES (900)", Connection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
fbCommand.ExecuteNonQuery(); | ||
|
||
var dbInfo = new FbDatabaseInfo(Connection); | ||
IDictionary<short, ulong> insertCount = dbInfo.GetInsertCount(); | ||
IDictionary<short, ulong> updateCount = dbInfo.GetUpdateCount(); | ||
IDictionary<short, ulong> readSeqCount = dbInfo.GetReadSeqCount(); | ||
IDictionary<short, ulong> readIdxCount = dbInfo.GetReadIdxCount(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
fbCommand.CommandText = "UPDATE TEST SET SMALLINT_FIELD = 900 WHERE (INT_FIELD = 900)"; | ||
fbCommand.ExecuteNonQuery(); | ||
|
||
insertCount = GetAffectedTables(insertCount, dbInfo.GetInsertCount()); | ||
updateCount = GetAffectedTables(updateCount, dbInfo.GetUpdateCount()); | ||
readSeqCount = GetAffectedTables(readSeqCount, dbInfo.GetReadSeqCount()); | ||
readIdxCount = GetAffectedTables(readIdxCount, dbInfo.GetReadIdxCount()); | ||
|
||
Assert.That(insertCount.ContainsKey(tableIdTest), Is.False); | ||
Assert.That(updateCount.ContainsKey(tableIdTest), Is.True); | ||
Assert.That(updateCount[tableIdTest], Is.EqualTo(1)); | ||
Assert.That(readSeqCount.ContainsKey(tableIdTest), Is.False); | ||
Assert.That(readIdxCount.ContainsKey(tableIdTest), Is.True); | ||
Assert.That(readIdxCount[tableIdTest], Is.EqualTo(1)); | ||
} | ||
|
||
private IDictionary<short, ulong> GetAffectedTables(IDictionary<short, ulong> aStatisticInfoBefore, IDictionary<short, ulong> aStatisticInfoAfter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
var result = new Dictionary<short, ulong>(); | ||
foreach (KeyValuePair<short, ulong> keyValuePair in aStatisticInfoAfter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
if (aStatisticInfoBefore.TryGetValue(keyValuePair.Key, out ulong value)) | ||
{ | ||
ulong counter = keyValuePair.Value - value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (counter > 0) | ||
result.Add(keyValuePair.Key, counter); | ||
} | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
result.Add(keyValuePair.Key, keyValuePair.Value); | ||
} | ||
return result; | ||
} | ||
|
||
private IDictionary<string, short> GetTableNameList() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can see, we would have to extend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
IDictionary<string, short> result = new Dictionary<string, short>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
var command = new FbCommand("select R.RDB$RELATION_ID, R.RDB$RELATION_NAME from RDB$RELATIONS R WHERE RDB$SYSTEM_FLAG = 0", Connection); | ||
FbDataReader reader = command.ExecuteReader(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
while (reader.Read()) | ||
{ | ||
result.Add(reader.GetString(1).Trim(), reader.GetInt16(0)); | ||
} | ||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
using System.IO; | ||
using System.Linq; | ||
using System.Net.Sockets; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace FirebirdSql.Data.Common; | ||
|
||
|
@@ -51,6 +53,22 @@ public static string ToHexString(this byte[] b) | |
return BitConverter.ToString(b).Replace("-", string.Empty); | ||
} | ||
|
||
public static IDictionary<short, ulong> GetTableStatistic(this byte[] b, int aLength) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
int capacity = aLength > 3 ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put it on single line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
(aLength - 3) / 6 + 1 : | ||
0; | ||
var tableStatistic = new Dictionary<short, ulong>(capacity); | ||
for (var i = 3; i < aLength; i += 6) | ||
{ | ||
var tableId = (short)IscHelper.VaxInteger(b, i, 2); | ||
var count = (ulong)IscHelper.VaxInteger(b, i + 2, 4); | ||
tableStatistic.Add(tableId, count); | ||
} | ||
|
||
return tableStatistic; | ||
} | ||
|
||
public static IEnumerable<IEnumerable<T>> Split<T>(this T[] array, int size) | ||
{ | ||
for (var i = 0; i < (float)array.Length / size; i++) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,14 +54,6 @@ public static List<object> ParseDatabaseInfo(byte[] buffer, Charset charset) | |
case IscCodes.isc_info_marks: | ||
case IscCodes.isc_info_reads: | ||
case IscCodes.isc_info_writes: | ||
case IscCodes.isc_info_backout_count: | ||
case IscCodes.isc_info_delete_count: | ||
case IscCodes.isc_info_expunge_count: | ||
case IscCodes.isc_info_insert_count: | ||
case IscCodes.isc_info_purge_count: | ||
case IscCodes.isc_info_read_idx_count: | ||
case IscCodes.isc_info_read_seq_count: | ||
case IscCodes.isc_info_update_count: | ||
case IscCodes.isc_info_db_size_in_pages: | ||
case IscCodes.isc_info_oldest_transaction: | ||
case IscCodes.isc_info_oldest_active: | ||
|
@@ -77,6 +69,17 @@ public static List<object> ParseDatabaseInfo(byte[] buffer, Charset charset) | |
info.Add(VaxInteger(buffer, pos, length)); | ||
break; | ||
|
||
case IscCodes.isc_info_backout_count: | ||
case IscCodes.isc_info_delete_count: | ||
case IscCodes.isc_info_expunge_count: | ||
case IscCodes.isc_info_insert_count: | ||
case IscCodes.isc_info_purge_count: | ||
case IscCodes.isc_info_update_count: | ||
case IscCodes.isc_info_read_seq_count: | ||
case IscCodes.isc_info_read_idx_count: | ||
info.Add( buffer.GetTableStatistic( length ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra spaces around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
break; | ||
|
||
case IscCodes.isc_info_no_reserve: | ||
case IscCodes.isc_info_forced_writes: | ||
case IscCodes.isc_info_db_read_only: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
var
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done