Skip to content
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

Added Indexes #299

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions backend/src/BIE.DataPipeline/DbHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,51 @@ internal bool CreateTable(DataSourceDescription description)
}
}

/// <summary>
/// Create indexes for shape dataset on location column
/// </summary>
/// <param name="description"></param>
internal bool CreateIndexes(DataSourceDescription description)
{
try
{
Console.WriteLine("Creating Index...");
var db = Database.Instance;


var query = "USE BIEDB;" +
" \r\n " +
" SET QUOTED_IDENTIFIER ON; " +
"\r\n " +
" IF NOT EXISTS (" +
" SELECT *" +
" FROM sys.indexes " +
" WHERE name = 'SI_"+description.table_name+"_Location' " +
" AND object_id = OBJECT_ID('dbo."+description.table_name+"')" +
" ) " +
" BEGIN" +
" CREATE SPATIAL INDEX SI_"+description.table_name+"_Location " +
" ON dbo."+description.table_name+"(Location); " +
" END " +
" \r\n"+
" UPDATE STATISTICS dbo." +description.table_name+"; " +
" \r\n";

var cmd = db.CreateCommand(query);
db.Execute(cmd);

Console.WriteLine("Index created.");

return true;
}
catch (Exception e)
{
Console.WriteLine("Error while creating Table:");
Console.Error.WriteLine(e);
return false;
}
}

private string GetCreationQuery(DataSourceDescription? description)
{
if (description.source.data_format == "SHAPE")
Expand Down
7 changes: 7 additions & 0 deletions backend/src/BIE.DataPipeline/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@

Console.WriteLine();
Console.WriteLine("Finished Inserting");
if (description.source.data_format == "SHAPE")
{
Console.WriteLine("Creating Indexes");
dbHelper.CreateIndexes(description);
Console.WriteLine("Indexes Created");
}

}
catch (Exception e)
{
Expand Down
Loading