From b512985b463ba5acc8d57477218d17162e689c35 Mon Sep 17 00:00:00 2001 From: John Krauss Date: Tue, 12 Jul 2016 11:15:08 -0400 Subject: [PATCH] drop/create less, better indexes --- scripts/generate_fixtures.py | 24 ++++++++++++------- src/pg/test/fixtures/load_fixtures.sql | 11 +++++++++ .../test/sql/40_observatory_utility_test.sql | 2 -- .../sql/41_observatory_augmentation_test.sql | 3 --- .../sql/42_observatory_exploration_test.sql | 3 --- .../sql/44_observatory_geometries_test.sql | 1 - 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/scripts/generate_fixtures.py b/scripts/generate_fixtures.py index da14bfe..de5a142 100644 --- a/scripts/generate_fixtures.py +++ b/scripts/generate_fixtures.py @@ -96,22 +96,28 @@ with open('src/pg/test/fixtures/load_fixtures.sql', 'w') as outfile: ALTER TABLE observatory.obs_table ADD PRIMARY KEY (id); ALTER TABLE observatory.obs_column_table - ADD PRIMARY KEY (column_id, table_id), - ADD FOREIGN KEY (column_id) REFERENCES observatory.obs_column(id) ON DELETE CASCADE, - ADD FOREIGN KEY (table_id) REFERENCES observatory.obs_table(id) ON DELETE CASCADE; + ADD PRIMARY KEY (column_id, table_id); +CREATE UNIQUE INDEX ON observatory.obs_column_table (table_id, column_id); CREATE UNIQUE INDEX ON observatory.obs_column_table (table_id, colname); ALTER TABLE observatory.obs_column ADD PRIMARY KEY (id); ALTER TABLE observatory.obs_column_to_column - ADD PRIMARY KEY (source_id, target_id, reltype), - ADD FOREIGN KEY (source_id) REFERENCES observatory.obs_column(id) ON DELETE CASCADE, - ADD FOREIGN KEY (target_id) REFERENCES observatory.obs_column(id) ON DELETE CASCADE; + ADD PRIMARY KEY (source_id, target_id, reltype); +CREATE UNIQUE INDEX ON observatory.obs_column_to_column (target_id, source_id, reltype); +CREATE INDEX ON observatory.obs_column_to_column (reltype); ALTER TABLE observatory.obs_column_tag - ADD PRIMARY KEY (column_id, tag_id), - ADD FOREIGN KEY (column_id) REFERENCES observatory.obs_column(id) ON DELETE CASCADE, - ADD FOREIGN KEY (tag_id) REFERENCES observatory.obs_tag(id) ON DELETE CASCADE; + ADD PRIMARY KEY (column_id, tag_id); +CREATE UNIQUE INDEX ON observatory.obs_column_tag (tag_id, column_id); ALTER TABLE observatory.obs_tag ADD PRIMARY KEY (id); +CREATE INDEX ON observatory.obs_tag (type); + +VACUUM ANALYZE observatory.obs_table; +VACUUM ANALYZE observatory.obs_column_table; +VACUUM ANALYZE observatory.obs_column; +VACUUM ANALYZE observatory.obs_column_to_column; +VACUUM ANALYZE observatory.obs_column_tag; +VACUUM ANALYZE observatory.obs_tag; CREATE TABLE observatory.obs_meta AS SELECT numer_c.id numer_id, diff --git a/src/pg/test/fixtures/load_fixtures.sql b/src/pg/test/fixtures/load_fixtures.sql index 5f765a1..721e9b1 100644 --- a/src/pg/test/fixtures/load_fixtures.sql +++ b/src/pg/test/fixtures/load_fixtures.sql @@ -25209,18 +25209,29 @@ ALTER TABLE observatory.obs_table ADD PRIMARY KEY (id); ALTER TABLE observatory.obs_column_table ADD PRIMARY KEY (column_id, table_id); +CREATE UNIQUE INDEX ON observatory.obs_column_table (table_id, column_id); CREATE UNIQUE INDEX ON observatory.obs_column_table (table_id, colname); ALTER TABLE observatory.obs_column ADD PRIMARY KEY (id); CREATE INDEX ON observatory.obs_column (type); ALTER TABLE observatory.obs_column_to_column ADD PRIMARY KEY (source_id, target_id, reltype); +CREATE UNIQUE INDEX ON observatory.obs_column_to_column (target_id, source_id, reltype); +CREATE INDEX ON observatory.obs_column_to_column (reltype); ALTER TABLE observatory.obs_column_tag ADD PRIMARY KEY (column_id, tag_id); +CREATE UNIQUE INDEX ON observatory.obs_column_tag (tag_id, column_id); ALTER TABLE observatory.obs_tag ADD PRIMARY KEY (id); CREATE INDEX ON observatory.obs_tag (type); +VACUUM ANALYZE observatory.obs_table; +VACUUM ANALYZE observatory.obs_column_table; +VACUUM ANALYZE observatory.obs_column; +VACUUM ANALYZE observatory.obs_column_to_column; +VACUUM ANALYZE observatory.obs_column_tag; +VACUUM ANALYZE observatory.obs_tag; + CREATE SCHEMA IF NOT EXISTS "observatory"; ALTER TABLE "obs_c6fb99c47d61289fbb8e561ff7773799d3fcc308" SET SCHEMA "observatory"; CREATE TABLE observatory.obs_meta AS diff --git a/src/pg/test/sql/40_observatory_utility_test.sql b/src/pg/test/sql/40_observatory_utility_test.sql index 72762c5..efa1314 100644 --- a/src/pg/test/sql/40_observatory_utility_test.sql +++ b/src/pg/test/sql/40_observatory_utility_test.sql @@ -77,5 +77,3 @@ SELECT cdb_observatory._OBS_StandardizeMeasureName('test 343 %% 2 qqq }}{{}}') = SELECT cdb_observatory.OBS_DumpVersion() IS NOT NULL AS OBS_DumpVersion_notnull; - -\i test/fixtures/drop_fixtures.sql diff --git a/src/pg/test/sql/41_observatory_augmentation_test.sql b/src/pg/test/sql/41_observatory_augmentation_test.sql index 8a3f023..2819fec 100644 --- a/src/pg/test/sql/41_observatory_augmentation_test.sql +++ b/src/pg/test/sql/41_observatory_augmentation_test.sql @@ -1,4 +1,3 @@ -\i test/fixtures/load_fixtures.sql \pset format unaligned \set ECHO none @@ -236,5 +235,3 @@ SELECT cdb_observatory.OBS_GetMeasureById( 'us.census.tiger.block_group', '2010 - 2014' ) IS NULL As OBS_GetMeasureById_nulls; - -\i test/fixtures/drop_fixtures.sql diff --git a/src/pg/test/sql/42_observatory_exploration_test.sql b/src/pg/test/sql/42_observatory_exploration_test.sql index 987f214..1993759 100644 --- a/src/pg/test/sql/42_observatory_exploration_test.sql +++ b/src/pg/test/sql/42_observatory_exploration_test.sql @@ -1,4 +1,3 @@ -\i test/fixtures/load_fixtures.sql \pset format unaligned -- set up variables for use in testing @@ -32,5 +31,3 @@ SELECT COUNT(*) > 0 AS _OBS_GetAvailableBoundariesExist FROM cdb_observatory.OBS_GetAvailableBoundaries( cdb_observatory._TestPoint() ) AS t(boundary_id, description, time_span, tablename); - -\i test/fixtures/drop_fixtures.sql diff --git a/src/pg/test/sql/44_observatory_geometries_test.sql b/src/pg/test/sql/44_observatory_geometries_test.sql index 72037fd..17d2b4c 100644 --- a/src/pg/test/sql/44_observatory_geometries_test.sql +++ b/src/pg/test/sql/44_observatory_geometries_test.sql @@ -1,6 +1,5 @@ \pset format unaligned \set ECHO all -\i test/fixtures/load_fixtures.sql -- set up variables for use in testing