Skip to content

Add (type, post_id) index to HPPS progress table#7978

Open
donnapep wants to merge 3 commits into
trunkfrom
perf/hpps-progress-type-post-id-index
Open

Add (type, post_id) index to HPPS progress table#7978
donnapep wants to merge 3 commits into
trunkfrom
perf/hpps-progress-type-post-id-index

Conversation

@donnapep
Copy link
Copy Markdown
Member

Summary

  • Add a composite KEY type_post_id (type, post_id) to wp_sensei_lms_progress
  • dbDelta applies the new index on plugin upgrade

Why

Lesson-status aggregation queries filter WHERE p.type = 'lesson'. The existing UNIQUE KEY user_progress (post_id, user_id, type) keeps type as the last column, so it can't satisfy the filter. Tables_Based_Grading_Listing_Service::build_count_query (and any future type-filtered scan) currently does a full table scan.

The new composite key lets MySQL range-scan by type and cover the INNER JOIN wp_posts ON post.ID = p.post_id lookup. On a ~211k-row dataset the lesson subset is ~88k rows, so the scanned row count drops by ~2.4x. Expected effect on the Grading listing count query: ~3.1s → ~1.3s.

Test plan

  • Update the plugin on a site that already has data; confirm the type_post_id key appears in SHOW INDEX FROM wp_sensei_lms_progress
  • Run EXPLAIN on Tables_Based_Grading_Listing_Service::build_count_query output and verify p.key = type_post_id with rows ≈ 88k (down from full scan)
  • Reload /wp-admin/admin.php?page=sensei_grading with HPPS enabled and confirm the listing count query time drops

🤖 Generated with Claude Code

Lesson-status aggregation queries filter `WHERE p.type = 'lesson'` but
the existing `UNIQUE KEY user_progress (post_id, user_id, type)` keeps
`type` as the last column, so it can't satisfy the filter. The
`Tables_Based_Grading_Listing_Service` count query (and any future
type-filtered scan) ends up doing a full table scan instead.

Add a composite `(type, post_id)` KEY so MySQL can range-scan by type
and cover the `INNER JOIN wp_posts ON post.ID = p.post_id` lookup. On a
~211k-row dataset this drops the scanned row count by ~2.4x and is
expected to bring the Grading listing count query from ~3.1s to ~1.3s.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 13, 2026 20:03
@donnapep donnapep self-assigned this May 13, 2026
@donnapep donnapep added this to the 4.26.0 milestone May 13, 2026
@donnapep donnapep added the HPPS label May 13, 2026
Copy link
Copy Markdown
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

Adds a composite (type, post_id) index to the HPPS progress table schema so admin grading queries that filter by type='lesson' can use an index instead of a full scan.

Changes:

  • Add KEY type_post_id (type, post_id) to the sensei_lms_progress table definition in the installer schema.
  • Add changelog entry describing the performance tweak.

Reviewed changes

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

File Description
includes/internal/installer/class-schema.php Adds composite index on (type, post_id) to the progress table CREATE TABLE definition, applied via dbDelta on upgrade.
changelog/perf-hpps-progress-type-post-id-index Adds patch-level changelog entry.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

WordPress Playground Preview

The changes in this pull request can previewed and tested using a WordPress Playground instance.

Open WordPress Playground Preview

donnapep and others added 2 commits May 14, 2026 07:54
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants