mirror of
https://github.com/temporalio/temporal.git
synced 2026-08-30 18:41:49 -07:00
Optimize Visibility PostgreSQL upgrade schema v1.14 (#11599)
## What changed? Apply same optimizations in https://github.com/temporalio/temporal/pull/10371 for v1.14. ## Why? Better upgrade script. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [x] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) ## Potential risks
This commit is contained in:
@@ -1,9 +1,31 @@
|
|||||||
ALTER TABLE executions_visibility
|
ALTER TABLE executions_visibility
|
||||||
ADD COLUMN TemporalExternalPayloadSizeBytes BIGINT GENERATED ALWAYS AS ((search_attributes->'TemporalExternalPayloadSizeBytes')::bigint) STORED;
|
ADD COLUMN IF NOT EXISTS TemporalExternalPayloadSizeBytes BIGINT GENERATED ALWAYS AS ((search_attributes->'TemporalExternalPayloadSizeBytes')::bigint) STORED,
|
||||||
|
ADD COLUMN IF NOT EXISTS TemporalExternalPayloadCount BIGINT GENERATED ALWAYS AS ((search_attributes->'TemporalExternalPayloadCount')::bigint) STORED;
|
||||||
|
|
||||||
ALTER TABLE executions_visibility
|
-- Drop invalid indices
|
||||||
ADD COLUMN TemporalExternalPayloadCount BIGINT GENERATED ALWAYS AS ((search_attributes->'TemporalExternalPayloadCount')::bigint) STORED;
|
DO LANGUAGE 'plpgsql' $$
|
||||||
|
DECLARE
|
||||||
|
r RECORD;
|
||||||
|
BEGIN
|
||||||
|
FOR r IN
|
||||||
|
SELECT i.relname as indexname
|
||||||
|
FROM
|
||||||
|
pg_class i,
|
||||||
|
pg_index ix
|
||||||
|
WHERE
|
||||||
|
i.oid = ix.indexrelid
|
||||||
|
AND ix.indrelid = (SELECT oid FROM pg_class WHERE relname = 'executions_visibility')
|
||||||
|
AND i.relname IN (
|
||||||
|
'by_temporal_external_payload_size_bytes',
|
||||||
|
'by_temporal_external_payload_count'
|
||||||
|
)
|
||||||
|
AND NOT ix.indisvalid
|
||||||
|
LOOP
|
||||||
|
EXECUTE format('DROP INDEX %I', r.indexname);
|
||||||
|
RAISE NOTICE 'Dropped invalid index %', r.indexname;
|
||||||
|
END LOOP;
|
||||||
|
END $$;
|
||||||
|
|
||||||
CREATE INDEX by_temporal_external_payload_size_bytes ON executions_visibility (namespace_id, TemporalExternalPayloadSizeBytes, (COALESCE(close_time, '9999-12-31 23:59:59')) DESC, start_time DESC, run_id);
|
|
||||||
|
|
||||||
CREATE INDEX by_temporal_external_payload_count ON executions_visibility (namespace_id, TemporalExternalPayloadCount, (COALESCE(close_time, '9999-12-31 23:59:59')) DESC, start_time DESC, run_id);
|
CREATE INDEX CONCURRENTLY IF NOT EXISTS by_temporal_external_payload_size_bytes ON executions_visibility (namespace_id, TemporalExternalPayloadSizeBytes, (COALESCE(close_time, '9999-12-31 23:59:59')) DESC, start_time DESC, run_id);
|
||||||
|
CREATE INDEX CONCURRENTLY IF NOT EXISTS by_temporal_external_payload_count ON executions_visibility (namespace_id, TemporalExternalPayloadCount, (COALESCE(close_time, '9999-12-31 23:59:59')) DESC, start_time DESC, run_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user