Add (type, post_id) index to HPPS progress table#7978
Open
donnapep wants to merge 3 commits into
Open
Conversation
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>
Contributor
There was a problem hiding this comment.
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 thesensei_lms_progresstable 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.
Contributor
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KEY type_post_id (type, post_id)towp_sensei_lms_progressdbDeltaapplies the new index on plugin upgradeWhy
Lesson-status aggregation queries filter
WHERE p.type = 'lesson'. The existingUNIQUE KEY user_progress (post_id, user_id, type)keepstypeas 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_idlookup. 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
type_post_idkey appears inSHOW INDEX FROM wp_sensei_lms_progressEXPLAINonTables_Based_Grading_Listing_Service::build_count_queryoutput and verifyp.key = type_post_idwithrows ≈ 88k(down from full scan)/wp-admin/admin.php?page=sensei_gradingwith HPPS enabled and confirm the listing count query time drops🤖 Generated with Claude Code