Fix SIGSEGV re-executing a parameterized write query string (#862) - #863
Merged
Conversation
Re-executing the same parameterized write query (e.g. CREATE (:Log {id:
$id, value: $val})) through the implicit prepared-statement cache
crashed with SIGSEGV on the second execution. Reads and explicit
prepare()-without-params (which rebinds on every execute) were
unaffected.
On the second execution the cached-physical-plan fast path calls
prepareForReuse(), which reaches ResultCollector::prepareForReuse() and
FactorizedTable::clear(). For a write statement the root
ResultCollector's FactorizedTable has an empty result schema (writes
return no columns), and the FactorizedTable constructor skips allocating
flatTupleBlockCollection / unFlatTupleBlockCollection /
inMemOverflowBuffer entirely for an empty schema. clear() unconditionally
dereferenced the null block collection.
Fix: make FactorizedTable::clear() early-return for empty-schema tables,
mirroring the constructor's guard.
Add regression tests covering repeated executions of parameterized
CREATE, MATCH...SET, writes inside an explicit transaction, and
parameterized reads through the cached-plan fast path.
Fixes #862
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.
Summary
Calling
Connection.execute(<query string>, <params>)twice with the same string for a parameterized write query segfaulted on the second call (0.20.0 regression, #862). Reads and the explicitprepare()-without-params path were unaffected.Root cause
The Python string+params path implicitly prepares with its parameters bound, so the second execution takes the cached-physical-plan fast path in
ClientContext::executeNoLock(), which callsprepareForReuse()on the cloned plan. That reachesResultCollector::prepareForReuse()→FactorizedTable::clear().For a write statement, the plan's root
ResultCollectorhas an empty result schema (writes return no columns).FactorizedTable's constructor skips allocatingflatTupleBlockCollection/unFlatTupleBlockCollection/inMemOverflowBufferentirely when the schema is empty, butclear()unconditionally dereferenced the nullflatTupleBlockCollection— null-pointer SIGSEGV.This explains every variant in the issue:
prepare()once +execute()twice is unaffected (unknownParametersnon-empty →canReuseCachedPlanWith()returns false → rebind path, noprepareForReuse())Fix
FactorizedTable::clear()now early-returns for empty-schema tables, mirroring the constructor's guard. No behavior change for tables that do allocate.Testing
test/api/prepare_test.cpp:RepeatedExecuteCachedPlanParameterizedWrite: parameterizedCREATE×3, parameterizedMATCH ... SET×2, writes insideBEGIN TRANSACTION/COMMIT, final row-count verificationRepeatedExecuteCachedPlanParameterizedRead: guards the non-empty-schema path through the fast pathapi_testsuite: 283/283 passed; clang-format cleanFixes #862