Bläddra i källkod

Code cleanup. Added index for faster sqlite access.

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57462 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 11 år sedan
förälder
incheckning
bee7c8e65c

+ 1 - 8
lib/temporal/SQL/map_stds_register_table_template.sql

@@ -19,20 +19,5 @@
 -- This table stores the names of the space-time datasets in which this map is registered 
 -- This table stores the names of the space-time datasets in which this map is registered 
 CREATE TABLE  TABLE_NAME_STDS_register (
 CREATE TABLE  TABLE_NAME_STDS_register (
   id VARCHAR NOT NULL, -- This column is a primary foreign key storing the STDS names
   id VARCHAR NOT NULL, -- This column is a primary foreign key storing the STDS names
-  PRIMARY KEY (id),
-  FOREIGN KEY (id) REFERENCES  STDS_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  STDS_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
-
---CREATE TRIGGER TABLE_NAME_STDS_register_insert AFTER INSERT ON TABLE_NAME_STDS_register
-
---CREATE TRIGGER TABLE_NAME_STDS_register_delete AFTER DELETE ON TABLE_NAME_STDS_register
-
-

+ 8 - 15
lib/temporal/SQL/map_tables_template.sql

@@ -28,28 +28,28 @@ CREATE TABLE  GRASS_MAP_base (
   PRIMARY KEY (id)
   PRIMARY KEY (id)
 );
 );
 
 
+CREATE INDEX GRASS_MAP_base_index ON GRASS_MAP_base (id);
+
 -- Relative valid time interval with start and end time
 -- Relative valid time interval with start and end time
 CREATE TABLE  GRASS_MAP_relative_time (
 CREATE TABLE  GRASS_MAP_relative_time (
   id VARCHAR NOT NULL,          -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name@mapset) and is used as primary foreign key
   id VARCHAR NOT NULL,          -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name@mapset) and is used as primary foreign key
   start_time INTEGER,  -- The relative valid start time in 
   start_time INTEGER,  -- The relative valid start time in 
   end_time INTEGER,    -- The relative valid end time in 
   end_time INTEGER,    -- The relative valid end time in 
   unit VARCHAR,                 -- The relative time unit, available are "years, months, days, minutes, seconds"
   unit VARCHAR,                 -- The relative time unit, available are "years, months, days, minutes, seconds"
-  PRIMARY KEY (id),
-  FOREIGN KEY (id) REFERENCES  GRASS_MAP_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  GRASS_MAP_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
 
 
-CREATE INDEX GRASS_MAP_relative_time_index ON GRASS_MAP_relative_time (start_time, end_time);
+CREATE INDEX GRASS_MAP_relative_time_index ON GRASS_MAP_relative_time (id, start_time, end_time);
 
 
 CREATE TABLE  GRASS_MAP_absolute_time (
 CREATE TABLE  GRASS_MAP_absolute_time (
   id VARCHAR NOT NULL,   -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name@mapset) and is used as primary foreign key
   id VARCHAR NOT NULL,   -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name@mapset) and is used as primary foreign key
   start_time TIMESTAMP,  --  Start of the valid time, can be NULL if no time information is available
   start_time TIMESTAMP,  --  Start of the valid time, can be NULL if no time information is available
   end_time TIMESTAMP,    --  End of the valid time, can be NULL if no time information is available or valid time is a single point in time
   end_time TIMESTAMP,    --  End of the valid time, can be NULL if no time information is available or valid time is a single point in time
   timezone VARCHAR,      -- The timezone of the valid time stored as string. This is currently not in use. Instead the timezone is set in the datetime strings 
   timezone VARCHAR,      -- The timezone of the valid time stored as string. This is currently not in use. Instead the timezone is set in the datetime strings 
-  PRIMARY KEY (id),
-  FOREIGN KEY (id) REFERENCES  GRASS_MAP_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  GRASS_MAP_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
 
 
-CREATE INDEX GRASS_MAP_absolute_time_index ON GRASS_MAP_absolute_time (start_time, end_time);
+CREATE INDEX GRASS_MAP_absolute_time_index ON GRASS_MAP_absolute_time (id, start_time, end_time);
 
 
 -- The spatial extent of a raster map
 -- The spatial extent of a raster map
 
 
@@ -63,27 +63,7 @@ CREATE TABLE  GRASS_MAP_spatial_extent (
   top DOUBLE PRECISION NOT NULL,
   top DOUBLE PRECISION NOT NULL,
   bottom DOUBLE PRECISION NOT NULL,
   bottom DOUBLE PRECISION NOT NULL,
   proj VARCHAR,
   proj VARCHAR,
-  PRIMARY KEY (id),
-  FOREIGN KEY (id) REFERENCES  GRASS_MAP_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  GRASS_MAP_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
 
 
-
---CREATE TRIGGER update_GRASS_MAP_absolute_time AFTER UPDATE ON GRASS_MAP_absolute_time 
-
---CREATE TRIGGER update_GRASS_MAP_relative_time AFTER UPDATE ON GRASS_MAP_relative_time 
-
-
---CREATE TRIGGER update_GRASS_MAP_spatial_extent AFTER UPDATE ON GRASS_MAP_spatial_extent 
+CREATE INDEX GRASS_MAP_spatial_extent_index ON GRASS_MAP_spatial_extent (id);

+ 2 - 3
lib/temporal/SQL/raster3d_metadata_table.sql

@@ -22,14 +22,8 @@ CREATE TABLE  raster3d_metadata (
   tbres DOUBLE PRECISION NOT NULL,
   tbres DOUBLE PRECISION NOT NULL,
   min DOUBLE PRECISION,
   min DOUBLE PRECISION,
   max DOUBLE PRECISION,
   max DOUBLE PRECISION,
-  PRIMARY KEY (id),
-  FOREIGN KEY (id) REFERENCES  raster3d_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  raster3d_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
 
 
+CREATE INDEX raster3d_metadata_index ON raster3d_metadata (id);
 
 
---CREATE TRIGGER update_raster3d_metadata AFTER UPDATE ON raster3d_metadata 

+ 2 - 4
lib/temporal/SQL/raster_metadata_table.sql

@@ -20,15 +20,7 @@ CREATE TABLE  raster_metadata (
   ewres DOUBLE PRECISION NOT NULL,
   ewres DOUBLE PRECISION NOT NULL,
   min DOUBLE PRECISION,
   min DOUBLE PRECISION,
   max DOUBLE PRECISION,
   max DOUBLE PRECISION,
-  PRIMARY KEY (id),
-  FOREIGN KEY (id) REFERENCES  raster_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  raster_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
 
 
---CREATE TRIGGER update_raster_metadata AFTER UPDATE ON raster_metadata 
-
+CREATE INDEX raster_metadata_index ON raster_metadata (id);

+ 2 - 25
lib/temporal/SQL/stds_map_register_table_template.sql

@@ -17,113 +17,7 @@
 -- This table stores the.ids of the GRASS_MAP maps registered in the current spacetime GRASS_MAP table
 -- This table stores the.ids of the GRASS_MAP maps registered in the current spacetime GRASS_MAP table
 CREATE TABLE  SPACETIME_NAME_GRASS_MAP_register (
 CREATE TABLE  SPACETIME_NAME_GRASS_MAP_register (
   id VARCHAR NOT NULL, -- This colum is a primary foreign key storing the registered GRASS_MAP map.ids
   id VARCHAR NOT NULL, -- This colum is a primary foreign key storing the registered GRASS_MAP map.ids
-  PRIMARY KEY (id),
-  FOREIGN KEY (id) REFERENCES  GRASS_MAP_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  GRASS_MAP_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
 
 
---CREATE TRIGGER SPACETIME_NAME_GRASS_MAP_register_insert_trigger AFTER INSERT ON SPACETIME_NAME_GRASS_MAP_register 
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
-
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---
---CREATE TRIGGER SPACETIME_NAME_GRASS_MAP_register_delete_trigger AFTER DELETE ON SPACETIME_NAME_GRASS_MAP_register 
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---			(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
---
+CREATE INDEX SPACETIME_NAME_GRASS_MAP_register_index ON SPACETIME_NAME_GRASS_MAP_register (id);

+ 3 - 13
lib/temporal/SQL/stds_tables_template.sql

@@ -30,8 +30,7 @@ CREATE TABLE  STDS_relative_time (
   granularity INTEGER,            -- The granularity 
   granularity INTEGER,            -- The granularity 
   unit VARCHAR,                   -- The relative time unit, available are "years, months, days, minutes, seconds"
   unit VARCHAR,                   -- The relative time unit, available are "years, months, days, minutes, seconds"
   map_time VARCHAR,               -- The temporal type of the registered maps, may be interval, point or mixed
   map_time VARCHAR,               -- The temporal type of the registered maps, may be interval, point or mixed
-  PRIMARY KEY (id),  
-  FOREIGN KEY (id) REFERENCES  STDS_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  STDS_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
 
 
 CREATE TABLE  STDS_absolute_time (
 CREATE TABLE  STDS_absolute_time (
@@ -41,8 +40,7 @@ CREATE TABLE  STDS_absolute_time (
   granularity VARCHAR,            -- The granularity "NNN seconds, NNN minutes, NNN hours, NNN days, NNN months, NNN years"
   granularity VARCHAR,            -- The granularity "NNN seconds, NNN minutes, NNN hours, NNN days, NNN months, NNN years"
   timezone VARCHAR,      -- The timezone of the valid time stored as string. This is currently not in use. Instead the timezone is set in the datetime strings 
   timezone VARCHAR,      -- The timezone of the valid time stored as string. This is currently not in use. Instead the timezone is set in the datetime strings 
   map_time VARCHAR,               -- The temporal type of the registered maps, may be interval, point or mixed
   map_time VARCHAR,               -- The temporal type of the registered maps, may be interval, point or mixed
-  PRIMARY KEY (id),  
-  FOREIGN KEY (id) REFERENCES  STDS_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  STDS_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
 
 
 CREATE TABLE  STDS_spatial_extent (
 CREATE TABLE  STDS_spatial_extent (
@@ -54,27 +52,5 @@ CREATE TABLE  STDS_spatial_extent (
   top DOUBLE PRECISION,     -- The spatial top extent, derived from the registered maps
   top DOUBLE PRECISION,     -- The spatial top extent, derived from the registered maps
   bottom DOUBLE PRECISION,  -- The spatial bottom extent, derived from the registered maps
   bottom DOUBLE PRECISION,  -- The spatial bottom extent, derived from the registered maps
   proj VARCHAR,      -- The projection of the space time dataset (XY of LL)
   proj VARCHAR,      -- The projection of the space time dataset (XY of LL)
-  PRIMARY KEY (id),  
-  FOREIGN KEY (id) REFERENCES  STDS_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  STDS_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
-
---CREATE TRIGGER update_STDS_abs_time AFTER UPDATE ON STDS_absolute_time 
-
---CREATE TRIGGER update_STDS_rel_time AFTER UPDATE ON STDS_relative_time 
-
---CREATE TRIGGER update_STDS_spatial_extent AFTER UPDATE ON STDS_spatial_extent 
-

+ 1 - 4
lib/temporal/SQL/str3ds_metadata_table.sql

@@ -23,14 +23,5 @@ CREATE TABLE  str3ds_metadata (
   title VARCHAR,                -- Title of the space time 3D raster dataset
   title VARCHAR,                -- Title of the space time 3D raster dataset
   description VARCHAR,          -- Detailed description of the space time 3D raster dataset
   description VARCHAR,          -- Detailed description of the space time 3D raster dataset
   command VARCHAR,              -- The command that was used to create the space time 3D raster dataset
   command VARCHAR,              -- The command that was used to create the space time 3D raster dataset
-  PRIMARY KEY (id),  
-  FOREIGN KEY (id) REFERENCES  str3ds_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  str3ds_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
-
---CREATE TRIGGER update_str3ds_metadata AFTER UPDATE ON str3ds_metadata 

+ 1 - 4
lib/temporal/SQL/strds_metadata_table.sql

@@ -21,14 +21,5 @@ CREATE TABLE  strds_metadata (
   title VARCHAR,                -- Title of the space-time raster dataset
   title VARCHAR,                -- Title of the space-time raster dataset
   description VARCHAR,          -- Detailed description of the space-time raster dataset
   description VARCHAR,          -- Detailed description of the space-time raster dataset
   command VARCHAR,              -- The command that was used to create the space time raster dataset
   command VARCHAR,              -- The command that was used to create the space time raster dataset
-  PRIMARY KEY (id),  
-  FOREIGN KEY (id) REFERENCES  strds_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  strds_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
-
---CREATE TRIGGER update_strds_metadata AFTER UPDATE ON strds_metadata 

+ 1 - 4
lib/temporal/SQL/stvds_metadata_table.sql

@@ -25,14 +25,5 @@ CREATE TABLE  stvds_metadata (
   islands INTEGER,        -- The number of islands accumulated from all registered maps (topological information)
   islands INTEGER,        -- The number of islands accumulated from all registered maps (topological information)
   holes INTEGER,          -- The number of holes accumulated from all registered maps (topological information)
   holes INTEGER,          -- The number of holes accumulated from all registered maps (topological information)
   volumes INTEGER,        -- The number of volumes accumulated from all registered maps (topological information)
   volumes INTEGER,        -- The number of volumes accumulated from all registered maps (topological information)
-  PRIMARY KEY (id),  
-  FOREIGN KEY (id) REFERENCES  stvds_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  stvds_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
-
---CREATE TRIGGER update_stvds_metadata AFTER UPDATE ON stvds_metadata 

+ 2 - 3
lib/temporal/SQL/vector_metadata_table.sql

@@ -25,14 +25,7 @@ CREATE TABLE  vector_metadata (
   islands INTEGER,        -- The number of islands (topological information)
   islands INTEGER,        -- The number of islands (topological information)
   holes INTEGER,          -- The number of holes (topological information)
   holes INTEGER,          -- The number of holes (topological information)
   volumes INTEGER,        -- The number of volumes (topological information)
   volumes INTEGER,        -- The number of volumes (topological information)
-  PRIMARY KEY (id),
-  FOREIGN KEY (id) REFERENCES  vector_base (id) ON DELETE CASCADE
+  FOREIGN KEY (id) REFERENCES  vector_base (id) ON DELETE CASCADE ON UPDATE CASCADE
 );
 );
 
 
---CREATE TRIGGER update_vector_metadata AFTER UPDATE ON vector_metadata 
+CREATE INDEX vector_metadata_index ON vector_metadata (id);

+ 1 - 1
lib/temporal/SQL/vector_views.sql

@@ -10,8 +10,6 @@ CREATE VIEW vector_view_abs_time AS SELECT
             A1.id, A1.mapset,
             A1.id, A1.mapset,
             A1.name, A1.layer, A1.temporal_type,
             A1.name, A1.layer, A1.temporal_type,
             A1.creation_time, 
             A1.creation_time, 
             A1.creator, 
             A1.creator, 
             A2.start_time, A2.end_time, A2.timezone,
             A2.start_time, A2.end_time, A2.timezone,
             A3.north, A3.south, A3.east, A3.west, A3.bottom, A3.top, A3.proj,
             A3.north, A3.south, A3.east, A3.west, A3.bottom, A3.top, A3.proj,
@@ -26,9 +24,7 @@ CREATE VIEW vector_view_abs_time AS SELECT
 CREATE VIEW vector_view_rel_time AS SELECT 
 CREATE VIEW vector_view_rel_time AS SELECT 
             A1.id, A1.mapset,
             A1.id, A1.mapset,
             A1.name, A1.layer, A1.temporal_type,
             A1.name, A1.layer, A1.temporal_type,
-            A1.creation_time, 
+            A1.creation_time,
             A1.creator, 
             A1.creator, 
             A2.start_time, A2.end_time,
             A2.start_time, A2.end_time,
             A3.north, A3.south, A3.east, A3.west, A3.bottom, A3.top, A3.proj,
             A3.north, A3.south, A3.east, A3.west, A3.bottom, A3.top, A3.proj,