From 6080592f9959cf787fc9cc82f662cdaf1f307828 Mon Sep 17 00:00:00 2001 From: Andrey Kurdyumov Date: Tue, 20 Jan 2015 00:06:38 +0600 Subject: [PATCH] Separate index and tables creation This separation allows don't pay penalty for each insert during compilation phase. Indexes created at the last step of the compilation process. For profiler application indexes created together with tables. --- .../ReadNAsmMapToDebugInfo.cs | 1 + .../Cosmos.Debug.Common.csproj | 1 + source/Cosmos.Debug.Common/DebugInfo.cs | 42 ++++++++++++------- source/Cosmos.Debug.Common/ObjDump.cs | 1 + source/Cosmos.Debug.Common/SQLite.sql | 27 ------------ source/Cosmos.Debug.Common/SQLiteIndexes.sql | 26 ++++++++++++ source/Cosmos.IL2CPU.Profiler/Assembler.cs | 2 +- source/Cosmos.IL2CPU.Profiler/Program.cs | 2 +- source/Cosmos.IL2CPU/CompilerEngine.cs | 2 +- 9 files changed, 58 insertions(+), 46 deletions(-) create mode 100644 source/Cosmos.Debug.Common/SQLiteIndexes.sql diff --git a/source/Cosmos.Build.MSBuild/ReadNAsmMapToDebugInfo.cs b/source/Cosmos.Build.MSBuild/ReadNAsmMapToDebugInfo.cs index 9af9801c3..c64c8cf4a 100644 --- a/source/Cosmos.Build.MSBuild/ReadNAsmMapToDebugInfo.cs +++ b/source/Cosmos.Build.MSBuild/ReadNAsmMapToDebugInfo.cs @@ -33,6 +33,7 @@ namespace Cosmos.Build.MSBuild { using (var xDebugInfo = new DebugInfo(DebugInfoFile)) { xDebugInfo.AddLabels(xSourceInfos); + xDebugInfo.CreateIndexes(); } return true; } diff --git a/source/Cosmos.Debug.Common/Cosmos.Debug.Common.csproj b/source/Cosmos.Debug.Common/Cosmos.Debug.Common.csproj index 3a0a5385f..9fe13bb5f 100644 --- a/source/Cosmos.Debug.Common/Cosmos.Debug.Common.csproj +++ b/source/Cosmos.Debug.Common/Cosmos.Debug.Common.csproj @@ -182,6 +182,7 @@ + diff --git a/source/Cosmos.Debug.Common/DebugInfo.cs b/source/Cosmos.Debug.Common/DebugInfo.cs index fd1287fc7..b8d66767a 100644 --- a/source/Cosmos.Debug.Common/DebugInfo.cs +++ b/source/Cosmos.Debug.Common/DebugInfo.cs @@ -1,23 +1,18 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.IO; using System.Data; -using System.Data.Common; -using System.Reflection; -using System.Text; -using Microsoft.Win32; -using Microsoft.Samples.Debugging.CorSymbolStore; -using System.Diagnostics.SymbolStore; -using System.Configuration; -using System.Threading; using System.Data.SQLite; +using System.Diagnostics.SymbolStore; +using System.IO; +using System.Linq; +using System.Reflection; using Dapper; -using SQLinq; -using SQLinq.Dapper; using DapperExtensions; using DapperExtensions.Mapper; using DapperExtensions.Sql; +using Microsoft.Samples.Debugging.CorSymbolStore; +using SQLinq; +using SQLinq.Dapper; namespace Cosmos.Debug.Common { @@ -68,7 +63,7 @@ namespace Cosmos.Debug.Common File.Delete(aDbName); } - public DebugInfo(string aPathname, bool aCreate = false) + public DebugInfo(string aPathname, bool aCreate = false, bool aCreateIndexes = false) { CurrentInstance = this; @@ -98,9 +93,10 @@ namespace Cosmos.Debug.Common // Be careful with indexes, they slow down inserts. So on tables that we have a // lot of inserts, but limited look ups, dont add them. // - xSQL.MakeIndex("Labels", "Address", false); - xSQL.MakeIndex("Labels", "Name", true); - xSQL.MakeIndex("Methods", "DocumentID", false); + if (aCreateIndexes) + { + this.CreateIndexes(); + } } } if (mConnection.State == ConnectionState.Closed) @@ -117,6 +113,20 @@ namespace Cosmos.Debug.Common } } + /// + /// Create indexes inside the database. + /// + public void CreateIndexes() + { + var xSQL = new SQL(mConnection); + + xSQL.MakeIndex("Labels", "Address", false); + xSQL.MakeIndex("Labels", "Name", true); + xSQL.MakeIndex("Methods", "DocumentID", false); + + xSQL.ExecuteAssemblyResource("SQLiteIndexes.sql"); + } + // The GUIDs etc are populated by the MSBuild task, so they wont be loaded when the debugger runs. // Because of this, we also allow manual loading. public void LoadLookups() diff --git a/source/Cosmos.Debug.Common/ObjDump.cs b/source/Cosmos.Debug.Common/ObjDump.cs index 84c39c5ee..89b86fa37 100644 --- a/source/Cosmos.Debug.Common/ObjDump.cs +++ b/source/Cosmos.Debug.Common/ObjDump.cs @@ -125,6 +125,7 @@ namespace Cosmos.Debug.Common { } xDebugInfo.AddLabels(xLabels, true); + xDebugInfo.CreateIndexes(); } } } diff --git a/source/Cosmos.Debug.Common/SQLite.sql b/source/Cosmos.Debug.Common/SQLite.sql index 04b5874f0..179f87758 100644 --- a/source/Cosmos.Debug.Common/SQLite.sql +++ b/source/Cosmos.Debug.Common/SQLite.sql @@ -91,30 +91,3 @@ alter table methods alter table MethodIlOps add column MethodID integer null;-- references Methods(ID); - --- Creating non-clustered index for FOREIGN KEY 'FK_AssemblyFileMethod' -CREATE INDEX [IX_FK_AssemblyFileMethod] -ON [Methods] - ([AssemblyFileID]); - - --- Creating non-clustered index for FOREIGN KEY 'FK_DocumentMethod' -CREATE INDEX [IX_FK_DocumentMethod] -ON [Methods] - ([DocumentID]); - --- Creating non-clustered index for FOREIGN KEY 'FK_LabelMethod' -CREATE INDEX [IX_FK_LabelMethod] -ON [Methods] - ([LabelStartID]); - --- Creating non-clustered index for FOREIGN KEY 'FK_LabelMethodEnd' -CREATE INDEX [IX_FK_LabelMethodEnd] -ON [Methods] - ([LabelEndID]); - - --- Creating non-clustered index for FOREIGN KEY 'FK_MethodIlOpMethod' -CREATE INDEX [IX_FK_MethodIlOpMethod] -ON [MethodIlOps] - ([MethodID]); diff --git a/source/Cosmos.Debug.Common/SQLiteIndexes.sql b/source/Cosmos.Debug.Common/SQLiteIndexes.sql new file mode 100644 index 000000000..cc7b1d581 --- /dev/null +++ b/source/Cosmos.Debug.Common/SQLiteIndexes.sql @@ -0,0 +1,26 @@ +-- Creating non-clustered index for FOREIGN KEY 'FK_AssemblyFileMethod' +CREATE INDEX [IX_FK_AssemblyFileMethod] +ON [Methods] + ([AssemblyFileID]); + + +-- Creating non-clustered index for FOREIGN KEY 'FK_DocumentMethod' +CREATE INDEX [IX_FK_DocumentMethod] +ON [Methods] + ([DocumentID]); + +-- Creating non-clustered index for FOREIGN KEY 'FK_LabelMethod' +CREATE INDEX [IX_FK_LabelMethod] +ON [Methods] + ([LabelStartID]); + +-- Creating non-clustered index for FOREIGN KEY 'FK_LabelMethodEnd' +CREATE INDEX [IX_FK_LabelMethodEnd] +ON [Methods] + ([LabelEndID]); + + +-- Creating non-clustered index for FOREIGN KEY 'FK_MethodIlOpMethod' +CREATE INDEX [IX_FK_MethodIlOpMethod] +ON [MethodIlOps] + ([MethodID]); diff --git a/source/Cosmos.IL2CPU.Profiler/Assembler.cs b/source/Cosmos.IL2CPU.Profiler/Assembler.cs index 8cb8b5c69..f3d966ac1 100644 --- a/source/Cosmos.IL2CPU.Profiler/Assembler.cs +++ b/source/Cosmos.IL2CPU.Profiler/Assembler.cs @@ -15,7 +15,7 @@ namespace Cosmos.IL2CPU.Profiler { protected override void InitILOps(Type aAssemblerBaseOp) { var xILOp = new ILOp(this.Assembler); - DebugInfo = new Debug.Common.DebugInfo(AppDomain.CurrentDomain.BaseDirectory + "DebugInfo.mdf", true); + DebugInfo = new Debug.Common.DebugInfo(AppDomain.CurrentDomain.BaseDirectory + "DebugInfo.mdf", true, true); // Don't change the type in the foreach to a var, its necessary as it is now // to typecast it, so we can then recast to an int. foreach (ILOpCode.Code xCode in Enum.GetValues(typeof(ILOpCode.Code))) diff --git a/source/Cosmos.IL2CPU.Profiler/Program.cs b/source/Cosmos.IL2CPU.Profiler/Program.cs index a1130af78..3b8f73d05 100644 --- a/source/Cosmos.IL2CPU.Profiler/Program.cs +++ b/source/Cosmos.IL2CPU.Profiler/Program.cs @@ -47,7 +47,7 @@ namespace Cosmos.IL2CPU.Profiler { { Console.WriteLine("ILScanner exception : " + e.Message); }; - using (var xDebugInfo = new DebugInfo(MDFFile, true)) + using (var xDebugInfo = new DebugInfo(MDFFile, true, true)) { xAsmblr.DebugInfo = xDebugInfo; xAsmblr.DebugEnabled = true; diff --git a/source/Cosmos.IL2CPU/CompilerEngine.cs b/source/Cosmos.IL2CPU/CompilerEngine.cs index 20be551fe..098be7262 100644 --- a/source/Cosmos.IL2CPU/CompilerEngine.cs +++ b/source/Cosmos.IL2CPU/CompilerEngine.cs @@ -206,7 +206,7 @@ namespace Cosmos.IL2CPU using (var xAsm = GetAppAssembler()) { - using (var xDebugInfo = new DebugInfo(xOutputFilename + ".cdb", true)) + using (var xDebugInfo = new DebugInfo(xOutputFilename + ".cdb", true, false)) { xAsm.DebugInfo = xDebugInfo; xAsm.DebugEnabled = DebugEnabled;