Skip to content

OpenConceptLab/ocl_online#636 | Exclude release members with NOT EXISTS and page partial indexing by keyset - #982

Merged
snyaggarwal merged 1 commit into
masterfrom
ocl_online#636
Nov 5, 2026
Merged

snyaggarwal merged 1 commit into
masterfrom
ocl_online#636

Conversation

@snyaggarwal

Copy link
Copy Markdown
Contributor

OpenConceptLab/ocl_online#636

When a new release comes out, the previous release is re-flagged without its shared members (exclude_members_of). On a large release this kept the staging database at about 99% CPU for about 37 hours.

Cause. exclude_source_members produced id NOT IN (subquery). Postgres can't turn NOT IN into an anti-join, and once the member list doesn't fit in work_mem it scans the whole list again for every row. OFFSET paging then repeats that work on every page of 500.

Changes

  • exclude_source_members uses NOT EXISTS, correlated on the member id. Postgres runs it as an anti-join on the existing (source_id, member_id) index. It leaves out the same rows.
  • batch_index_partial_by_ids gets each page after the first with id < last id instead of OFFSET, so every page costs the same. A union can't be filtered, so it keeps paging by OFFSET.
  • Two new database tests, one for keyset paging and one for the union fallback. The mock paging test now checks the keyset filter.

Measured on staging (read-only, a release of about 430k concepts excluded from one of about 31k):

Per page Whole run
Before 23 s for a single row about 35 h observed
NOT EXISTS 2.6–106 ms about 3 s projected
NOT EXISTS + keyset 2.6–16 ms under 1 s projected

Tests: BaseModelTest, SourceReleaseFlagsTest, core.sources.tests and TaskTest pass locally (361 tests), and pylint scores 10/10.

🤖 Generated with Claude Code

@snyaggarwal
snyaggarwal requested a review from paynejd November 5, 2026 07:31
@snyaggarwal snyaggarwal self-assigned this Nov 5, 2026

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review verdict: no P1–P5 findings and no nits.

Verified:

  • BaseModelTest and SourceReleaseFlagsTest: 40 tests passed.
  • Pylint on core/common/models.py, core/common/tasks.py, and core/common/tests.py: 10.00/10.
  • The NOT EXISTS rewrite remains equivalent for both concept and mapping through tables, and the keyset path preserves the union fallback.

(Codex / GPT-5)

@snyaggarwal
snyaggarwal requested review from paynejd and removed request for paynejd November 5, 2026 07:46
@snyaggarwal
snyaggarwal merged commit 0b3cc3e into master Nov 5, 2026
3 checks passed
@snyaggarwal
snyaggarwal deleted the ocl_online#636 branch November 5, 2026 08:08
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.

1 participant