diff --git a/webserver/server/app/models/pagination/slotBoundsPagination.queries.ts b/webserver/server/app/models/pagination/slotBoundsPagination.queries.ts index c3de9024..4587b218 100644 --- a/webserver/server/app/models/pagination/slotBoundsPagination.queries.ts +++ b/webserver/server/app/models/pagination/slotBoundsPagination.queries.ts @@ -19,7 +19,7 @@ export interface ISlotBoundsPaginationQuery { result: ISlotBoundsPaginationResult; } -const slotBoundsPaginationIR: any = {"usedParamSet":{"low":true,"high":true},"params":[{"name":"low","required":true,"transform":{"type":"scalar"},"locs":[{"a":155,"b":159}]},{"name":"high","required":true,"transform":{"type":"scalar"},"locs":[{"a":409,"b":414}]}],"statement":"WITH\n low_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n slot <= :low! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT\n 1\n ),\n high_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n slot <= :high! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT 1\n ),\n min_hash AS (\n (SELECT\n COALESCE(MAX(\"Transaction\".id), -1) AS min_tx_id\n FROM\n \"Transaction\"\n JOIN low_block ON \"Transaction\".block_id = low_block.id\n GROUP BY\n low_block.slot\n LIMIT\n 1\n )\n UNION (SELECT min_tx_id FROM (values(-1)) s(min_tx_id))\n ORDER BY min_tx_id DESC\n LIMIT\n 1\n ),\n max_hash AS (\n SELECT\n COALESCE(MAX(\"Transaction\".id), -2) AS max_tx_id\n FROM\n \"Transaction\"\n JOIN high_block ON \"Transaction\".block_id = high_block.id\n GROUP BY\n high_block.slot\n )\nSELECT\n *\nFROM min_hash\nLEFT JOIN max_hash ON 1 = 1"}; +const slotBoundsPaginationIR: any = {"usedParamSet":{"low":true,"high":true},"params":[{"name":"low","required":true,"transform":{"type":"scalar"},"locs":[{"a":782,"b":786}]},{"name":"high","required":true,"transform":{"type":"scalar"},"locs":[{"a":1036,"b":1041}]}],"statement":"WITH\n low_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n \n slot <= :low! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT\n 1\n ),\n high_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n slot <= :high! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT 1\n ),\n min_hash AS (\n (SELECT\n COALESCE(MAX(\"Transaction\".id), -1) AS min_tx_id\n FROM\n \"Transaction\"\n JOIN low_block ON \"Transaction\".block_id = low_block.id\n GROUP BY\n low_block.slot\n LIMIT\n 1\n )\n UNION (SELECT min_tx_id FROM (values(-1)) s(min_tx_id))\n ORDER BY min_tx_id DESC\n LIMIT\n 1\n ),\n max_hash AS (\n SELECT\n COALESCE(MAX(\"Transaction\".id), -2) AS max_tx_id\n FROM\n \"Transaction\"\n JOIN high_block ON \"Transaction\".block_id = high_block.id\n GROUP BY\n high_block.slot\n )\nSELECT\n *\nFROM min_hash\nLEFT JOIN max_hash ON 1 = 1"}; /** * Query generated from SQL: @@ -32,6 +32,7 @@ const slotBoundsPaginationIR: any = {"usedParamSet":{"low":true,"high":true},"pa * FROM * "Block" * WHERE + * * slot <= :low! AND tx_count > 0 * ORDER BY * "Block".id DESC diff --git a/webserver/server/app/models/pagination/slotBoundsPagination.sql b/webserver/server/app/models/pagination/slotBoundsPagination.sql index 6fbaa75e..4527bccb 100644 --- a/webserver/server/app/models/pagination/slotBoundsPagination.sql +++ b/webserver/server/app/models/pagination/slotBoundsPagination.sql @@ -7,6 +7,21 @@ WITH FROM "Block" WHERE + /* + We use <= here even though slot filter parameter is exclusive on the + lower bound. This is because the tx that we find here (after joining + with min_hash) is used later in a condition of the form: + + "Transaction".id > :after_tx_id! + + For example. + + Lets say :low is 1, and there is a block with txs at this slot. This + means we want to find _at least_ the first tx in slot 2. + + So what we want in this query is to find the last tx in slot 1. + Then, when we use the > comparator we would get the right tx. + */ slot <= :low! AND tx_count > 0 ORDER BY "Block".id DESC