Skip to content

Commit 136841f

Browse files
committed
perf(jsonrpc): add DB index to improve filter of executed outputs
- Added partial index output_executed_idx on input_epoch_application_id. - The index contains only rows where execution_transaction_hash IS NOT NULL. - Added the corresponding down-migration statement.
1 parent e8f6796 commit 136841f

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

internal/repository/postgres/schema/migrations/000001_create_initial_schema.down.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ DROP TABLE IF EXISTS "withdrawal";
3737

3838
DROP TRIGGER IF EXISTS "output_set_updated_at" ON "output";
3939
DROP INDEX IF EXISTS "output_pending_voucher_idx";
40+
DROP INDEX IF EXISTS "output_executed_idx";
4041
DROP INDEX IF EXISTS "output_raw_data_address_idx";
4142
DROP INDEX IF EXISTS "output_raw_data_type_idx";
4243
DROP TABLE IF EXISTS "output";

internal/repository/postgres/schema/migrations/000001_create_initial_schema.up.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ WHERE "execution_transaction_hash" IS NULL AND SUBSTRING("raw_data" FROM 1 FOR 4
450450
E'\\x237a816f' -- Voucher
451451
);
452452

453+
-- Serves GetNumberOfExecutedOutputs without scanning the application's full
454+
-- output history. Outputs enter this index only after execution is observed.
455+
CREATE INDEX "output_executed_idx" ON "output" ("input_epoch_application_id")
456+
WHERE "execution_transaction_hash" IS NOT NULL;
457+
453458
CREATE TRIGGER "output_set_updated_at" BEFORE UPDATE ON "output"
454459
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
455460

0 commit comments

Comments
 (0)