Skip to content

Commit

Permalink
3803 vault indexes (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnickelsen authored Jan 13, 2025
1 parent c18df00 commit 16afb2d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
15 changes: 15 additions & 0 deletions src/ProjectOrigin.Vault/Database/Postgres/Scripts/v2/v2-0011.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE INDEX IF NOT EXISTS idx_wallet_slices_certificate_id_registry
ON public.wallet_slices
(certificate_id, registry_name);

CREATE INDEX IF NOT EXISTS idx_attributes_certificate_id_registry
ON public.attributes
(certificate_id, attribute_key, registry_name);

CREATE INDEX IF NOT EXISTS idx_wallet_attributes_certificate_wallet_attribute
ON public.wallet_attributes
(certificate_id, registry_name, attribute_key);

CREATE INDEX IF NOT EXISTS idx_wallet_slices_wallet_endpoint_id
ON public.wallet_slices
(wallet_endpoint_id);
12 changes: 6 additions & 6 deletions src/ProjectOrigin.Vault/Repositories/CertificateRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ CREATE TEMPORARY TABLE certificates_work_table ON COMMIT DROP AS (
SELECT * FROM certificates_work_table;
SELECT attributes.registry_name, attributes.certificate_id, attributes.attribute_key as key, attributes.attribute_value as value, attributes.attribute_type as type
FROM attributes_view attributes
WHERE (wallet_id IS NULL AND (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM certificates_work_table))
OR (wallet_id, registry_name, certificate_id) IN (SELECT wallet_id, registry_name, certificate_id FROM certificates_work_table)
WHERE (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM certificates_work_table)
AND (wallet_id IS NULL OR wallet_id in (SELECT DISTINCT(wallet_id) FROM certificates_work_table))
";

Expand Down Expand Up @@ -168,8 +168,8 @@ CREATE TEMPORARY TABLE certificates_work_table ON COMMIT DROP AS (
SELECT * FROM certificates_work_table WHERE (@UpdatedSince IS NULL OR updated_at > @UpdatedSince) LIMIT @limit;
SELECT attributes.registry_name, attributes.certificate_id, attributes.attribute_key as key, attributes.attribute_value as value, attributes.attribute_type as type
FROM attributes_view attributes
WHERE (wallet_id IS NULL AND (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM certificates_work_table))
OR (wallet_id, registry_name, certificate_id) IN (SELECT wallet_id, registry_name, certificate_id FROM certificates_work_table)
WHERE (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM certificates_work_table)
AND (wallet_id IS NULL OR wallet_id in (SELECT DISTINCT(wallet_id) FROM certificates_work_table))
";

Expand Down Expand Up @@ -233,8 +233,8 @@ ORDER BY
SELECT * FROM certificates_work_table LIMIT @limit OFFSET @skip;
SELECT attributes.registry_name, attributes.certificate_id, attributes.attribute_key as key, attributes.attribute_value as value, attributes.attribute_type as type
FROM attributes_view attributes
WHERE (wallet_id IS NULL AND (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM certificates_work_table))
OR (wallet_id, registry_name, certificate_id) IN (SELECT wallet_id, registry_name, certificate_id FROM certificates_work_table)
WHERE (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM certificates_work_table)
AND (wallet_id IS NULL OR wallet_id in (SELECT DISTINCT(wallet_id) FROM certificates_work_table))
";

using (var gridReader = await _connection.QueryMultipleAsync(sql, filter))
Expand Down
16 changes: 8 additions & 8 deletions src/ProjectOrigin.Vault/Repositories/ClaimRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ CREATE TEMPORARY TABLE claims_work_table ON COMMIT DROP AS (
SELECT * FROM claims_work_table WHERE (@UpdatedSince IS NULL OR updated_at > @UpdatedSince) LIMIT @limit;
SELECT attributes.registry_name, attributes.certificate_id, attributes.attribute_key as key, attributes.attribute_value as value, attributes.attribute_type as type
FROM attributes_view attributes
WHERE (wallet_id IS NULL AND (registry_name, certificate_id) IN (SELECT consumption_registry_name, consumption_certificate_id FROM claims_work_table))
OR (wallet_id IS NULL AND (registry_name, certificate_id) IN (SELECT production_registry_name, production_certificate_id FROM claims_work_table))
OR (registry_name, certificate_id, wallet_id) IN (SELECT consumption_registry_name, consumption_certificate_id, wallet_id FROM claims_work_table)
OR (registry_name, certificate_id, wallet_id) IN (SELECT production_registry_name, production_certificate_id, wallet_id FROM claims_work_table);
WHERE ((registry_name, certificate_id) IN (SELECT consumption_registry_name, consumption_certificate_id FROM claims_work_table)
AND (wallet_id IS NULL OR wallet_id in (SELECT DISTINCT(wallet_id) FROM claims_work_table)))
OR ((registry_name, certificate_id) IN (SELECT production_registry_name, production_certificate_id FROM claims_work_table)
AND (wallet_id IS NULL OR wallet_id in (SELECT DISTINCT(wallet_id) FROM claims_work_table)));
";

using (var gridReader = await _connection.QueryMultipleAsync(sql, filter))
Expand Down Expand Up @@ -138,10 +138,10 @@ CREATE TEMPORARY TABLE claims_work_table ON COMMIT DROP AS (
SELECT * FROM claims_work_table LIMIT @limit OFFSET @skip;
SELECT attributes.registry_name, attributes.certificate_id, attributes.attribute_key as key, attributes.attribute_value as value, attributes.attribute_type as type
FROM attributes_view attributes
WHERE (wallet_id IS NULL AND (registry_name, certificate_id) IN (SELECT consumption_registry_name, consumption_certificate_id FROM claims_work_table))
OR (wallet_id IS NULL AND (registry_name, certificate_id) IN (SELECT production_registry_name, production_certificate_id FROM claims_work_table))
OR (registry_name, certificate_id, wallet_id) IN (SELECT consumption_registry_name, consumption_certificate_id, wallet_id FROM claims_work_table)
OR (registry_name, certificate_id, wallet_id) IN (SELECT production_registry_name, production_certificate_id, wallet_id FROM claims_work_table);
WHERE ((registry_name, certificate_id) IN (SELECT consumption_registry_name, consumption_certificate_id FROM claims_work_table)
AND (wallet_id IS NULL OR wallet_id in (SELECT DISTINCT(wallet_id) FROM claims_work_table)))
OR ((registry_name, certificate_id) IN (SELECT production_registry_name, production_certificate_id FROM claims_work_table)
AND (wallet_id IS NULL OR wallet_id in (SELECT DISTINCT(wallet_id) FROM claims_work_table)));
";

using (var gridReader = await _connection.QueryMultipleAsync(sql, filter))
Expand Down
8 changes: 4 additions & 4 deletions src/ProjectOrigin.Vault/Repositories/TransferRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ CREATE TEMPORARY TABLE transfer_work_table ON COMMIT DROP AS (
SELECT * FROM transfer_work_table WHERE (@UpdatedSince IS NULL OR updated_at > @UpdatedSince) LIMIT @limit;
SELECT attributes.registry_name, attributes.certificate_id, attributes.attribute_key as key, attributes.attribute_value as value, attributes.attribute_type as type
FROM attributes_view attributes
WHERE (wallet_id IS NULL AND (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM transfer_work_table))
OR (wallet_id, registry_name, certificate_id) IN (SELECT wallet_id, registry_name, certificate_id FROM transfer_work_table)
WHERE (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM transfer_work_table)
AND (wallet_id IS NULL OR wallet_id in (SELECT DISTINCT(wallet_id) FROM transfer_work_table))
";

using (var gridReader = await _connection.QueryMultipleAsync(sql, filter))
Expand Down Expand Up @@ -112,8 +112,8 @@ CREATE TEMPORARY TABLE transfer_work_table ON COMMIT DROP AS (
SELECT * FROM transfer_work_table LIMIT @limit OFFSET @skip;
SELECT attributes.registry_name, attributes.certificate_id, attributes.attribute_key as key, attributes.attribute_value as value, attributes.attribute_type as type
FROM attributes_view attributes
WHERE (wallet_id IS NULL AND (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM transfer_work_table))
OR (wallet_id, registry_name, certificate_id) IN (SELECT wallet_id, registry_name, certificate_id FROM transfer_work_table)
WHERE (registry_name, certificate_id) IN (SELECT registry_name, certificate_id FROM transfer_work_table)
AND (wallet_id IS NULL OR wallet_id in (SELECT DISTINCT(wallet_id) FROM transfer_work_table))
";

using (var gridReader = await _connection.QueryMultipleAsync(sql, filter))
Expand Down

0 comments on commit 16afb2d

Please sign in to comment.