This commit is contained in:
2025-12-30 15:33:32 +01:00
parent bcedae40fc
commit 03e39eb925
3 changed files with 60 additions and 10 deletions

View File

@@ -338,6 +338,33 @@ CREATE TABLE rawdatacor_2024 PARTITION OF rawdatacor
PostgreSQL automatically routes INSERTs to the correct partition based on `event_year`.
### Indexes in PostgreSQL
Both tables have these indexes automatically created:
**Primary Key** (required for partitioned tables):
```sql
-- Must include partition key (event_year)
UNIQUE (id, event_year)
```
**Consolidation Key** (prevents duplicates):
```sql
-- Ensures one record per consolidation group
UNIQUE (unit_name, tool_name_id, event_timestamp, event_year)
```
**Query Optimization**:
```sql
-- Fast filtering by unit/tool
(unit_name, tool_name_id)
-- JSONB queries with GIN index
GIN (measurements)
```
**Note**: All indexes are automatically created on all partitions when you run `setup --create-schema`.
---
## Summary