drop/create less, better indexes

This commit is contained in:
John Krauss 2016-07-12 11:15:08 -04:00
parent 329b4dbca3
commit b512985b46
6 changed files with 26 additions and 18 deletions

View File

@ -96,22 +96,28 @@ with open('src/pg/test/fixtures/load_fixtures.sql', 'w') as outfile:
ALTER TABLE observatory.obs_table ALTER TABLE observatory.obs_table
ADD PRIMARY KEY (id); ADD PRIMARY KEY (id);
ALTER TABLE observatory.obs_column_table ALTER TABLE observatory.obs_column_table
ADD PRIMARY KEY (column_id, table_id), ADD PRIMARY KEY (column_id, table_id);
ADD FOREIGN KEY (column_id) REFERENCES observatory.obs_column(id) ON DELETE CASCADE, CREATE UNIQUE INDEX ON observatory.obs_column_table (table_id, column_id);
ADD FOREIGN KEY (table_id) REFERENCES observatory.obs_table(id) ON DELETE CASCADE;
CREATE UNIQUE INDEX ON observatory.obs_column_table (table_id, colname); CREATE UNIQUE INDEX ON observatory.obs_column_table (table_id, colname);
ALTER TABLE observatory.obs_column ALTER TABLE observatory.obs_column
ADD PRIMARY KEY (id); ADD PRIMARY KEY (id);
ALTER TABLE observatory.obs_column_to_column ALTER TABLE observatory.obs_column_to_column
ADD PRIMARY KEY (source_id, target_id, reltype), ADD PRIMARY KEY (source_id, target_id, reltype);
ADD FOREIGN KEY (source_id) REFERENCES observatory.obs_column(id) ON DELETE CASCADE, CREATE UNIQUE INDEX ON observatory.obs_column_to_column (target_id, source_id, reltype);
ADD FOREIGN KEY (target_id) REFERENCES observatory.obs_column(id) ON DELETE CASCADE; CREATE INDEX ON observatory.obs_column_to_column (reltype);
ALTER TABLE observatory.obs_column_tag ALTER TABLE observatory.obs_column_tag
ADD PRIMARY KEY (column_id, tag_id), ADD PRIMARY KEY (column_id, tag_id);
ADD FOREIGN KEY (column_id) REFERENCES observatory.obs_column(id) ON DELETE CASCADE, CREATE UNIQUE INDEX ON observatory.obs_column_tag (tag_id, column_id);
ADD FOREIGN KEY (tag_id) REFERENCES observatory.obs_tag(id) ON DELETE CASCADE;
ALTER TABLE observatory.obs_tag ALTER TABLE observatory.obs_tag
ADD PRIMARY KEY (id); 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 CREATE TABLE observatory.obs_meta AS
SELECT numer_c.id numer_id, SELECT numer_c.id numer_id,

View File

@ -25209,18 +25209,29 @@ ALTER TABLE observatory.obs_table
ADD PRIMARY KEY (id); ADD PRIMARY KEY (id);
ALTER TABLE observatory.obs_column_table ALTER TABLE observatory.obs_column_table
ADD PRIMARY KEY (column_id, table_id); 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); CREATE UNIQUE INDEX ON observatory.obs_column_table (table_id, colname);
ALTER TABLE observatory.obs_column ALTER TABLE observatory.obs_column
ADD PRIMARY KEY (id); ADD PRIMARY KEY (id);
CREATE INDEX ON observatory.obs_column (type); CREATE INDEX ON observatory.obs_column (type);
ALTER TABLE observatory.obs_column_to_column ALTER TABLE observatory.obs_column_to_column
ADD PRIMARY KEY (source_id, target_id, reltype); 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 ALTER TABLE observatory.obs_column_tag
ADD PRIMARY KEY (column_id, tag_id); ADD PRIMARY KEY (column_id, tag_id);
CREATE UNIQUE INDEX ON observatory.obs_column_tag (tag_id, column_id);
ALTER TABLE observatory.obs_tag ALTER TABLE observatory.obs_tag
ADD PRIMARY KEY (id); ADD PRIMARY KEY (id);
CREATE INDEX ON observatory.obs_tag (type); 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"; CREATE SCHEMA IF NOT EXISTS "observatory";
ALTER TABLE "obs_c6fb99c47d61289fbb8e561ff7773799d3fcc308" SET SCHEMA "observatory"; ALTER TABLE "obs_c6fb99c47d61289fbb8e561ff7773799d3fcc308" SET SCHEMA "observatory";
CREATE TABLE observatory.obs_meta AS CREATE TABLE observatory.obs_meta AS

View File

@ -77,5 +77,3 @@ SELECT cdb_observatory._OBS_StandardizeMeasureName('test 343 %% 2 qqq }}{{}}') =
SELECT cdb_observatory.OBS_DumpVersion() SELECT cdb_observatory.OBS_DumpVersion()
IS NOT NULL AS OBS_DumpVersion_notnull; IS NOT NULL AS OBS_DumpVersion_notnull;
\i test/fixtures/drop_fixtures.sql

View File

@ -1,4 +1,3 @@
\i test/fixtures/load_fixtures.sql
\pset format unaligned \pset format unaligned
\set ECHO none \set ECHO none
@ -236,5 +235,3 @@ SELECT cdb_observatory.OBS_GetMeasureById(
'us.census.tiger.block_group', 'us.census.tiger.block_group',
'2010 - 2014' '2010 - 2014'
) IS NULL As OBS_GetMeasureById_nulls; ) IS NULL As OBS_GetMeasureById_nulls;
\i test/fixtures/drop_fixtures.sql

View File

@ -1,4 +1,3 @@
\i test/fixtures/load_fixtures.sql
\pset format unaligned \pset format unaligned
-- set up variables for use in testing -- set up variables for use in testing
@ -32,5 +31,3 @@ SELECT COUNT(*) > 0 AS _OBS_GetAvailableBoundariesExist
FROM cdb_observatory.OBS_GetAvailableBoundaries( FROM cdb_observatory.OBS_GetAvailableBoundaries(
cdb_observatory._TestPoint() cdb_observatory._TestPoint()
) AS t(boundary_id, description, time_span, tablename); ) AS t(boundary_id, description, time_span, tablename);
\i test/fixtures/drop_fixtures.sql

View File

@ -1,6 +1,5 @@
\pset format unaligned \pset format unaligned
\set ECHO all \set ECHO all
\i test/fixtures/load_fixtures.sql
-- set up variables for use in testing -- set up variables for use in testing