Skip to content

Index build job metadata lookups - #92

Merged
alexanderoster merged 1 commit into
alexanderoster:developfrom
krixkrix:metadata-lookup-indices
Oct 26, 2026
Merged

alexanderoster merged 1 commit into
alexanderoster:developfrom
krixkrix:metadata-lookup-indices

Conversation

@krixkrix

Copy link
Copy Markdown

Every Has/Get/StoreMetaDataString on buildjobmetadata and buildjobexecutionmetadata filters on (owner uuid, metadatakey, active), but neither table has an index, so each lookup scans the whole table. The tables grow with every job and execution, so opening a job's details gets slower as the build history grows: in a synthetic database with 460k metadata rows, reading 46 keys took 2.4 s, and 0.7 ms with the indices.

The indices are created by a new CDatabaseMigrationClass::ensureIndices hook that runs after the schema migration on every start (CREATE INDEX IF NOT EXISTS). Existing databases get them on their next start without a schema version step, and no table or data changes.

Unit tests check the query plans on a new database and on a database created without the indices.

Every Has/Get/StoreMetaDataString on buildjobmetadata and
buildjobexecutionmetadata filters on (owner uuid, metadatakey, active),
but neither table has an index, so each lookup scans the whole table.
The tables grow with every job and execution, so opening a job's details
gets slower as the build history grows: in a synthetic database with
460k metadata rows, reading 46 keys took 2.4 s, and 0.7 ms with the
indices.

The indices are created by a new CDatabaseMigrationClass::ensureIndices
hook that runs after the schema migration on every start
(CREATE INDEX IF NOT EXISTS). Existing databases get them on their next
start without a schema version step, and no table or data changes.

Unit tests check the query plans on a new database and on a database
created without the indices.
@alexanderoster

Copy link
Copy Markdown
Owner

Great find, thank you!

@alexanderoster
alexanderoster merged commit 138b7e5 into alexanderoster:develop Oct 26, 2026
1 of 2 checks passed
@krixkrix
krixkrix deleted the metadata-lookup-indices branch November 4, 2026 16:26
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