-- Supports idempotent area snapshots created from FindS fences.
SET @area_finds_fence_index_exists = (
  SELECT COUNT(*)
  FROM information_schema.statistics
  WHERE table_schema = DATABASE()
    AND table_name = 'area'
    AND index_name = 'idx_finds_fence_id'
);
SET @area_finds_fence_index_sql = IF(
  @area_finds_fence_index_exists = 0,
  'CREATE INDEX `idx_finds_fence_id` ON `area` (`finds_fence_id`)',
  'SELECT 1'
);
PREPARE area_finds_fence_index_stmt FROM @area_finds_fence_index_sql;
EXECUTE area_finds_fence_index_stmt;
DEALLOCATE PREPARE area_finds_fence_index_stmt;
