Repository navigation
MBS-14548: Add tag vote count indexes to entity tag tables - #3916
Open
adwitiyabisht wants to merge 1 commit into
Open
adwitiyabisht wants to merge 1 commit into
adwitiyabisht wants to merge 1 commit into
Conversation
Member
|
Thanks! Presumably this would also help with the other |
Author
|
Thank you @mwiencek. I will extend the changes to other applicable tables and update the PR shortly. |
Author
|
Updated the implementation to add the partial index to all 11 *_tag tables, as suggested. Performance benchmarks were run on |
adwitiyabisht
force-pushed
the
master
branch
from
November 28, 2026 17:35
9bef7ad to
7862b62
Compare
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.
Problem
Fix MBS-14548.
Entity tag page queries (find_entities in lib/MusicBrainz/Server/Data/EntityTag.pm) filter {entity}_tag by tag and positive vote count, then order results by vote count. The existing tag-only indexes do not efficiently support this filtering and ordering together, which can cause PostgreSQL to process and sort many rows before applying pagination.
Solution
Added a partial composite index on each of the 11 *_tag tables:
Tables covered: area_tag, artist_tag, event_tag, instrument_tag, label_tag, place_tag, recording_tag, release_tag, release_group_tag, series_tag and work_tag. These are all the aggregated *_tag tables in CreateTables.sql, and they match the entity types that use the shared tag role. The existing *_idx_tag indexes are left in place.
Also updated:
admin/sql/CreateIndexes.sqladmin/sql/DropIndexes.sql20261120-tag-vote-count-indexes.sql(replaces the earlier single-table20261120-release-group-tag-vote-count-index.sql)upgrade.jsonAI usage
Testing
Tested locally using Docker and PostgreSQL with EXPLAIN (ANALYZE, BUFFERS).
Dataset: Tag ID
7, 6,160 rows with positive vote counts, page size 50.Query:
Measurements
LIMIT 50 OFFSET 0LIMIT 50 OFFSET 500LIMIT 50 OFFSET 4900Times are medians of five local executions for each configuration. The first single-run measurements for OFFSET 0 were 60.628 ms without the index and 11.065 ms with the index. The table reports medians from five executions.
The measurements were taken on a local development database and are not directly comparable to the replication-mirror measurements in the issue. Repeated runs also benefited from PostgreSQL's cache.
Timings were only measured on
release_group_tag. The other 10 tables use the same query shape and index definition.As an additional execution-plan check, EXPLAIN on artist_tag (whose ORDER BY uses sort_name as a tiebreaker) shows a backward Index Only Scan using artist_tag_idx_tag_count, followed by an Incremental Sort with tt.count as the presorted key. This was a plan check on a small fixture, not a performance measurement.