Skip to content

Conversation

@dustinbyrne
Copy link
Contributor

This change drops some unused/redundant indexes on posthog_cohortcalculationhistory.

We currently have:

"posthog_cohortcalculationhistory_pkey" PRIMARY KEY, btree (id)
"posthog_coh_cohort__cbac1b_idx" btree (cohort_id, started_at DESC)
"posthog_coh_team_id_0ba00c_idx" btree (team_id, cohort_id)
"posthog_coh_team_id_762cc7_idx" btree (team_id, started_at)
"posthog_cohortcalculationhistory_cohort_id_e7c02b55" btree (cohort_id)
"posthog_cohortcalculationhistory_team_id_beba9c96" btree (team_id) 

posthog_cohortcalculationhistory_cohort_id_e7c02b55 indexes cohort_id, but so does the composite index posthog_coh_cohort__cbac1b_idx.
posthog_cohortcalculationhistory_team_id_beba9c96 indexes team_id, but so do the composite indexes posthog_coh_team_id_0ba00c_idx and posthog_coh_team_id_762cc7_idx.

This change drops posthog_cohortcalculationhistory_cohort_id_e7c02b55, posthog_cohortcalculationhistory_team_id_beba9c96.

Copilot AI review requested due to automatic review settings December 5, 2025 19:14
@dustinbyrne dustinbyrne changed the title fix(db): Drop redundant cohortcalculationhistory indexes fix(cohorts): Drop redundant cohortcalculationhistory indexes Dec 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

Migration SQL Changes

Hey 👋, we've detected some migrations on this PR. Here's the SQL output for each migration, make sure they make sense:

posthog/migrations/0937_remove_redundant_cohortcalculationhistory_indexes.py

--
-- Raw SQL operation
--
DROP INDEX CONCURRENTLY IF EXISTS posthog_cohortcalculationhistory_cohort_id_e7c02b55;
--
-- Raw SQL operation
--
DROP INDEX CONCURRENTLY IF EXISTS posthog_cohortcalculationhistory_team_id_beba9c96;

Last updated: 2025-12-08 21:36 UTC (b50450e)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

🔍 Migration Risk Analysis

We've analyzed your migrations for potential risks.

Summary: 1 Safe | 0 Needs Review | 0 Blocked

✅ Safe

Brief or no lock, backwards compatible

posthog.0937_remove_redundant_cohortcalculationhistory_indexes
  └─ #1 ✅ RunSQL: DROP INDEX CONCURRENTLY is safe (non-blocking)
  └─ #2 ✅ RunSQL: DROP INDEX CONCURRENTLY is safe (non-blocking)

Last updated: 2025-12-08 21:36 UTC (b50450e)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR drops redundant database indexes on the posthog_cohortcalculationhistory table to reduce database overhead and improve performance. The indexes being removed are covered by existing composite indexes.

Key Changes:

  • Drops single-column index on cohort_id (covered by composite index on cohort_id, started_at DESC)
  • Drops single-column index on team_id (covered by composite indexes on team_id, cohort_id and team_id, started_at)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
posthog/migrations/0936_remove_redundant_cohortcalculationhistory_indexes.py Migration to drop two redundant indexes using DROP INDEX CONCURRENTLY for non-blocking database operation
posthog/migrations/max_migration.txt Updated to track the latest migration number

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Both of these are not neccessary due to composite indexes that cover the
same space
Seems unnecessary, but what if?
@dustinbyrne dustinbyrne force-pushed the fix/drop-redundant-cohortcalculationhistory-indexes branch from 8fc868c to 268cc6f Compare December 8, 2025 17:19
@dustinbyrne dustinbyrne merged commit 1350193 into master Dec 8, 2025
180 checks passed
@dustinbyrne dustinbyrne deleted the fix/drop-redundant-cohortcalculationhistory-indexes branch December 8, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants