Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
9cffa38f
Unverified
Commit
9cffa38f
authored
1 year ago
by
Ngoc Khuat
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Index unindexed FKs for Postgres (#33578)
parent
e55e7f78
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
resources/migrations/000_migrations.yaml
+44
-0
44 additions, 0 deletions
resources/migrations/000_migrations.yaml
test/metabase/db/schema_migrations_test.clj
+22
-0
22 additions, 0 deletions
test/metabase/db/schema_migrations_test.clj
with
66 additions
and
0 deletions
resources/migrations/000_migrations.yaml
+
44
−
0
View file @
9cffa38f
...
...
@@ -15159,6 +15159,50 @@ databaseChangeLog:
column:
name: action_id
- changeSet:
id: v48.00-013
author: qnkhuat
comment: Index unindexed FKs for postgres
preConditions:
- onFail: MARK_RAN
- dbms:
type: postgresql
changes:
- sql:
sql: >-
CREATE INDEX IF NOT EXISTS idx_action_made_public_by_id ON action (made_public_by_id);
CREATE INDEX IF NOT EXISTS idx_action_model_id ON action (model_id);
CREATE INDEX IF NOT EXISTS idx_application_permissions_revision_user_id ON application_permissions_revision (user_id);
CREATE INDEX IF NOT EXISTS idx_collection_permission_graph_revision_user_id ON collection_permission_graph_revision (user_id);
CREATE INDEX IF NOT EXISTS idx_core_session_user_id ON core_session (user_id);
CREATE INDEX IF NOT EXISTS idx_dashboard_tab_dashboard_id ON dashboard_tab (dashboard_id);
CREATE INDEX IF NOT EXISTS idx_dimension_human_readable_field_id ON dimension (human_readable_field_id);
CREATE INDEX IF NOT EXISTS idx_metabase_database_creator_id ON metabase_database (creator_id);
CREATE INDEX IF NOT EXISTS idx_model_index_creator_id ON model_index (creator_id);
CREATE INDEX IF NOT EXISTS idx_native_query_snippet_creator_id ON native_query_snippet (creator_id);
CREATE INDEX IF NOT EXISTS idx_permissions_revision_user_id ON permissions_revision (user_id);
CREATE INDEX IF NOT EXISTS idx_persisted_info_creator_id ON persisted_info (creator_id);
CREATE INDEX IF NOT EXISTS idx_persisted_info_database_id ON persisted_info (database_id);
CREATE INDEX IF NOT EXISTS idx_pulse_dashboard_id ON pulse (dashboard_id);
CREATE INDEX IF NOT EXISTS idx_pulse_card_dashboard_card_id ON pulse_card (dashboard_card_id);
CREATE INDEX IF NOT EXISTS idx_pulse_channel_recipient_pulse_channel_id ON pulse_channel_recipient (pulse_channel_id);
CREATE INDEX IF NOT EXISTS idx_pulse_channel_recipient_user_id ON pulse_channel_recipient (user_id);
CREATE INDEX IF NOT EXISTS idx_query_action_database_id ON query_action (database_id);
CREATE INDEX IF NOT EXISTS idx_report_card_database_id ON report_card (database_id);
CREATE INDEX IF NOT EXISTS idx_report_card_made_public_by_id ON report_card (made_public_by_id);
CREATE INDEX IF NOT EXISTS idx_report_card_table_id ON report_card (table_id);
CREATE INDEX IF NOT EXISTS idx_report_dashboard_made_public_by_id ON report_dashboard (made_public_by_id);
CREATE INDEX IF NOT EXISTS idx_report_dashboardcard_action_id ON report_dashboardcard (action_id);
CREATE INDEX IF NOT EXISTS idx_report_dashboardcard_dashboard_tab_id ON report_dashboardcard (dashboard_tab_id);
CREATE INDEX IF NOT EXISTS idx_revision_user_id ON revision (user_id);
CREATE INDEX IF NOT EXISTS idx_sandboxes_card_id ON sandboxes (card_id);
CREATE INDEX IF NOT EXISTS idx_sandboxes_permission_id ON sandboxes (permission_id);
CREATE INDEX IF NOT EXISTS idx_secret_creator_id ON secret (creator_id);
CREATE INDEX IF NOT EXISTS idx_timeline_creator_id ON timeline (creator_id);
CREATE INDEX IF NOT EXISTS idx_timeline_event_creator_id ON timeline_event (creator_id);
rollback: # no need
# >>>>>>>>>> DO NOT ADD NEW MIGRATIONS BELOW THIS LINE! ADD THEM ABOVE <<<<<<<<<<
########################################################################################################################
...
...
This diff is collapsed.
Click to expand it.
test/metabase/db/schema_migrations_test.clj
+
22
−
0
View file @
9cffa38f
...
...
@@ -1115,3 +1115,25 @@
;; Only the sandbox with a corresponding `Permissions` row is present
(
is
(
=
[{
:id
1
,
:group_id
1
,
:table_id
table-id,
:card_id
nil,
:attribute_remappings
"{\"foo\", 1}"
,
:permission_id
perm-id
}]
(
mdb.query/query
{
:select
[
:*
]
:from
[
:sandboxes
]})))))))
(
deftest
fks-are-indexed-test
(
mt/test-driver
:postgres
(
testing
"all FKs should be indexed"
(
is
(
=
[]
(
t2/query
"SELECT
conrelid::regclass AS table_name,
a.attname AS column_name
FROM
pg_constraint AS c
JOIN pg_attribute AS a ON a.attnum = ANY(c.conkey) AND a.attrelid = c.conrelid
WHERE
c.contype = 'f'
AND NOT EXISTS (
SELECT 1
FROM pg_index AS i
WHERE i.indrelid = c.conrelid
AND a.attnum = ANY(i.indkey)
)
ORDER BY
table_name,
column_name;"
))))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment