Repository navigation
Plan a compiled write's per-row loop on Postgres without materializing, so a node table whose statistics say it is near empty isn't read whole for each row (#430) - #441
Merged
Conversation
…g, so a node table whose statistics say it is near empty isn't read whole for each row (#430) #420 turned off seq scans and hash and merge joins around a compiled write's per-row loop. Once an autoanalyze just after a DELETE left the node table's statistics at about one row while it still held many pages, a CALL's rows were joined to it through a Materialize over a full scan of its primary-key index, so each row read the whole table: CALL...RETURN took 72 s to 142 s over 20,000 rows on CI. The loop now runs with enable_material off too, and the loop-time test forces that state.
This was referenced Nov 6, 2026
Merged
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #430. The reference fix is liberation-data/drivine4j#631; the TypeScript port is liberation-data/drivine#646.
Cause
#420 turned off
enable_seqscan,enable_hashjoinandenable_mergejoinaround a compiled write's per-row loop on Postgres. An autoanalyze that lands just after aDELETEleaves the node table's statistics at about one row, while the table still holds many pages. In that state, the loop's per-row join of a CALL's rows is planned like this:That is a full, unparameterized scan of the primary-key index under a Materialize, so every row reads the whole table.
MATCH (n:CyLoop) CALL (n) { SET n.y = n.i RETURN n.i AS j } RETURN count(j)took between 72 s and 142 s over 20,000 rows. It failed in 3 of about 4 CI runs, sync and async alike. On a test machine it happened 3 times in 400 runs, with auto_explain capturing the plan above.The fix
enable_materialjoins_JOIN_METHODS. Each wrapped loop now also runs with materialization off, so it reads the index by the row's key, and the setting is put back with the other three.enable_materialandcy_planner[4]). The other 1,058 Postgres statements are byte-identical.Tests
test_compiled_write_loop_time.py, async and sync: on Postgres, the test runsANALYZE drivine_noderight after itsDELETEand turns autovacuum off on that table while the writes are timed (reset infinally). Without the guard, an autoanalyze landing mid-run sometimes reset the statistics. With the bad state forced, the test fails every time without the fix (about 98 s over 20,000 rows) and passes with it (about 0.65 s).test_postgres_nested_loop_plan.pyandtest_postgres_nested_loop_settings.py: they cover the fourth setting, including its restore when the loop fails.Docs
docs/04-statements.mdnamesenable_material.Gate
ruff check,ruff format --check,pyrightandunasync --checkpass.