Skip to content

Commit 76ed840

Browse files
authored
Added Indexes (#299)
2 parents 81c719e + 9caec03 commit 76ed840

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

backend/src/BIE.DataPipeline/DbHelper.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,51 @@ internal bool CreateTable(DataSourceDescription description)
104104
}
105105
}
106106

107+
/// <summary>
108+
/// Create indexes for shape dataset on location column
109+
/// </summary>
110+
/// <param name="description"></param>
111+
internal bool CreateIndexes(DataSourceDescription description)
112+
{
113+
try
114+
{
115+
Console.WriteLine("Creating Index...");
116+
var db = Database.Instance;
117+
118+
119+
var query = "USE BIEDB;" +
120+
" \r\n " +
121+
" SET QUOTED_IDENTIFIER ON; " +
122+
"\r\n " +
123+
" IF NOT EXISTS (" +
124+
" SELECT *" +
125+
" FROM sys.indexes " +
126+
" WHERE name = 'SI_"+description.table_name+"_Location' " +
127+
" AND object_id = OBJECT_ID('dbo."+description.table_name+"')" +
128+
" ) " +
129+
" BEGIN" +
130+
" CREATE SPATIAL INDEX SI_"+description.table_name+"_Location " +
131+
" ON dbo."+description.table_name+"(Location); " +
132+
" END " +
133+
" \r\n"+
134+
" UPDATE STATISTICS dbo." +description.table_name+"; " +
135+
" \r\n";
136+
137+
var cmd = db.CreateCommand(query);
138+
db.Execute(cmd);
139+
140+
Console.WriteLine("Index created.");
141+
142+
return true;
143+
}
144+
catch (Exception e)
145+
{
146+
Console.WriteLine("Error while creating Table:");
147+
Console.Error.WriteLine(e);
148+
return false;
149+
}
150+
}
151+
107152
private string GetCreationQuery(DataSourceDescription? description)
108153
{
109154
if (description.source.data_format == "SHAPE")

backend/src/BIE.DataPipeline/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@
9898

9999
Console.WriteLine();
100100
Console.WriteLine("Finished Inserting");
101+
if (description.source.data_format == "SHAPE")
102+
{
103+
Console.WriteLine("Creating Indexes");
104+
dbHelper.CreateIndexes(description);
105+
Console.WriteLine("Indexes Created");
106+
}
107+
101108
}
102109
catch (Exception e)
103110
{

0 commit comments

Comments
 (0)