From 3faf0a44de75e182bdeabf55b74b73d2173540c8 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sat, 31 Aug 2024 07:49:30 +0100 Subject: [PATCH] chore: redo and clean all indexes on attributes instances tables (#1222) --- .../V0_42__fix_indexes_in_hypertables.sql | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 search-service/src/main/resources/db/migration/V0_42__fix_indexes_in_hypertables.sql diff --git a/search-service/src/main/resources/db/migration/V0_42__fix_indexes_in_hypertables.sql b/search-service/src/main/resources/db/migration/V0_42__fix_indexes_in_hypertables.sql new file mode 100644 index 000000000..3b339a971 --- /dev/null +++ b/search-service/src/main/resources/db/migration/V0_42__fix_indexes_in_hypertables.sql @@ -0,0 +1,20 @@ +-- Default indexes created by Timescale that should not have been removed +-- https://docs.timescale.com/use-timescale/latest/hypertables/about-hypertables/#hypertable-indexes +CREATE INDEX IF NOT EXISTS attribute_instance_time_idx + ON attribute_instance(time DESC ); +CREATE INDEX IF NOT EXISTS attribute_instance_audit_time_idx + ON attribute_instance_audit(time DESC); + +-- Indexes on main keys used when doing a temporal query +-- As recommended in https://docs.timescale.com/getting-started/latest/create-hypertable/#creating-your-first-hypertable +CREATE INDEX attribute_instance_tea_idx + ON attribute_instance(temporal_entity_attribute, time DESC); +CREATE INDEX attribute_instance_audit_tea_timeproperty_idx + ON attribute_instance_audit(temporal_entity_attribute, time_property, time DESC); + +-- Remove current unwanted indexes +DROP INDEX IF EXISTS attribute_instance_audit_tea_time_property_idx; +DROP INDEX IF EXISTS attribute_instance_temporal_entity_attribute_idx; + +-- Same as attribute_instance_time_idx created above, but with a deprecated reference to observed_at column +DROP INDEX IF EXISTS attribute_instance_observed_at_idx;