Remove useless filtring in events&actions sql - #134
Conversation
| pending_chain | ||
| WHERE 1=1 | ||
| ${ | ||
| // If fromAsNum is not undefined, then we have also set toAsNum and can safely query the range |
There was a problem hiding this comment.
I think these are auto format.
|
|
||
| # docker-compose postgres volumes | ||
| db/ | ||
| /db/ |
There was a problem hiding this comment.
src/db will be ignored without this
| FROM | ||
| blocks b | ||
| INNER JOIN pending_chain ON b.id = pending_chain.parent_id | ||
| AND pending_chain.id <> pending_chain.parent_id |
There was a problem hiding this comment.
I am not confident that this can never be true. I just don't know the Mina spec well enough. What is gained by removing this filter? Is the performance notably better?
There was a problem hiding this comment.
No I don't think the perf would be much better. It's just this logic is very confusing here when I'm reading the code
|
Thanks for digging into this and backing it with the Two small things before merge:
Also, the branch is ~6 weeks behind |
…nvariant The reviewer flagged that this PR dropped the id <> parent_id guard from fullChainCTE but left the identical one in getZkappsWithPendingEventsQuery, so the file contradicted itself on whether the guard was needed. Removed it there too, and documented the invariant both places rely on: no block is its own parent (parent_id is a FK to blocks.id; a self-reference would be a cycle), and the recursive walk terminates on genesis's NULL parent_id regardless — so the guard never excludes a row. Verified against the checked-in integration fixture: 39 blocks, 0 with id = parent_id, exactly 1 with parent_id IS NULL. The comment points a future schema/hard-fork change that ever self-references a block at the spot that would loop, so it surfaces in review rather than as a query hang. Integration suite (25 tests) green; the modified recursive query executes cleanly against the fixture without looping. Addresses review feedback on #134. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This is confirmed by running this on a online archive db: