From a36b2ae436381d655ff8d0c6edf0757cc86e71b1 Mon Sep 17 00:00:00 2001 From: ptrus Date: Wed, 18 Dec 2024 17:38:41 +0100 Subject: [PATCH] storage: rewrite RuntimeEvmVerifiedContractEvents --- .changelog/838.feature.md | 4 ++++ analyzer/queries/queries.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .changelog/838.feature.md diff --git a/.changelog/838.feature.md b/.changelog/838.feature.md new file mode 100644 index 000000000..b414ec55d --- /dev/null +++ b/.changelog/838.feature.md @@ -0,0 +1,4 @@ +Optimize `RuntimeEvmVerifiedContractEvents` query + +Optimizes the query by switching DECODE to ENCODE for address comparison +to leverage existing indexes on `chain.runtime_events` table. diff --git a/analyzer/queries/queries.go b/analyzer/queries/queries.go index fb0364b88..c999aec46 100644 --- a/analyzer/queries/queries.go +++ b/analyzer/queries/queries.go @@ -1143,7 +1143,7 @@ var ( JOIN chain.runtime_events as evs ON evs.type = 'evm.log' AND evs.runtime = abi_contracts.runtime AND - decode(body->>'address', 'base64') = preimages.address_data + body->>'address' = encode(preimages.address_data, 'base64') WHERE (evs.abi_parsed_at IS NULL OR evs.abi_parsed_at < abi_contracts.verification_info_downloaded_at) LIMIT $2`