create index if not exists idx_tenant_memberships_student_active
  on public.tenant_memberships(tenant_id, role, status, user_id)
  where role = 'student' and status = 'active';

create index if not exists idx_student_profiles_tenant_region_user
  on public.student_profiles(tenant_id, region_id, user_id);

create index if not exists idx_answer_records_tenant_answered_user
  on public.answer_records(tenant_id, answered_at desc, user_id);

create index if not exists idx_score_events_tenant_created_user_positive
  on public.user_score_events(tenant_id, created_at desc, user_id)
  where points > 0;

create index if not exists idx_user_word_progress_tenant_review_user
  on public.user_word_progress(tenant_id, last_review_date desc, user_id)
  where last_review_date is not null;

create index if not exists idx_practice_reports_tenant_mode_score
  on public.practice_session_reports(tenant_id, mode, score desc, submitted_at desc, user_id)
  where mode = 'mock_exam';
