-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize slot filter tx filter query
- Loading branch information
1 parent
28538c0
commit b0702f8
Showing
7 changed files
with
147 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
indexer/migration/src/m20240229_000019_add_block_tx_count_column.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use sea_schema::migration::prelude::*; | ||
|
||
use entity::block::*; | ||
|
||
pub struct Migration; | ||
|
||
impl MigrationName for Migration { | ||
fn name(&self) -> &str { | ||
"m20240229_000019_add_block_tx_count_column" | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.alter_table( | ||
Table::alter() | ||
.table(Entity) | ||
.add_column(ColumnDef::new(Column::TxCount).integer()) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.alter_table( | ||
Table::alter() | ||
.table(Entity) | ||
.drop_column(Column::TxCount) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 53 additions & 29 deletions
82
webserver/server/app/models/pagination/slotBoundsPagination.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,54 @@ | ||
/* @name slotBoundsPagination */ | ||
/* @name slotBoundsPagination */ | ||
WITH | ||
min_hash AS | ||
( | ||
SELECT COALESCE("Transaction".id, -1) AS min_tx_id, | ||
slot AS min_slot | ||
FROM "Transaction" | ||
JOIN "Block" | ||
ON "Block".id = "Transaction".block_id | ||
WHERE slot <= :low! | ||
ORDER BY "Block".id DESC, | ||
"Transaction".id DESC | ||
LIMIT 1 | ||
), | ||
max_hash AS | ||
( | ||
SELECT slot AS max_slot, | ||
COALESCE(Max("Transaction".id), -2) AS max_tx_id | ||
FROM "Transaction" | ||
JOIN "Block" | ||
ON "Transaction".block_id = "Block".id | ||
WHERE slot <= :high! | ||
GROUP BY "Block".id | ||
ORDER BY "Block".id DESC | ||
LIMIT 1 | ||
) | ||
SELECT * | ||
FROM min_hash | ||
LEFT JOIN max_hash | ||
ON 1 = 1; | ||
low_block AS ( | ||
SELECT | ||
"Block".id, | ||
"Block".slot | ||
FROM | ||
"Block" | ||
WHERE | ||
slot <= :low! AND tx_count > 0 | ||
ORDER BY | ||
"Block".id DESC | ||
LIMIT | ||
1 | ||
), | ||
high_block AS ( | ||
SELECT | ||
"Block".id, | ||
"Block".slot | ||
FROM | ||
"Block" | ||
WHERE | ||
slot <= :high! AND tx_count > 0 | ||
ORDER BY | ||
"Block".id DESC | ||
LIMIT | ||
1 | ||
), | ||
min_hash AS ( | ||
SELECT | ||
COALESCE(MAX("Transaction".id), -1) AS min_tx_id, | ||
slot AS min_slot | ||
FROM | ||
"Transaction" | ||
JOIN low_block ON "Transaction".block_id = low_block.id | ||
GROUP BY | ||
low_block.slot | ||
LIMIT | ||
1 | ||
), | ||
max_hash AS ( | ||
SELECT | ||
COALESCE(MAX("Transaction".id), -2) AS max_tx_id, | ||
slot AS max_slot | ||
FROM | ||
"Transaction" | ||
JOIN high_block ON "Transaction".block_id = high_block.id | ||
GROUP BY | ||
high_block.slot | ||
) | ||
SELECT | ||
* | ||
FROM min_hash | ||
LEFT JOIN max_hash ON 1 = 1; |