Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create index on SequencedLeafData(TreeId, LeafIdentityHash) #3695

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robstradling
Copy link
Contributor

@robstradling robstradling commented Dec 9, 2024

In the PostgreSQL storage backend, the selectLeavesByLeafIdentityHashSQL query in log_storage.go will currently do a full table scan on the SequencedLeafData table, because there's no index for joining on its LeafIdentifyHash and TreeId fields. This query is used by the QueueLeaves 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...

FOREIGN KEY(TreeId, LeafIdentityHash) REFERENCES LeafData(TreeId, LeafIdentityHash) ON DELETE CASCADE

...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

@robstradling robstradling requested review from mhutchinson, AlCutter and a team as code owners December 9, 2024 16:26
@roger2hk
Copy link
Contributor

roger2hk commented Dec 9, 2024

/gcbrun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants