-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9714 from archesproject/9670_improve_bulk_load_pe…
…rformance Improve bulk load performance, #9670
- Loading branch information
Showing
6 changed files
with
110 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
arches/app/models/migrations/9670_improve_bulk_load_performance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from django.db import migrations | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("models", "9477_fix_for_spatial_view_dbf_function_edtf_displaying_null"), | ||
] | ||
|
||
update_check_excess_tiles_trigger = """ | ||
create or replace procedure __arches_complete_bulk_load() AS | ||
$$ | ||
DECLARE | ||
cardinality_violations bigint; | ||
BEGIN | ||
alter table tiles enable trigger __arches_check_excess_tiles_trigger; | ||
alter table tiles enable trigger __arches_trg_update_spatial_attributes; | ||
END | ||
$$ | ||
language plpgsql; | ||
""" | ||
|
||
restore_check_excess_tiles_trigger = """ | ||
create or replace procedure __arches_complete_bulk_load() as | ||
$$ | ||
DECLARE | ||
cardinality_violations bigint; | ||
BEGIN | ||
alter table tiles enable trigger __arches_check_excess_tiles_trigger; | ||
alter table tiles enable trigger __arches_trg_update_spatial_attributes; | ||
if (not __arches_refresh_spatial_views()) then | ||
Raise EXCEPTION 'Unable to refresh spatial views'; | ||
end if; | ||
with cardinality_violations as (SELECT t.resourceinstanceid, | ||
t.nodegroupid, | ||
COALESCE(t.parenttileid::text, '') parent_tileid, | ||
count(*) | ||
FROM tiles t, | ||
node_groups ng | ||
WHERE t.nodegroupid = ng.nodegroupid | ||
AND ng.cardinality = '1' | ||
group by t.resourceinstanceid, t.nodegroupid, parent_tileid | ||
having count(*) > 1) | ||
select count(*) | ||
into cardinality_violations | ||
from cardinality_violations; | ||
if (cardinality_violations > 0) then | ||
Raise Exception 'Cardinality violations found. Run `%` to list violations', | ||
'select * from __arches_get_tile_cardinality_violations()'; | ||
else | ||
Raise Notice 'No cardinality violations found'; | ||
end if; | ||
END $$ | ||
language plpgsql; | ||
""" | ||
|
||
create_index_on_load_staging_tileid = """ | ||
CREATE INDEX IF NOT EXISTS load_staging_tileid ON load_staging (tileid); | ||
""" | ||
|
||
drop_index_on_load_staging_tileid = """ | ||
DROP INDEX IF EXISTS load_staging_tileid; | ||
""" | ||
|
||
operations = [ | ||
migrations.RunSQL(update_check_excess_tiles_trigger, restore_check_excess_tiles_trigger), | ||
migrations.RunSQL(create_index_on_load_staging_tileid, drop_index_on_load_staging_tileid), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters