Skip to content

Commit

Permalink
Fix query (#2263)
Browse files Browse the repository at this point in the history
Signed-off-by: deniallugo <[email protected]>
  • Loading branch information
Deniallugo committed Jul 29, 2022
1 parent 7c0df4b commit 797ae9e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
42 changes: 21 additions & 21 deletions core/lib/storage/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2368,27 +2368,6 @@
"nullable": []
}
},
"437718be33383e1db84110963f08d50fcca36fb6ce174d26109f556ee0ec87e7": {
"query": "\n SELECT GREATEST(\n (SELECT MAX(block_number) FROM account_balance_updates\n WHERE account_id = $1 AND block_number >= $2),\n (SELECT MAX(block_number) FROM account_creates\n WHERE account_id = $1 AND block_number >= $2),\n (SELECT MAX(block_number) FROM account_pubkey_updates\n WHERE account_id = $1 AND block_number >= $2)\n )\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "greatest",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8",
"Int8"
]
},
"nullable": [
null
]
}
},
"439d0083a3b98066071cde5909969b4e9ce744bc1bfa761116c6fb5bcc356075": {
"query": "DELETE FROM account_balance_updates WHERE block_number > $1",
"describe": {
Expand Down Expand Up @@ -6276,6 +6255,27 @@
]
}
},
"bf64c3301d4a81968a1220319fae8ec04063f7a83757da850e3f8f5aed121750": {
"query": "\n SELECT GREATEST(\n (SELECT block_number FROM account_balance_updates\n WHERE account_id = $1 AND block_number >= $2 ORDER BY block_number DESC LIMIT 1\n ),\n (SELECT block_number FROM account_creates\n WHERE account_id = $1 AND block_number >= $2 ORDER BY block_number DESC LIMIT 1\n ),\n (SELECT block_number FROM account_pubkey_updates\n WHERE account_id = $1 AND block_number >= $2 ORDER BY block_number DESC LIMIT 1\n )\n )\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "greatest",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8",
"Int8"
]
},
"nullable": [
null
]
}
},
"bf88992c521353535925401702028307ba3d79dfa2e60d939a117e7aae5a6403": {
"query": "SELECT MAX(number) FROM blocks",
"describe": {
Expand Down
15 changes: 9 additions & 6 deletions core/lib/storage/src/chain/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,15 @@ impl<'a, 'c> AccountSchema<'a, 'c> {
let block_number = sqlx::query!(
"
SELECT GREATEST(
(SELECT MAX(block_number) FROM account_balance_updates
WHERE account_id = $1 AND block_number >= $2),
(SELECT MAX(block_number) FROM account_creates
WHERE account_id = $1 AND block_number >= $2),
(SELECT MAX(block_number) FROM account_pubkey_updates
WHERE account_id = $1 AND block_number >= $2)
(SELECT block_number FROM account_balance_updates
WHERE account_id = $1 AND block_number >= $2 ORDER BY block_number DESC LIMIT 1
),
(SELECT block_number FROM account_creates
WHERE account_id = $1 AND block_number >= $2 ORDER BY block_number DESC LIMIT 1
),
(SELECT block_number FROM account_pubkey_updates
WHERE account_id = $1 AND block_number >= $2 ORDER BY block_number DESC LIMIT 1
)
)
",
i64::from(*account_id),
Expand Down

0 comments on commit 797ae9e

Please sign in to comment.