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.
This commit is contained in:
Andrey Kurdyumov 2015-01-20 00:06:38 +06:00
parent 40a5b7bc00
commit 6080592f99
9 changed files with 58 additions and 46 deletions

View file

@ -33,6 +33,7 @@ namespace Cosmos.Build.MSBuild {
using (var xDebugInfo = new DebugInfo(DebugInfoFile))
{
xDebugInfo.AddLabels(xSourceInfos);
xDebugInfo.CreateIndexes();
}
return true;
}

View file

@ -182,6 +182,7 @@
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="SQLiteIndexes.sql" />
<EmbeddedResource Include="SQLite.sql" />
<None Include="Guess.mdf" />
<Content Include="Guess_log.ldf">

View file

@ -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
}
}
/// <summary>
/// Create indexes inside the database.
/// </summary>
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()

View file

@ -125,6 +125,7 @@ namespace Cosmos.Debug.Common {
}
xDebugInfo.AddLabels(xLabels, true);
xDebugInfo.CreateIndexes();
}
}
}

View file

@ -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]);

View file

@ -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]);

View file

@ -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)))

View file

@ -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;

View file

@ -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;