diff --git a/deltaScripts/14.3.1/DR2060/dropGridDataURI.sh b/deltaScripts/14.3.1/DR2060/dropGridDataURI.sh index d4d41282eb..9468a258b5 100644 --- a/deltaScripts/14.3.1/DR2060/dropGridDataURI.sh +++ b/deltaScripts/14.3.1/DR2060/dropGridDataURI.sh @@ -16,6 +16,21 @@ function dropDatauri { } +# takes one arg: name of the index +function dropIndex { + ${PSQL} -U awips -d metadata -c "DROP INDEX IF EXISTS \"$1\";" +} + +# takes three args: table, index name, columns +# will first drop the index if it exists and then adds it back, this is +# fairly inefficient if it does exist but operationally it won't exist and for +# testing this allows the script to be run easily as a noop. +function dropAndAddIndex { + ${PSQL} -U awips -d metadata -c "DROP INDEX IF EXISTS \"$2\";" + ${PSQL} -U awips -d metadata -c "CREATE INDEX $2 ON $1 USING btree $3;" +} + + # takes three args: table, constraint name, unique columns # will first drop the constraint if it exists and then adds it back, this is # fairly inefficient if it does exist but operationally it won't exist and for @@ -28,14 +43,24 @@ function dropAndAddConstraint { echo "FATAL: The update has failed." exit 1 fi +} + +# takes one arg: name of the table +function vacuumTable { ${PSQL} -U awips -d metadata -c "VACUUM FULL ANALYZE $1" } echo "INFO: Dropping dataURI columns." -dropAndAddConstraint grid grid_reftime_forecasttime_rangestart_rangeend_info_id "(refTime, forecastTime, rangestart, rangeend, info_id)" -dropAndAddConstraint grid_info grid_info_datasetid_secondaryid_ensembleid_location_id_parameter_abbreviation_level_id "(datasetid, secondaryid, ensembleid, location_id, parameter_abbreviation, level_id)" +dropAndAddConstraint grid grid_reftime_forecasttime_info_id_rangestart_rangeend_key "(refTime, forecastTime, info_id, rangestart, rangeend)" +dropAndAddConstraint grid_info grid_info_datasetid_parameter_abbreviation_level_id_seconda_key "(datasetid, parameter_abbreviation, level_id, secondaryid, ensembleid, location_id)" +dropIndex gridDatasetReftime_idx +dropIndex grid_reftimeindex +dropIndex gridinfoNameParamLevel_idx +dropAndAddIndex grid grid_info_id_index "(info_id)" dropDatauri +vacuumTable grid +vacuumTable grid_info echo "INFO: grid dataURI column dropped successfully" diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/res/scripts/grid_indices.sql b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/res/scripts/grid_indices.sql index a7a86e8478..b4a00aed35 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/res/scripts/grid_indices.sql +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/res/scripts/grid_indices.sql @@ -17,17 +17,6 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ - -CREATE INDEX "gridDatasetReftime_idx" - ON grid - USING btree - (info_id, reftime, forecasttime); - -CREATE INDEX "gridinfoNameParamLevel_idx" - ON grid_info - USING btree - (datasetid, parameter_abbreviation, level_id); - CREATE INDEX "gridinfoSecondryId_idx" ON grid_info USING btree diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/GridInfoRecord.java b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/GridInfoRecord.java index 7a40edd823..2b0cd6e72f 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/GridInfoRecord.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/GridInfoRecord.java @@ -63,8 +63,8 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; */ @Entity @Table(name = "grid_info", uniqueConstraints = { @UniqueConstraint(columnNames = { - "datasetid", "secondaryid", "ensembleid", "location_id", - "parameter_abbreviation", "level_id" }) }) + "datasetid", "parameter_abbreviation", "level_id", "secondaryid", + "ensembleid", "location_id" }) }) @SequenceGenerator(name = "GRIDINFO_GENERATOR", sequenceName = "gridinfo_seq", allocationSize = 1) @DynamicSerialize public class GridInfoRecord extends PersistableDataObject { @@ -196,59 +196,74 @@ public class GridInfoRecord extends PersistableDataObject { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + result = (prime * result) + ((datasetId == null) ? 0 : datasetId.hashCode()); - result = prime * result + result = (prime * result) + ((ensembleId == null) ? 0 : ensembleId.hashCode()); - result = prime * result + ((level == null) ? 0 : level.hashCode()); - result = prime * result + result = (prime * result) + ((level == null) ? 0 : level.hashCode()); + result = (prime * result) + ((location == null) ? 0 : location.hashCode()); - result = prime * result + result = (prime * result) + ((parameter == null) ? 0 : parameter.hashCode()); - result = prime * result + result = (prime * result) + ((secondaryId == null) ? 0 : secondaryId.hashCode()); return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } GridInfoRecord other = (GridInfoRecord) obj; if (datasetId == null) { - if (other.datasetId != null) + if (other.datasetId != null) { return false; - } else if (!datasetId.equals(other.datasetId)) + } + } else if (!datasetId.equals(other.datasetId)) { return false; + } if (ensembleId == null) { - if (other.ensembleId != null) + if (other.ensembleId != null) { return false; - } else if (!ensembleId.equals(other.ensembleId)) + } + } else if (!ensembleId.equals(other.ensembleId)) { return false; + } if (level == null) { - if (other.level != null) + if (other.level != null) { return false; - } else if (!level.equals(other.level)) + } + } else if (!level.equals(other.level)) { return false; + } if (location == null) { - if (other.location != null) + if (other.location != null) { return false; - } else if (!location.equals(other.location)) + } + } else if (!location.equals(other.location)) { return false; + } if (parameter == null) { - if (other.parameter != null) + if (other.parameter != null) { return false; - } else if (!parameter.equals(other.parameter)) + } + } else if (!parameter.equals(other.parameter)) { return false; + } if (secondaryId == null) { - if (other.secondaryId != null) + if (other.secondaryId != null) { return false; - } else if (!secondaryId.equals(other.secondaryId)) + } + } else if (!secondaryId.equals(other.secondaryId)) { return false; + } return true; } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/GridRecord.java b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/GridRecord.java index 807e7fa89e..9dba5f39f6 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/GridRecord.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/GridRecord.java @@ -76,14 +76,13 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; */ @Entity @SequenceGenerator(initialValue = 1, name = PluginDataObject.ID_GEN, sequenceName = "gridseq") -@Table(name = "grid", uniqueConstraints = { @UniqueConstraint(columnNames = { - "refTime", "forecastTime", "rangestart", "rangeend", "info_id" }) }) /* - * Both refTime and forecastTime are included in the refTimeIndex since - * forecastTime is unlikely to be used. + * No need for a separate refTime/forecastTime index since its included in grid + * unique constraint */ -@org.hibernate.annotations.Table(appliesTo = "grid", indexes = { @Index(name = "grid_refTimeIndex", columnNames = { - "refTime", "forecastTime" }) }) +@Table(name = "grid", uniqueConstraints = { @UniqueConstraint(columnNames = { + "refTime", "forecastTime", "info_id", "rangestart", "rangeend" }) }) +@org.hibernate.annotations.Table(appliesTo = "grid", indexes = { @Index(name = "grid_info_id_index", columnNames = { "info_id" }) }) @DynamicSerialize public class GridRecord extends PersistablePluginDataObject implements ISpatialEnabled {