Repository navigation
Make get_vertex see clause writes after a CALLed function runs statements - #2615
Open
ksaiharshavinay wants to merge 1 commit into
Open
ksaiharshavinay wants to merge 1 commit into
ksaiharshavinay wants to merge 1 commit into
Conversation
…ents A statement executed inside a function called with CALL goes through SPI, whose CommandCounterIncrement advances the global command id but not the curcid of the snapshot used by the executor. The clause machinery tracks curcid manually and assumes it stays in step, so after such a CALL the snapshot lags: a SET update later in the same query is stamped with a command id the snapshot cannot see, and properties(endNode(r)) returns the pre-update tuple even though the stored vertex is correct. A plain INSERT inside the called function triggers it too; DDL is not required. Apply the same save / advance-with-Max / restore pattern the executor's entity fetch in cypher_utils.c already uses, in get_vertex(), which backs startNode(), endNode() and _get_vertex_by_graphid. Add a regression test in cypher_call.sql with a no-op CALL as control and an index-creating CALL as the failing case. Fixes apache#2605
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.
Fixes #2605.
In the reported query, a
CALLto a PL/pgSQL function that createsan index on an unrelated label makes a later
SET n0.k4 = NULLinvisible to
properties(endNode(r)): it returns the pre-updateproperties even though the stored vertex is correct.
Root cause: any statement executed inside the called function goes
through SPI, which calls CommandCounterIncrement() when it finishes.
That advances the global command id but not the curcid of the
snapshot the executor is using. The executor's clause machinery
tracks curcid manually and assumes it stays in step with the global
command id, so after such a CALL the snapshot's curcid lags behind.
The SET update is then stamped with a command id the snapshot cannot
see, and the scan in get_vertex() returns the old tuple version.
(The same happens with a plain INSERT inside the called function -
DDL is not required.)
The executor's own entity fetch (entity_exists() in cypher_utils.c)
already guards against this by temporarily advancing the snapshot's
curcid to the current command id (and restoring it afterwards).
get_vertex() - used by startNode(), endNode() and
_get_vertex_by_graphid - did not. This change applies the same
pattern there: save, advance with Max, restore immediately after the
tuple fetch so no error path can leave the snapshot raised.
Regression tests in cypher_call.sql: the reported shape with a
no-op CALL as control, an index-creating CALL, and an
INSERT-executing CALL. Full suite: all 43 tests pass (PG 18.6, AGE
master).
Disclosure: this fix was developed with AI assistance (Claude), and
every change was reproduced, tested and reviewed locally by me.