# Index Strategy

## Основни принципи

- Индекси върху всички foreign keys и slug-based lookups.
- Partial indexes за `deleted_at IS NULL`, където това е съществено за публичните query patterns.
- GIN индекси за full text search върху имоти, страници и блог статии.
- Composite index за най-честия listing use-case.

## Критични индекси

### Properties

- `idx_properties_listing_filters`
  За стандартен листинг: `is_active`, `status_id`, `deal_type_id`, `property_type_id`, `published_at DESC`
- `idx_properties_price`
- `idx_properties_area_total`
- `idx_properties_location_id`
- `idx_properties_office_id`
- `idx_properties_search_vector`

### Locations

- `idx_locations_parent_id`
- `idx_locations_type_parent`
- `uq_locations_parent_slug`
- `uq_locations_root_slug`

### Custom fields

- `idx_custom_field_definitions_filterable`
- `idx_property_custom_field_values_number`
- `idx_property_custom_field_values_boolean`
- `idx_property_custom_field_values_option`
- `idx_property_custom_field_multi_values_property_id`

### Content / SEO

- `idx_pages_search_vector`
- `idx_blog_posts_search_vector`
- `idx_seo_metadata_entity_type`

### Inquiries

- `idx_inquiries_status_id`
- `idx_inquiries_created_at`
- `idx_inquiry_logs_inquiry_id`

## Scaling бележки

При 100k+ имота е препоръчително:

- да се валидират най-тежките listing query-та с `EXPLAIN (ANALYZE, BUFFERS)`
- да се следи selectivity на composite индексите
- да се обмислят materialized views за faceted navigation / landing pages
- да се добави caching слой за често търсени region/property-type/deal-type комбинации
