diff --git a/persistence/sql/migrations/sql/20221220124639000000_errors_index.down.sql b/persistence/sql/migrations/sql/20221220124639000000_errors_index.down.sql new file mode 100644 index 000000000000..706fa24ba79c --- /dev/null +++ b/persistence/sql/migrations/sql/20221220124639000000_errors_index.down.sql @@ -0,0 +1,3 @@ +CREATE INDEX selfservice_errors_nid_idx ON selfservice_errors (id, nid); + +DROP INDEX selfservice_errors_errors_nid_id_idx; diff --git a/persistence/sql/migrations/sql/20221220124639000000_errors_index.mysql.down.sql b/persistence/sql/migrations/sql/20221220124639000000_errors_index.mysql.down.sql new file mode 100644 index 000000000000..d07b35940e31 --- /dev/null +++ b/persistence/sql/migrations/sql/20221220124639000000_errors_index.mysql.down.sql @@ -0,0 +1,6 @@ +CREATE INDEX selfservice_errors_nid_idx ON selfservice_errors (id, nid); + +-- needed for foreign key constraint, was there before implicitly +CREATE INDEX selfservice_errors_nid_only_idx ON selfservice_errors (nid); + +DROP INDEX selfservice_errors_errors_nid_id_idx ON selfservice_errors; diff --git a/persistence/sql/migrations/sql/20221220124639000000_errors_index.mysql.up.sql b/persistence/sql/migrations/sql/20221220124639000000_errors_index.mysql.up.sql new file mode 100644 index 000000000000..30cbda798d8b --- /dev/null +++ b/persistence/sql/migrations/sql/20221220124639000000_errors_index.mysql.up.sql @@ -0,0 +1,4 @@ +CREATE INDEX selfservice_errors_errors_nid_id_idx ON selfservice_errors (nid, id); + +-- This index is not needed anymore, because the primary ID index together with the new index cover all queries. +DROP INDEX selfservice_errors_nid_idx ON selfservice_errors; diff --git a/persistence/sql/migrations/sql/20221220124639000000_errors_index.up.sql b/persistence/sql/migrations/sql/20221220124639000000_errors_index.up.sql new file mode 100644 index 000000000000..072022573e58 --- /dev/null +++ b/persistence/sql/migrations/sql/20221220124639000000_errors_index.up.sql @@ -0,0 +1,4 @@ +CREATE INDEX selfservice_errors_errors_nid_id_idx ON selfservice_errors (nid, id); + +-- This index is not needed anymore, because the primary ID index together with the new index cover all queries. +DROP INDEX selfservice_errors_nid_idx; diff --git a/persistence/sql/persister_courier.go b/persistence/sql/persister_courier.go index e4c08e87be3d..a51a46e2da36 100644 --- a/persistence/sql/persister_courier.go +++ b/persistence/sql/persister_courier.go @@ -7,7 +7,6 @@ import ( "context" "database/sql" "encoding/json" - "fmt" "github.com/gobuffalo/pop/v6" "github.com/gofrs/uuid" @@ -137,11 +136,7 @@ func (p *Persister) SetMessageStatus(ctx context.Context, id uuid.UUID, ms couri defer span.End() count, err := p.GetConnection(ctx).RawQuery( - // #nosec G201 - fmt.Sprintf( - "UPDATE %s SET status = ? WHERE id = ? AND nid = ?", - "courier_messages", - ), + "UPDATE courier_messages SET status = ? WHERE id = ? AND nid = ?", ms, id, p.NetworkID(ctx), @@ -162,11 +157,7 @@ func (p *Persister) IncrementMessageSendCount(ctx context.Context, id uuid.UUID) defer span.End() count, err := p.GetConnection(ctx).RawQuery( - // #nosec G201 - fmt.Sprintf( - "UPDATE %s SET send_count = send_count + 1 WHERE id = ? AND nid = ?", - "courier_messages", - ), + "UPDATE courier_messages SET send_count = send_count + 1 WHERE id = ? AND nid = ?", id, p.NetworkID(ctx), ).ExecWithCount()