Skip to content

Commit

Permalink
fix: provide index hint in QueryForCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Jun 19, 2023
1 parent 7182eca commit ebb1102
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion persistence/sql/identity/persister_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,17 @@ type Where struct {
// QueryForCredentials queries for identity credentials with custom WHERE
// clauses, returning the results resolved by the owning identity's UUID.
func QueryForCredentials(con *pop.Connection, joinOn string, where ...Where) (map[uuid.UUID](map[identity.CredentialsType]identity.Credentials), error) {
ici := "identity_credential_identifiers"
switch con.Dialect.Name() {
case "cockroach":
ici += "@identity_credential_identifiers_nid_identity_credential_id_idx"
case "sqlite3":
ici += " INDEXED BY identity_credential_identifiers_nid_identity_credential_id_idx"
case "mysql":
ici += " USE INDEX(identity_credential_identifiers_nid_identity_credential_id_idx)"
default:
// good luck 🤷‍♂️
}
q := con.Select(
"identity_credentials.id cred_id",
"identity_credentials.identity_id identity_id",
Expand All @@ -598,7 +609,7 @@ func QueryForCredentials(con *pop.Connection, joinOn string, where ...Where) (ma
"identity_credential_types ict",
"(identity_credentials.identity_credential_type_id = ict.id)",
).LeftJoin(
"identity_credential_identifiers",
ici,
joinOn,
)
for _, w := range where {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- nothing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- nothing: needed for foreign key anyways
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX identity_credential_identifiers_nid_identity_credential_id_idx ON identity_credential_identifiers (identity_credential_id, nid);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- index already exists

0 comments on commit ebb1102

Please sign in to comment.