Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added indexes and removed aggregate functions #231

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions database/bfgd/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
)

const (
bfgdVersion = 8
bfgdVersion = 9

logLevel = "INFO"
verbose = false
)

const effectiveHeightSql = `
COALESCE((SELECT MIN(height)
COALESCE((SELECT height

FROM
(
Expand All @@ -38,6 +38,7 @@ const effectiveHeightSql = `
= pop_basis.l2_keystone_abrev_hash

WHERE ll.l2_block_number >= l2_keystones.l2_block_number
ORDER BY height ASC LIMIT 1
)), 0)
`

Expand Down Expand Up @@ -808,7 +809,7 @@ func (p *pgdb) L2BTCFinalityByL2KeystoneAbrevHash(ctx context.Context, l2Keyston
l2_keystones.ep_hash,
l2_keystones.version,
%s,
COALESCE((SELECT MAX(height) FROM btc_blocks_can),0)
COALESCE((SELECT height FROM btc_blocks_can ORDER BY height DESC LIMIT 1),0)

FROM l2_keystones
LEFT JOIN pop_basis ON l2_keystones.l2_keystone_abrev_hash
Expand Down
12 changes: 12 additions & 0 deletions database/bfgd/scripts/0009.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Copyright (c) 2024 Hemi Labs, Inc.
-- Use of this source code is governed by the MIT License,
-- which can be found in the LICENSE file.

BEGIN;

UPDATE version SET version = 9;

CREATE INDEX btc_blocks_can_hash_idx ON btc_blocks_can (hash);
CREATE INDEX btc_blocks_can_height_idx ON btc_blocks_can (height);

COMMIT;