Repository navigation
Conversation
Contributor
moylop260
force-pushed
the
drop-covered-channel-index-19.0
branch
2 times, most recently
from
November 10, 2026 07:44
304cf60 to
a14107d
Compare
…e on channel The two indexes created in init() become models.Index attributes, the way 19.0 declares them, with the names they already have. models.Index compares the comment of the existing index with its definition and rebuilds it when they differ, so a pre-migration gives the existing indexes the comment the ORM expects and the first update does not rebuild them on a big queue_job table. queue.job.channel has index=True, which makes the ORM create queue_job__channel_index. The composite index on (channel, date_done, date_created) has channel as its leading column. New databases never create the single column index. Existing ones keep it, because the ORM only logs "Keep unexpected index" when a field stops asking for one.
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.
queue.job.channelhasindex=True, so the ORM createsqueue_job__channel_index. The composite index on(channel, date_done, date_created)haschannelas its leading column, so the single column index is covered by it. PgHero reports it as such. On a real database it is 64 MB that every job insert and state change maintains and vacuum visits.This PR does two things:
index=Truefromchannel. Existing databases keep the old index (the ORM only logs "Keep unexpected index" when a field stops asking for one), so it has to be dropped by hand there.init()created withcreate_indextomodels.Indexattributes, the way 19.0 declares them, with the names they already have.Index.apply_to_databaserebuilds an index whose comment differs from its definition, somigrations/19.0.2.5.0/pre-migration.pygives the two existing indexes the comment the ORM expects. The directory name assumes the next minor bump; rename it if the bot bumps another version, otherwise the first update rebuilds the two indexes once.Index that replaces the removed one
Measured: the same query with and without the index
EXPLAIN (ANALYZE, VERBOSE, BUFFERS) SELECT id FROM <table> WHERE <column> = <value>on the staging copy of 2026-11-09 (PostgreSQL 18.6,work_mem16MB, a database of about 200 GB). Each plan is run twice inside a transaction and the second is kept. "Without" is aDROP INDEXof the removed index in the same transaction (rolled back afterwards). Two values per column: the most frequent one and one of median frequency.enable_seqscan=offwas set so that every plan uses an index, otherwise the small tables answer with a sequential scan in both cases. Buffers (shared hit + read) are the number to compare; the milliseconds move with the cache.queue.job.channelqueue_job__channel_indexqueue_job_channel_date_done_date_created_index(channel, date_done, date_created)Not confirmed as unnecessary. The narrow index reads fewer pages when the lookup is by that column alone and unselective:
mail.followers.res_model = <most frequent model>(about 8M rows): 125,235 buffers with the simple index, 3,718,346 without it (2.5 s -> 7.6 s forced; 3.1 s -> 5.6 s when the planner chooses). With a selective value (249 rows) both cost the same.queue.job.channel: the most frequent value (3.2M rows) costs the same (863,143 vs 878,710 buffers), a median one (787K rows) reads 416,475 buffers with the simple index and 703,278 without it.The other 26 fields cost the same or within a few pages; the "wider index reads more" mark on the small tables (
account.journal.company_id,portal_donor.card.type.name, ...) is a difference of tens of pages on tables that answer in less than 1 ms.Checked with a real
-u allOn a clone of a migrated database (about 200 GB,
queue_jobwith 3.2M rows), with the comments set by hand to the same text as the pre-migration (the manifest version was not bumped, so the script itself did not run):-u allended with RC=0 andodoo.schemaat DEBUG logged no index event forqueue_job, so neither index was rebuilt. A second-u alllogged no index creation or drop at all. The OCA test suite was not run.