Repository navigation
Fix chained MATCH rebinding a zero-row variable into a path - #2627
Open
leo7martins wants to merge 1 commit into
Open
leo7martins wants to merge 1 commit into
leo7martins wants to merge 1 commit into
Conversation
A MATCH on a missing label projects NULL constants and a false WHERE, so it yields no rows. A following MATCH q = (var), including one after WITH, builds _agtype_build_path() around a Var that points at that constant. The function is IMMUTABLE and rejects NULL, and subquery pull-up substitutes the constant into the call. The planner evaluates it while folding constants and raises "argument 1 must not be null" instead of returning count 0. Same-clause paths already turned a NULL entity into a NULL path. Follow a rebound Var through subquery target lists and do the same when it refers to a NULL constant, so the function is not called. Non-empty matches still build the path from the real vertex. Fixes 2616
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 #2616.
On an empty graph, these queries abort with
ERROR: argument 1 must not be nullinstead of returningcount = 0:A fresh variable (
MATCH q = (zz)) returns 0. After one:rt3edge exists, the rebound query returns 1. This is the same error text as #882, reached through a chained MATCH that rebinds a variable.A missing label is compiled as a NULL agtype constant plus a false WHERE, so the first MATCH yields no rows. The following
MATCH q = (var)only sees a Var pointing at that constant and builds_agtype_build_path(var). That function is IMMUTABLE and not STRICT, and it raises on a NULL argument. Subquery pull-up substitutes the NULL constant into the call, and the planner evaluates it while folding constants, before the empty match can produce zero rows. A path in the same clause already turned a NULL entity expression into a NULL path; a rebound variable skipped that check because the expression is a Var. An existing label with no edges does not produce a NULL constant, and that query already returned 0.expr_is_null_constant()follows the Var through subquery target lists. When it reaches a NULL constant, the path variable is a NULL constant and_agtype_build_pathis not called. Matches that bind a real vertex still build the path from that vertex.SELECT _agtype_build_path(NULL)still errors.Regression cases in
regress/sql/cypher_match.sqlcover the empty chained MATCH, the empty WITH form, a fresh variable on the empty graph, and both rebound shapes after one edge.Tested on PostgreSQL 18.7:
argument 1 must not be null;MATCH q = (zz)returned 0; after one:rt3edge, the rebound query returned 1.make PG_CONFIG=/usr/bin/pg_config installcheck: 44 of 44 tests passed (# All 44 tests passed.), includingcypher_match.make PG_CONFIG=/usr/bin/pg_config COPT=-Werror src/backend/parser/cypher_clause.ocompiled with no warnings.This was written with help from an AI coding assistant.