From 5ff94c72abce8c135531514c7eccdbf6e3ae52f2 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 4 Oct 2024 11:48:48 +0200 Subject: [PATCH] query cache --- ...7794340f8ff29933f69a80edb321ce4010306.json | 213 ++++++++++++++++++ ...9228b7c8b73430fea33364288987abc341995.json | 213 ------------------ 2 files changed, 213 insertions(+), 213 deletions(-) create mode 100644 .sqlx/query-21193630991ce15c085a35fe0457794340f8ff29933f69a80edb321ce4010306.json delete mode 100644 .sqlx/query-39ef23d0458033aaac5261361369228b7c8b73430fea33364288987abc341995.json diff --git a/.sqlx/query-21193630991ce15c085a35fe0457794340f8ff29933f69a80edb321ce4010306.json b/.sqlx/query-21193630991ce15c085a35fe0457794340f8ff29933f69a80edb321ce4010306.json new file mode 100644 index 0000000..4a83990 --- /dev/null +++ b/.sqlx/query-21193630991ce15c085a35fe0457794340f8ff29933f69a80edb321ce4010306.json @@ -0,0 +1,213 @@ +{ + "db_name": "PostgreSQL", + "query": "WITH\n canonical_blocks AS (\n SELECT\n *\n FROM\n blocks\n WHERE\n chain_status='canonical'\n ),\n max_canonical_height AS (\n SELECT\n max(HEIGHT) AS max_height\n FROM\n canonical_blocks\n ),\n pending_blocks AS (\n SELECT\n b.*\n FROM\n blocks AS b,\n max_canonical_height AS m\n WHERE\n b.height>m.max_height\n AND b.chain_status='pending'\n ),\n blocks AS (\n SELECT\n *\n FROM\n canonical_blocks\n UNION ALL\n SELECT\n *\n FROM\n pending_blocks\n ),\n user_command_info AS (\n SELECT DISTINCT\n ON (\n buc.block_id,\n buc.user_command_id,\n buc.sequence_no\n ) u.id,\n u.command_type AS \"command_type: UserCommandType\",\n u.fee_payer_id,\n u.source_id,\n u.receiver_id,\n u.nonce,\n u.amount,\n u.fee,\n u.valid_until,\n u.memo,\n u.hash,\n buc.block_id,\n buc.sequence_no,\n buc.status AS \"status: TransactionStatus\",\n buc.failure_reason,\n b.state_hash,\n b.chain_status AS \"chain_status: ChainStatus\",\n b.height\n FROM\n user_commands AS u\n INNER JOIN blocks_user_commands AS buc ON u.id=buc.user_command_id\n INNER JOIN public_keys AS pk ON u.fee_payer_id=pk.id\n OR (\n buc.status='applied'\n AND (\n u.source_id=pk.id\n OR u.receiver_id=pk.id\n )\n )\n INNER JOIN blocks AS b ON buc.block_id=b.id\n WHERE\n (\n $1<=b.height\n OR $1 IS NULL\n )\n AND (\n $2=u.hash\n OR $2 IS NULL\n )\n AND (\n $3=pk.value\n AND $4=''\n OR (\n $3 IS NULL\n AND $4 IS NULL\n )\n )\n AND (\n $5=buc.status\n OR $5 IS NULL\n )\n AND (\n $6=buc.status\n OR $6 IS NULL\n )\n AND (\n $7=pk.value\n OR $7 IS NULL\n )\n ),\n id_count AS (\n SELECT\n count(*) AS total_count\n FROM\n user_command_info\n )\nSELECT\n u.*,\n id_count.total_count,\n pk_payer.value AS fee_payer,\n pk_source.value AS source,\n pk_receiver.value AS receiver,\n ac.creation_fee AS \"creation_fee?\"\nFROM\n id_count,\n (\n SELECT\n *\n FROM\n user_command_info\n ORDER BY\n block_id,\n id,\n sequence_no\n LIMIT\n $8\n OFFSET\n $9\n ) AS u\n INNER JOIN public_keys AS pk_payer ON u.fee_payer_id=pk_payer.id\n INNER JOIN public_keys AS pk_source ON u.source_id=pk_source.id\n INNER JOIN public_keys AS pk_receiver ON u.receiver_id=pk_receiver.id\n /* Account creation fees are attributed to the first successful command in the\n block that mentions the account with the following LEFT JOINs */\n LEFT JOIN account_identifiers AS ai_receiver ON u.receiver_id=ai_receiver.public_key_id\n LEFT JOIN accounts_created AS ac ON u.block_id=ac.block_id\n AND ai_receiver.id=ac.account_identifier_id\n AND u.\"status: TransactionStatus\"='applied'\n AND u.sequence_no=(\n SELECT\n least(\n (\n SELECT\n min(bic2.sequence_no)\n FROM\n blocks_internal_commands AS bic2\n INNER JOIN internal_commands AS ic2 ON bic2.internal_command_id=ic2.id\n WHERE\n u.receiver_id=ic2.receiver_id\n AND bic2.block_id=u.block_id\n AND bic2.status='applied'\n ),\n (\n SELECT\n min(buc2.sequence_no)\n FROM\n blocks_user_commands AS buc2\n INNER JOIN user_commands AS uc2 ON buc2.user_command_id=uc2.id\n WHERE\n u.receiver_id=uc2.receiver_id\n AND buc2.block_id=u.block_id\n AND buc2.status='applied'\n )\n )\n )\nORDER BY\n u.block_id,\n u.id,\n u.sequence_no\n", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "command_type: UserCommandType", + "type_info": { + "Custom": { + "name": "user_command_type", + "kind": { + "Enum": [ + "payment", + "delegation" + ] + } + } + } + }, + { + "ordinal": 2, + "name": "fee_payer_id", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "source_id", + "type_info": "Int4" + }, + { + "ordinal": 4, + "name": "receiver_id", + "type_info": "Int4" + }, + { + "ordinal": 5, + "name": "nonce", + "type_info": "Int8" + }, + { + "ordinal": 6, + "name": "amount", + "type_info": "Text" + }, + { + "ordinal": 7, + "name": "fee", + "type_info": "Text" + }, + { + "ordinal": 8, + "name": "valid_until", + "type_info": "Int8" + }, + { + "ordinal": 9, + "name": "memo", + "type_info": "Text" + }, + { + "ordinal": 10, + "name": "hash", + "type_info": "Text" + }, + { + "ordinal": 11, + "name": "block_id", + "type_info": "Int4" + }, + { + "ordinal": 12, + "name": "sequence_no", + "type_info": "Int4" + }, + { + "ordinal": 13, + "name": "status: TransactionStatus", + "type_info": { + "Custom": { + "name": "transaction_status", + "kind": { + "Enum": [ + "applied", + "failed" + ] + } + } + } + }, + { + "ordinal": 14, + "name": "failure_reason", + "type_info": "Text" + }, + { + "ordinal": 15, + "name": "state_hash", + "type_info": "Text" + }, + { + "ordinal": 16, + "name": "chain_status: ChainStatus", + "type_info": { + "Custom": { + "name": "chain_status_type", + "kind": { + "Enum": [ + "canonical", + "orphaned", + "pending" + ] + } + } + } + }, + { + "ordinal": 17, + "name": "height", + "type_info": "Int8" + }, + { + "ordinal": 18, + "name": "total_count", + "type_info": "Int8" + }, + { + "ordinal": 19, + "name": "fee_payer", + "type_info": "Text" + }, + { + "ordinal": 20, + "name": "source", + "type_info": "Text" + }, + { + "ordinal": 21, + "name": "receiver", + "type_info": "Text" + }, + { + "ordinal": 22, + "name": "creation_fee?", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Int8", + "Text", + "Text", + "Text", + { + "Custom": { + "name": "transaction_status", + "kind": { + "Enum": [ + "applied", + "failed" + ] + } + } + }, + { + "Custom": { + "name": "transaction_status", + "kind": { + "Enum": [ + "applied", + "failed" + ] + } + } + }, + "Text", + "Int8", + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + true, + false, + true, + false, + false, + false, + false, + false, + true, + null, + null, + null, + null, + false, + false, + false, + false + ] + }, + "hash": "21193630991ce15c085a35fe0457794340f8ff29933f69a80edb321ce4010306" +} diff --git a/.sqlx/query-39ef23d0458033aaac5261361369228b7c8b73430fea33364288987abc341995.json b/.sqlx/query-39ef23d0458033aaac5261361369228b7c8b73430fea33364288987abc341995.json deleted file mode 100644 index b324ed6..0000000 --- a/.sqlx/query-39ef23d0458033aaac5261361369228b7c8b73430fea33364288987abc341995.json +++ /dev/null @@ -1,213 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH canonical_blocks AS (\n SELECT * FROM blocks WHERE chain_status = 'canonical'\n),\n\nmax_canonical_height AS (\n SELECT MAX(height) AS max_height FROM canonical_blocks\n),\n\npending_blocks AS (\n SELECT b.*\n FROM blocks AS b, max_canonical_height AS m\n WHERE b.height > m.max_height AND b.chain_status = 'pending'\n),\n\nblocks AS (\n SELECT * FROM canonical_blocks\n UNION ALL\n SELECT * FROM pending_blocks\n),\n\nuser_command_info AS (\n SELECT DISTINCT ON (buc.block_id, buc.user_command_id, buc.sequence_no)\n u.id,\n u.command_type AS \"command_type: UserCommandType\",\n u.fee_payer_id,\n u.source_id,\n u.receiver_id,\n u.nonce,\n u.amount,\n u.fee,\n u.valid_until,\n u.memo,\n u.hash,\n buc.block_id,\n buc.sequence_no,\n buc.status AS \"status: TransactionStatus\",\n buc.failure_reason,\n b.state_hash,\n b.chain_status AS \"chain_status: ChainStatus\",\n b.height\n FROM user_commands AS u\n INNER JOIN blocks_user_commands AS buc\n ON u.id = buc.user_command_id\n INNER JOIN public_keys AS pk\n ON\n u.fee_payer_id = pk.id\n OR (\n buc.status = 'applied'\n AND (u.source_id = pk.id OR u.receiver_id = pk.id)\n )\n INNER JOIN blocks AS b\n ON buc.block_id = b.id\n WHERE\n ($1 <= b.height OR $1 IS NULL)\n AND ($2 = u.hash OR $2 IS NULL)\n AND ($3 = pk.value AND $4 = '' OR ($3 IS NULL AND $4 IS NULL))\n AND ($5 = buc.status OR $5 IS NULL)\n AND ($6 = buc.status OR $6 IS NULL)\n AND ($7 = pk.value OR $7 IS NULL)\n),\n\nid_count AS (\n SELECT COUNT(*) AS total_count FROM user_command_info\n)\n\nSELECT\n u.*,\n id_count.total_count,\n pk_payer.value AS fee_payer,\n pk_source.value AS source,\n pk_receiver.value AS receiver,\n ac.creation_fee AS \"creation_fee?\"\nFROM id_count,\n (\n SELECT *\n FROM user_command_info\n ORDER BY block_id, id, sequence_no\n LIMIT $8 OFFSET $9\n ) AS u\nINNER JOIN public_keys AS pk_payer\n ON u.fee_payer_id = pk_payer.id\nINNER JOIN public_keys AS pk_source\n ON u.source_id = pk_source.id\nINNER JOIN public_keys AS pk_receiver\n ON u.receiver_id = pk_receiver.id\n/* Account creation fees are attributed to the first successful command in the\n block that mentions the account with the following LEFT JOINs */\nLEFT JOIN account_identifiers AS ai_receiver\n ON u.receiver_id = ai_receiver.public_key_id\nLEFT JOIN accounts_created AS ac\n ON\n u.block_id = ac.block_id\n AND ai_receiver.id = ac.account_identifier_id\n AND u.\"status: TransactionStatus\" = 'applied'\n AND u.sequence_no\n = (SELECT LEAST(\n (\n SELECT MIN(bic2.sequence_no)\n FROM blocks_internal_commands AS bic2\n INNER JOIN internal_commands AS ic2\n ON bic2.internal_command_id = ic2.id\n WHERE\n u.receiver_id = ic2.receiver_id\n AND bic2.block_id = u.block_id\n AND bic2.status = 'applied'\n ),\n (\n SELECT MIN(buc2.sequence_no)\n FROM blocks_user_commands AS buc2\n INNER JOIN user_commands AS uc2\n ON buc2.user_command_id = uc2.id\n WHERE\n u.receiver_id = uc2.receiver_id\n AND buc2.block_id = u.block_id\n AND buc2.status = 'applied'\n )\n ))\nORDER BY u.block_id, u.id, u.sequence_no\n", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "command_type: UserCommandType", - "type_info": { - "Custom": { - "name": "user_command_type", - "kind": { - "Enum": [ - "payment", - "delegation" - ] - } - } - } - }, - { - "ordinal": 2, - "name": "fee_payer_id", - "type_info": "Int4" - }, - { - "ordinal": 3, - "name": "source_id", - "type_info": "Int4" - }, - { - "ordinal": 4, - "name": "receiver_id", - "type_info": "Int4" - }, - { - "ordinal": 5, - "name": "nonce", - "type_info": "Int8" - }, - { - "ordinal": 6, - "name": "amount", - "type_info": "Text" - }, - { - "ordinal": 7, - "name": "fee", - "type_info": "Text" - }, - { - "ordinal": 8, - "name": "valid_until", - "type_info": "Int8" - }, - { - "ordinal": 9, - "name": "memo", - "type_info": "Text" - }, - { - "ordinal": 10, - "name": "hash", - "type_info": "Text" - }, - { - "ordinal": 11, - "name": "block_id", - "type_info": "Int4" - }, - { - "ordinal": 12, - "name": "sequence_no", - "type_info": "Int4" - }, - { - "ordinal": 13, - "name": "status: TransactionStatus", - "type_info": { - "Custom": { - "name": "transaction_status", - "kind": { - "Enum": [ - "applied", - "failed" - ] - } - } - } - }, - { - "ordinal": 14, - "name": "failure_reason", - "type_info": "Text" - }, - { - "ordinal": 15, - "name": "state_hash", - "type_info": "Text" - }, - { - "ordinal": 16, - "name": "chain_status: ChainStatus", - "type_info": { - "Custom": { - "name": "chain_status_type", - "kind": { - "Enum": [ - "canonical", - "orphaned", - "pending" - ] - } - } - } - }, - { - "ordinal": 17, - "name": "height", - "type_info": "Int8" - }, - { - "ordinal": 18, - "name": "total_count", - "type_info": "Int8" - }, - { - "ordinal": 19, - "name": "fee_payer", - "type_info": "Text" - }, - { - "ordinal": 20, - "name": "source", - "type_info": "Text" - }, - { - "ordinal": 21, - "name": "receiver", - "type_info": "Text" - }, - { - "ordinal": 22, - "name": "creation_fee?", - "type_info": "Text" - } - ], - "parameters": { - "Left": [ - "Int8", - "Text", - "Text", - "Text", - { - "Custom": { - "name": "transaction_status", - "kind": { - "Enum": [ - "applied", - "failed" - ] - } - } - }, - { - "Custom": { - "name": "transaction_status", - "kind": { - "Enum": [ - "applied", - "failed" - ] - } - } - }, - "Text", - "Int8", - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - false, - true, - false, - true, - false, - false, - false, - false, - false, - true, - null, - null, - null, - null, - false, - false, - false, - false - ] - }, - "hash": "39ef23d0458033aaac5261361369228b7c8b73430fea33364288987abc341995" -}