есть большая партицированная таблица. добавили партицию, создали индекс ONLY на родительскую таблицу. далее создали индекс на партицию и прицепили родительскому индексу.
Код: Выделить всё
CREATE INDEX CONCURRENTLY i_audit_messages_sectioned_y2021m07_on_operation_code_id ON audit_messages_sectioned_y2021m07(operation_code_id);
ALTER INDEX i_audit_messages_sectioned_on_operation_code_id ATTACH PARTITION i_audit_messages_sectioned_y2021m07_on_operation_code_id;
--- удаляли так, тут без проблем удалилось:
Код: Выделить всё
ALTER TABLE audit_messages_sectioned DETACH PARTITION audit_messages_sectioned_y2021m07;
DROP INDEX IF EXISTS i_audit_messages_sectioned_y2021m07_on_operation_code_id;
DROP TABLE audit_messages_sectioned_y2021m07;
Код: Выделить всё
CREATE TABLE IF NOT EXISTS audit_messages_sectioned_y2021m07 PARTITION OF audit_messages_sectioned FOR VALUES FROM ('2021-07-01 00:00:00') TO ('2021-08-01 00:00:00');
CREATE INDEX CONCURRENTLY i_audit_messages_sectioned_y2021m07_on_operation_code_id ON audit_messages_sectioned_y2021m07(operation_code_id);
Код: Выделить всё
ALTER INDEX i_audit_messages_sectioned_on_operation_code_id ATTACH PARTITION i_audit_messages_sectioned_y2021m07_on_operation_code_id;
ERROR: cannot attach index "i_audit_messages_sectioned_y2021m07_on_operation_code_id" as a partition of index "i_audit_messages_sectioned_on_operation_code_id"
DETAIL: Another index is already attached for partition "audit_messages_sectioned_y2021m07"
--- ну ок, есть и хорошо. смотрим как работает, а работает как-будто его нет
Код: Выделить всё
EXPLAIN select operation_code_id from audit_messages_sectioned_y2021m07 order by operation_code_id;
QUERY PLAN
--------------------------------------------------------------------------------------------
Sort (cost=715.46..729.36 rows=5560 width=4)
Sort Key: operation_code_id
-> Seq Scan on audit_messages_sectioned_y2021m07 (cost=0.00..369.60 rows=5560 width=4)
(3 rows)
Код: Выделить всё
EXPLAIN select operation_code_id from audit_messages_sectioned_y2021m08 order by operation_code_id;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Index Only Scan using i_audit_messages_sectioned_y2021m08_on_operation_code_id on audit_messages_sectioned_y2021m08 (cost=0.56..1048590.12 rows=40380104 width=4)
(1 row)