Create index on SequencedLeafData(TreeId, LeafIdentityHash) #3695
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.
In the PostgreSQL storage backend, the
selectLeavesByLeafIdentityHashSQL
query inlog_storage.go
will currently do a full table scan on theSequencedLeafData
table, because there's no index for joining on itsLeafIdentifyHash
andTreeId
fields. This query is used by theQueueLeaves
operation when any of the to-be-queued leaves already exist.This PR adds an appropriate
CREATE INDEX
statement in each of the PostgreSQL, MySQL, and CockroachDB storage backends.Since there's already a corresponding foreign key constraint on the
SequencedLeafData
table......and since MySQL requires that foreign key columns be indexed; if you create a table with a foreign key constraint but no index on a given column, an index is created, it appears that this PR is effectively a no-op for MySQL/MariaDB.
PostgreSQL doesn't automatically create indexes for foreign keys though, so this PR is needed in that context. I'm not sure what the behaviour is for CockroachDB.
I think it makes sense to keep the PostgreSQL, MySQL, and CockroachDB schema scripts as similar as possible, but if it's preferred to reduce the scope of this PR to only update the PostgreSQL backend then I can do that.
Checklist