Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Added indexes for datapoint tables to improve query performance (#1356)

Rich Turner41e6af81315e
diff --git a/manager/src/main/resources/org/openremote/manager/setup/database/V20240722_01__Indexes.sql b/manager/src/main/resources/org/openremote/manager/setup/database/V20240722_01__Indexes.sql
new file mode 100644
index 000000000..f7efab08f
--- /dev/null
+++ b/manager/src/main/resources/org/openremote/manager/setup/database/V20240722_01__Indexes.sql
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2024, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Add an index for entity ID, attribute name and timestamp to improve data point retrieval */
+CREATE index if not exists asset_datapoint_entity_id_attribute_name_timestamp_idx on openremote.asset_datapoint (entity_id, attribute_name, timestamp DESC);
+CREATE index if not exists asset_predicted_datapoint_entity_id_attribute_name_timestamp_idx on openremote.asset_predicted_datapoint (entity_id, attribute_name, timestamp DESC);