feat(datastore): add index on manifests subject_id field
What does this MR do?
In preparation for !2086 (merged), this adds the required indexes to make the new GC query performant. We need to merge and release this change first.
Related to #1489 (closed)
Query plan for !2086 (merged) after creating this index:
localhost jdrpereira@gitlabhq_registry_dblab=# explain (analyze) SELECT 1 FROM tags
WHERE top_level_namespace_id = 1569
AND repository_id = 1632081
AND manifest_id = 18534278
UNION ALL
SELECT 1 FROM manifest_references
WHERE top_level_namespace_id = 1569
AND repository_id = 1632081
AND child_id = 18534278
UNION ALL
SELECT 1 FROM manifests
WHERE top_level_namespace_id = 1569
AND repository_id = 1632081
AND subject_id = 18534278;
Append (cost=0.43..10.21 rows=3 width=4) (actual time=7.142..9.360 rows=1 loops=1)
-> Index Only Scan using index_tags_p_27_on_ns_id_and_repo_id_and_manifest_id_and_name on tags_p_27 tags (cost=0.43..3.45 rows=1 width=4) (actual time=7.141..7.142 rows=1 loops=1)
Index Cond: ((top_level_namespace_id = 1569) AND (repository_id = 1632081) AND (manifest_id = 18534278))
Heap Fetches: 0
-> Index Only Scan using manifest_references_p_27_top_level_namespace_id_repository__idx on manifest_references_p_27 manifest_references (cost=0.29..3.31 rows=1 width=4) (actual time=0.935..0.935 rows=0 loops=1)
Index Cond: ((top_level_namespace_id = 1569) AND (repository_id = 1632081) AND (child_id = 18534278))
Heap Fetches: 0
-> Index Only Scan using index_manifests_p_27_on_ns_id_and_repo_id_and_subject_id on manifests_p_27 manifests (cost=0.43..3.44 rows=1 width=4) (actual time=1.280..1.280 rows=0 loops=1)
Index Cond: ((top_level_namespace_id = 1569) AND (repository_id = 1632081) AND (subject_id = 18534278))
Heap Fetches: 0
Planning Time: 69.209 ms
Execution Time: 9.447 ms
Time: 275.770 ms
Author checklist
- Assign one of conventional-commit prefixes to the MR.
-
fix: Indicates a bug fix, triggers a patch release. -
feat: Signals the introduction of a new feature, triggers a minor release. -
perf: Focuses on performance improvements that don't introduce new features or fix bugs, triggers a patch release. -
docs: Updates or changes to documentation. Does not trigger a release. -
style: Changes that do not affect the code's functionality. Does not trigger a release. -
refactor: Modifications to the code that do not fix bugs or add features but improve code structure or readability. Does not trigger a release. -
test: Changes related to adding or modifying tests. Does not trigger a release. -
chore: Routine tasks that don't affect the application, such as updating build processes, package manager configs, etc. Does not trigger a release. -
build: Changes that affect the build system or external dependencies. May trigger a release. -
ci: Modifications to continuous integration configuration files and scripts. Does not trigger a release. -
revert: Reverts a previous commit. It could result in a patch, minor, or major release.
-
-
Feature flags
-
This change does not require a feature flag -
Added feature flag: ( Add the Feature flag tracking issue link here )
-
- Unit-tests
-
Unit-tests are not required -
I added unit tests
-
- Documentation:
-
Documentation is not required -
I added documentation -
I created or linked to an existing issue for every added or updated TODO,BUG,FIXMEorOPTIMIZEprefixed comment
-
-
database changes including schema/background migrations:
-
Change does not introduce database changes - MR includes DB chagnes
- Do not include code that depends on the schema migrations in the same commit. Split the MR into two or more.
-
Manually run up and down migrations in a postgres.ai production database clone and post a screenshot of the result here. -
If adding new queries, extract a query plan from postgres.ai and post the link here. If changing existing queries, also extract a query plan for the current version for comparison. -
I do not have access to postgres.ai and have made a comment on this MR asking for these to be run on my behalf.
-
-
If adding new background migration, follow the guide for performance testing new background migrations and add a report/summary to the MR with your analysis.
-
-
Ensured this change is safe to deploy to individual stages in the same environment ( cny->prod). State-related changes can be troublesome due to having parts of the fleet processing (possibly related) requests in different ways. -
If the change contains a breaking change, apply the breaking change label. -
If the change is considered high risk, apply the label high-risk-change - Changes cannot be rolled back
-
Change can be safelly rolled back - Change can't be safelly rolled back
-
Apply the label cannot-rollback. -
Add a section to the MR description that includes the following details: -
The reasoning behind why a release containing the presented MR can not be rolled back (e.g. schema migrations or changes to the FS structure) -
Detailed steps to revert/disable a feature introduced by the same change where a migration cannot be rolled back. (note: ideally MRs containing schema migrations should not contain feature changes.) -
Ensure this MR does not add code that depends on these changes that cannot be rolled back.
-
-
-
Reviewer checklist
-
Ensure the commit and MR tittle are still accurate. -
If the change contains a breaking change, verify the breaking change label. -
If the change is considered high risk, verify the label high-risk-change -
Identify if the change can be rolled back safely. (note: all other reasons for not being able to rollback will be sufficiently captured by major version changes).
Edited by João Pereira