You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by jg...@apache.org on 2026/07/03 16:10:00 UTC
(age) branch PG19 updated (0892ceda -> 9088e010)
This is an automated email from the ASF dual-hosted git repository.
jrgemignani pushed a change to branch PG19
in repository https://gitbox.apache.org/repos/asf/age.git
from 0892ceda Add automatic header-dependency tracking to the Makefile (#2454)
new e5431fcb Propagate null through unnest and single() three-valued logic (#2406)
new 3ffbbc51 Fix segfault on CREATE/MERGE/SET with generated or extra label columns (#2458)
new 9088e010 Fix installcheck fetch-depth parameter to 100 (#2461)
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.github/workflows/installcheck.yaml | 2 +-
Makefile | 1 +
regress/expected/generated_columns.out | 222 +++++++++++++++++++++++++++++++
regress/expected/list_comprehension.out | 33 +++++
regress/expected/predicate_functions.out | 116 +++++++++++++---
regress/sql/generated_columns.sql | 129 ++++++++++++++++++
regress/sql/list_comprehension.sql | 8 ++
regress/sql/predicate_functions.sql | 75 +++++++++--
src/backend/executor/cypher_create.c | 4 +-
src/backend/executor/cypher_merge.c | 22 ++-
src/backend/executor/cypher_set.c | 23 ++++
src/backend/executor/cypher_utils.c | 47 +++++++
src/backend/parser/cypher_clause.c | 199 ++++++++++++++++-----------
src/backend/parser/cypher_gram.y | 37 ++----
src/backend/utils/adt/agtype.c | 20 ++-
src/include/executor/cypher_utils.h | 1 +
16 files changed, 801 insertions(+), 138 deletions(-)
create mode 100644 regress/expected/generated_columns.out
create mode 100644 regress/sql/generated_columns.sql
(age) 01/03: Propagate null through unnest and single() three-valued logic (#2406)
Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jrgemignani pushed a commit to branch PG19
in repository https://gitbox.apache.org/repos/asf/age.git
commit e5431fcbc63b4f87cf2defd67c2ecae5e7662f1e
Author: Muhammad Taha Naveed <mt...@apache.org>
AuthorDate: Fri Jul 3 16:20:59 2026 +0500
Propagate null through unnest and single() three-valued logic (#2406)
Fix age_unnest to emit SQL NULL for AGTV_NULL elements and rewrite single() to proper three-valued logic, fixing UNWIND [null] count, list-comprehension null filters, and single() semantics per openCypher.
Closes #2383
Closes #2393
---
regress/expected/list_comprehension.out | 33 +++++
regress/expected/predicate_functions.out | 116 +++++++++++++++---
regress/sql/list_comprehension.sql | 8 ++
regress/sql/predicate_functions.sql | 75 ++++++++++--
src/backend/parser/cypher_clause.c | 199 +++++++++++++++++++------------
src/backend/parser/cypher_gram.y | 37 ++----
src/backend/utils/adt/agtype.c | 20 +++-
7 files changed, 355 insertions(+), 133 deletions(-)
diff --git a/regress/expected/list_comprehension.out b/regress/expected/list_comprehension.out
index e47b2d56..63b24647 100644
--- a/regress/expected/list_comprehension.out
+++ b/regress/expected/list_comprehension.out
@@ -809,6 +809,39 @@ SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [1, null, 2] | -x] $$
[-1, null, -2]
(1 row)
+-- Issue 2393 - WHERE filter over null elements should use openCypher's
+-- three-valued logic: IS NULL must keep nulls, IS NOT NULL must drop them.
+SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [null, 1] WHERE x IS NULL] $$) AS (result agtype);
+ result
+--------
+ [null]
+(1 row)
+
+SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [null, 1, null] WHERE x IS NULL] $$) AS (result agtype);
+ result
+--------------
+ [null, null]
+(1 row)
+
+SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [null, 1] WHERE x IS NOT NULL] $$) AS (result agtype);
+ result
+--------
+ [1]
+(1 row)
+
+SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [1, 2, 3] WHERE x IS NULL] $$) AS (result agtype);
+ result
+--------
+ []
+(1 row)
+
+SELECT * FROM cypher('list_comprehension', $$ UNWIND [null, 1] AS x RETURN x, x IS NULL, x IS NOT NULL $$) AS (x agtype, a agtype, b agtype);
+ x | a | b
+---+-------+-------
+ | true | false
+ 1 | false | true
+(2 rows)
+
-- Clean up
SELECT * FROM drop_graph('list_comprehension', true);
NOTICE: drop cascades to 4 other objects
diff --git a/regress/expected/predicate_functions.out b/regress/expected/predicate_functions.out
index 9ee673a4..f6957c49 100644
--- a/regress/expected/predicate_functions.out
+++ b/regress/expected/predicate_functions.out
@@ -194,20 +194,20 @@ $$) AS (result agtype);
--
-- NULL predicate results: three-valued logic
--
--- Note: In AGE's agtype, null is a first-class value. The comparison
--- agtype_null > agtype_integer evaluates to true (not SQL NULL).
--- Three-valued logic only applies when the predicate itself is a
--- literal null constant, which becomes SQL NULL after coercion.
--- agtype null in list: null > 0 = true in AGE, so any() = true
+-- Null list elements arrive at the predicate as SQL NULL, so the usual
+-- strict-operator short-circuit applies: `null > 0` yields NULL, and the
+-- predicate functions combine NULLs with the openCypher three-valued
+-- logic (true trumps null in any(), false trumps null in all(), etc.).
+-- [null]: only null predicate, no true -> any() = NULL
SELECT * FROM cypher('predicate_functions', $$
RETURN any(x IN [null] WHERE x > 0)
$$) AS (result agtype);
result
--------
- true
+
(1 row)
--- agtype null + real values: all comparisons are true
+-- one true (1 > 0) is enough: any() = true
SELECT * FROM cypher('predicate_functions', $$
RETURN any(x IN [null, 1, 2] WHERE x > 0)
$$) AS (result agtype);
@@ -226,16 +226,16 @@ $$) AS (result agtype);
(1 row)
--- agtype null in list: null > 0 = true in AGE, so all() = true
+-- no false, but one null -> all() = NULL
SELECT * FROM cypher('predicate_functions', $$
RETURN all(x IN [1, null, 2] WHERE x > 0)
$$) AS (result agtype);
result
--------
- true
+
(1 row)
--- -1 > 0 = false, so all() = false
+-- -1 > 0 = false dominates the null -> all() = false
SELECT * FROM cypher('predicate_functions', $$
RETURN all(x IN [1, null, -1] WHERE x > 0)
$$) AS (result agtype);
@@ -244,16 +244,16 @@ $$) AS (result agtype);
false
(1 row)
--- agtype null > 0 = true in AGE, so none() = false
+-- [null]: only null predicate, no true -> none() = NULL
SELECT * FROM cypher('predicate_functions', $$
RETURN none(x IN [null] WHERE x > 0)
$$) AS (result agtype);
result
--------
- false
+
(1 row)
--- 5 > 0 = true, so none() = false
+-- one true (5 > 0) dominates: none() = false
SELECT * FROM cypher('predicate_functions', $$
RETURN none(x IN [null, 5] WHERE x > 0)
$$) AS (result agtype);
@@ -262,24 +262,108 @@ $$) AS (result agtype);
false
(1 row)
--- agtype null > 0 = true AND 5 > 0 = true: 2 matches, single = false
+-- one definite true (5 > 0) and one null predicate: the null could also
+-- be a match, so we cannot conclude exactly-one -> single() = NULL
SELECT * FROM cypher('predicate_functions', $$
RETURN single(x IN [null, 5] WHERE x > 0)
$$) AS (result agtype);
result
--------
+
+(1 row)
+
+-- two definite trues dominate any null -> single() = false
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN single(x IN [null, 5, 6] WHERE x > 0)
+$$) AS (result agtype);
+ result
+--------
false
(1 row)
--- single() with null list: NULL (same as other predicate functions)
+-- only null predicates -> single() = NULL
SELECT * FROM cypher('predicate_functions', $$
- RETURN single(x IN null WHERE x > 0)
+ RETURN single(x IN [null, null] WHERE x > 0)
+$$) AS (result agtype);
+ result
+--------
+
+(1 row)
+
+-- one true + one false + one null: the null could be the second true
+-- so we cannot conclude exactly-one -> single() = NULL
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN single(x IN [1, null, -1] WHERE x > 0)
+$$) AS (result agtype);
+ result
+--------
+
+(1 row)
+
+--
+-- Additional null/three-valued coverage for any()/all()/none()
+--
+-- any() with no true and one null -> NULL
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN any(x IN [null, -1] WHERE x > 0)
+$$) AS (result agtype);
+ result
+--------
+
+(1 row)
+
+-- all() with one true and one null -> NULL (the null might be false)
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN all(x IN [1, null] WHERE x > 0)
+$$) AS (result agtype);
+ result
+--------
+
+(1 row)
+
+-- all() with one definite false dominates any null -> false
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN all(x IN [null, -1] WHERE x > 0)
+$$) AS (result agtype);
+ result
+--------
+ false
+(1 row)
+
+-- none() with no true and one null -> NULL
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN none(x IN [null, -1] WHERE x > 0)
$$) AS (result agtype);
result
--------
(1 row)
+-- IS NULL predicate now sees unwound null elements (issue #2393)
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN any(x IN [1, null] WHERE x IS NULL)
+$$) AS (result agtype);
+ result
+--------
+ true
+(1 row)
+
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN none(x IN [1, null] WHERE x IS NULL)
+$$) AS (result agtype);
+ result
+--------
+ false
+(1 row)
+
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN all(x IN [null, null] WHERE x IS NULL)
+$$) AS (result agtype);
+ result
+--------
+ true
+(1 row)
+
--
-- Integration with graph data
--
diff --git a/regress/sql/list_comprehension.sql b/regress/sql/list_comprehension.sql
index 57b43221..e493da6d 100644
--- a/regress/sql/list_comprehension.sql
+++ b/regress/sql/list_comprehension.sql
@@ -194,5 +194,13 @@ SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [1, null, 2] | x % 2]
SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [1, null, 2] | x ^ 2] $$) AS (result agtype);
SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [1, null, 2] | -x] $$) AS (result agtype);
+-- Issue 2393 - WHERE filter over null elements should use openCypher's
+-- three-valued logic: IS NULL must keep nulls, IS NOT NULL must drop them.
+SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [null, 1] WHERE x IS NULL] $$) AS (result agtype);
+SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [null, 1, null] WHERE x IS NULL] $$) AS (result agtype);
+SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [null, 1] WHERE x IS NOT NULL] $$) AS (result agtype);
+SELECT * FROM cypher('list_comprehension', $$ RETURN [x IN [1, 2, 3] WHERE x IS NULL] $$) AS (result agtype);
+SELECT * FROM cypher('list_comprehension', $$ UNWIND [null, 1] AS x RETURN x, x IS NULL, x IS NOT NULL $$) AS (x agtype, a agtype, b agtype);
+
-- Clean up
SELECT * FROM drop_graph('list_comprehension', true);
\ No newline at end of file
diff --git a/regress/sql/predicate_functions.sql b/regress/sql/predicate_functions.sql
index 82933f87..ad99a582 100644
--- a/regress/sql/predicate_functions.sql
+++ b/regress/sql/predicate_functions.sql
@@ -123,17 +123,17 @@ $$) AS (result agtype);
--
-- NULL predicate results: three-valued logic
--
--- Note: In AGE's agtype, null is a first-class value. The comparison
--- agtype_null > agtype_integer evaluates to true (not SQL NULL).
--- Three-valued logic only applies when the predicate itself is a
--- literal null constant, which becomes SQL NULL after coercion.
+-- Null list elements arrive at the predicate as SQL NULL, so the usual
+-- strict-operator short-circuit applies: `null > 0` yields NULL, and the
+-- predicate functions combine NULLs with the openCypher three-valued
+-- logic (true trumps null in any(), false trumps null in all(), etc.).
--- agtype null in list: null > 0 = true in AGE, so any() = true
+-- [null]: only null predicate, no true -> any() = NULL
SELECT * FROM cypher('predicate_functions', $$
RETURN any(x IN [null] WHERE x > 0)
$$) AS (result agtype);
--- agtype null + real values: all comparisons are true
+-- one true (1 > 0) is enough: any() = true
SELECT * FROM cypher('predicate_functions', $$
RETURN any(x IN [null, 1, 2] WHERE x > 0)
$$) AS (result agtype);
@@ -144,34 +144,83 @@ SELECT * FROM cypher('predicate_functions', $$
RETURN all(x IN [1] WHERE null)
$$) AS (result agtype);
--- agtype null in list: null > 0 = true in AGE, so all() = true
+-- no false, but one null -> all() = NULL
SELECT * FROM cypher('predicate_functions', $$
RETURN all(x IN [1, null, 2] WHERE x > 0)
$$) AS (result agtype);
--- -1 > 0 = false, so all() = false
+-- -1 > 0 = false dominates the null -> all() = false
SELECT * FROM cypher('predicate_functions', $$
RETURN all(x IN [1, null, -1] WHERE x > 0)
$$) AS (result agtype);
--- agtype null > 0 = true in AGE, so none() = false
+-- [null]: only null predicate, no true -> none() = NULL
SELECT * FROM cypher('predicate_functions', $$
RETURN none(x IN [null] WHERE x > 0)
$$) AS (result agtype);
--- 5 > 0 = true, so none() = false
+-- one true (5 > 0) dominates: none() = false
SELECT * FROM cypher('predicate_functions', $$
RETURN none(x IN [null, 5] WHERE x > 0)
$$) AS (result agtype);
--- agtype null > 0 = true AND 5 > 0 = true: 2 matches, single = false
+-- one definite true (5 > 0) and one null predicate: the null could also
+-- be a match, so we cannot conclude exactly-one -> single() = NULL
SELECT * FROM cypher('predicate_functions', $$
RETURN single(x IN [null, 5] WHERE x > 0)
$$) AS (result agtype);
--- single() with null list: NULL (same as other predicate functions)
+-- two definite trues dominate any null -> single() = false
SELECT * FROM cypher('predicate_functions', $$
- RETURN single(x IN null WHERE x > 0)
+ RETURN single(x IN [null, 5, 6] WHERE x > 0)
+$$) AS (result agtype);
+
+-- only null predicates -> single() = NULL
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN single(x IN [null, null] WHERE x > 0)
+$$) AS (result agtype);
+
+-- one true + one false + one null: the null could be the second true
+-- so we cannot conclude exactly-one -> single() = NULL
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN single(x IN [1, null, -1] WHERE x > 0)
+$$) AS (result agtype);
+
+--
+-- Additional null/three-valued coverage for any()/all()/none()
+--
+
+-- any() with no true and one null -> NULL
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN any(x IN [null, -1] WHERE x > 0)
+$$) AS (result agtype);
+
+-- all() with one true and one null -> NULL (the null might be false)
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN all(x IN [1, null] WHERE x > 0)
+$$) AS (result agtype);
+
+-- all() with one definite false dominates any null -> false
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN all(x IN [null, -1] WHERE x > 0)
+$$) AS (result agtype);
+
+-- none() with no true and one null -> NULL
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN none(x IN [null, -1] WHERE x > 0)
+$$) AS (result agtype);
+
+-- IS NULL predicate now sees unwound null elements (issue #2393)
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN any(x IN [1, null] WHERE x IS NULL)
+$$) AS (result agtype);
+
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN none(x IN [1, null] WHERE x IS NULL)
+$$) AS (result agtype);
+
+SELECT * FROM cypher('predicate_functions', $$
+ RETURN all(x IN [null, null] WHERE x IS NULL)
$$) AS (result agtype);
--
diff --git a/src/backend/parser/cypher_clause.c b/src/backend/parser/cypher_clause.c
index 72370ba0..147e3e74 100644
--- a/src/backend/parser/cypher_clause.c
+++ b/src/backend/parser/cypher_clause.c
@@ -56,6 +56,10 @@
#include "utils/ag_func.h"
#include "utils/ag_guc.h"
+#ifndef INT8PASSBYVAL
+#define INT8PASSBYVAL FLOAT8PASSBYVAL
+#endif
+
/*
* Variable string names for makeTargetEntry. As they are going to be variable
* names that will be hidden from the user, we need to do our best to make sure
@@ -1764,25 +1768,71 @@ static Node *make_bool_or_agg(ParseState *pstate, Node *arg)
return (Node *) agg;
}
+/*
+ * Helper: build a fully-transformed `count(*) FILTER (WHERE filter)` Aggref.
+ *
+ * The filter must already be a transformed boolean expression.
+ */
+static Node *make_count_star_filter_agg(ParseState *pstate, Node *filter)
+{
+ Aggref *agg;
+ Oid count_oid;
+
+ /* count() -- the zero-argument count-star form */
+ count_oid = LookupFuncName(list_make1(makeString("count")),
+ 0, NULL, false);
+
+ agg = makeNode(Aggref);
+ agg->aggfnoid = count_oid;
+ agg->aggtype = INT8OID;
+ agg->aggcollid = InvalidOid;
+ agg->inputcollid = InvalidOid;
+ agg->aggtranstype = InvalidOid; /* filled by planner */
+ agg->aggargtypes = NIL;
+ agg->aggdirectargs = NIL;
+ agg->args = NIL;
+ agg->aggorder = NIL;
+ agg->aggdistinct = NIL;
+ agg->aggfilter = (Expr *) filter;
+ agg->aggstar = true;
+ agg->aggvariadic = false;
+ agg->aggkind = AGGKIND_NORMAL;
+ agg->aggpresorted = false;
+ agg->agglevelsup = 0;
+ agg->aggsplit = AGGSPLIT_SIMPLE;
+ agg->aggno = -1;
+ agg->aggtransno = -1;
+ agg->location = -1;
+
+ pstate->p_hasAggs = true;
+
+ return (Node *) agg;
+}
+
/*
* Helper: build a transformed CASE expression implementing three-valued
- * predicate logic for all(), any(), and none().
+ * predicate logic for all(), any(), none(), and single().
+ *
+ * any(): CASE WHEN bool_or(pred IS TRUE) THEN true
+ * WHEN bool_or(pred IS NULL) THEN NULL
+ * ELSE false END
*
- * any(): CASE WHEN bool_or(pred IS TRUE) THEN true
- * WHEN bool_or(pred IS NULL) THEN NULL
- * ELSE false END
+ * all(): CASE WHEN bool_or(pred IS FALSE) THEN false
+ * WHEN bool_or(pred IS NULL) THEN NULL
+ * ELSE true END
*
- * all(): CASE WHEN bool_or(pred IS FALSE) THEN false
- * WHEN bool_or(pred IS NULL) THEN NULL
- * ELSE true END
+ * none(): CASE WHEN bool_or(pred IS TRUE) THEN false
+ * WHEN bool_or(pred IS NULL) THEN NULL
+ * ELSE true END
*
- * none(): CASE WHEN bool_or(pred IS TRUE) THEN false
- * WHEN bool_or(pred IS NULL) THEN NULL
- * ELSE true END
+ * single(): CASE WHEN count(*) FILTER (WHERE pred IS TRUE) >= 2 THEN false
+ * WHEN bool_or(pred IS NULL) THEN NULL
+ * WHEN count(*) FILTER (WHERE pred IS TRUE) = 1 THEN true
+ * ELSE false END
*
- * Empty list: both bool_or calls return NULL (no rows), so the CASE
- * falls through to the default: false for any(), true for all()/none().
- * This matches Cypher's vacuous truth semantics.
+ * Empty list: bool_or returns NULL on zero rows and count(*) returns 0, so
+ * the CASE falls through to the default: false for any()/single(), true for
+ * all()/none(). This matches Cypher's vacuous truth semantics.
*/
static Node *make_predicate_case_expr(ParseState *pstate, Node *pred,
cypher_predicate_function_kind kind)
@@ -1840,7 +1890,7 @@ static Node *make_predicate_case_expr(ParseState *pstate, Node *pred,
cexpr->defresult = (Expr *) false_const;
cexpr->location = -1;
}
- else /* CPFK_NONE */
+ else if (kind == CPFK_NONE)
{
/* bool_or(pred IS TRUE) -> false */
bool_or_first = make_bool_or_agg(pstate,
@@ -1857,6 +1907,62 @@ static Node *make_predicate_case_expr(ParseState *pstate, Node *pred,
cexpr->defresult = (Expr *) true_const;
cexpr->location = -1;
}
+ else /* CPFK_SINGLE */
+ {
+ /*
+ * Three WHEN arms, in order:
+ * count(*) FILTER (pred IS TRUE) >= 2 -> false (definitely >1)
+ * bool_or(pred IS NULL) -> NULL (unknown arm)
+ * count(*) FILTER (pred IS TRUE) = 1 -> true (exactly one)
+ * else -> false (zero true)
+ *
+ * The >=2 arm is tested first so that 2-or-more definite trues
+ * win over any null predicates, matching Neo4j semantics.
+ */
+ CaseWhen *when0, *when3;
+ Node *count_ge_2, *count_eq_1;
+ Node *count_true_a, *count_true_b;
+ Node *int_2 = (Node *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64),
+ Int64GetDatum(2), false, INT8PASSBYVAL);
+ Node *int_1 = (Node *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64),
+ Int64GetDatum(1), false, INT8PASSBYVAL);
+
+ /*
+ * Two separate Aggref nodes for count(*) FILTER (pred IS TRUE);
+ * the planner will common-subexpression them back to a single
+ * aggregate evaluation.
+ */
+ count_true_a = make_count_star_filter_agg(pstate,
+ make_boolean_test(pred, IS_TRUE));
+ count_true_b = make_count_star_filter_agg(pstate,
+ make_boolean_test(pred, IS_TRUE));
+
+ count_ge_2 = (Node *) make_op(pstate, list_make1(makeString(">=")),
+ count_true_a, int_2,
+ pstate->p_last_srf, -1);
+ count_eq_1 = (Node *) make_op(pstate, list_make1(makeString("=")),
+ count_true_b, int_1,
+ pstate->p_last_srf, -1);
+
+ /* first arm: count >= 2 -> false */
+ when0 = makeNode(CaseWhen);
+ when0->expr = (Expr *) count_ge_2;
+ when0->result = (Expr *) false_const;
+ when0->location = -1;
+
+ /* third arm: count = 1 -> true */
+ when3 = makeNode(CaseWhen);
+ when3->expr = (Expr *) count_eq_1;
+ when3->result = (Expr *) true_const;
+ when3->location = -1;
+
+ cexpr = makeNode(CaseExpr);
+ cexpr->casetype = BOOLOID;
+ cexpr->arg = NULL;
+ cexpr->args = list_make3(when0, when2, when3);
+ cexpr->defresult = (Expr *) false_const;
+ cexpr->location = -1;
+ }
return (Node *) cexpr;
}
@@ -1933,67 +2039,12 @@ static Query *transform_cypher_predicate_function(cypher_parsestate *cpstate,
pred = coerce_to_boolean(child_pstate, pred, "WHERE");
}
- if (pred_func->kind == CPFK_SINGLE)
- {
- /*
- * single(): SELECT count(*) FROM unnest(list) AS x
- * WHERE pred IS TRUE
- *
- * Using IS TRUE ensures NULL predicates are not counted as
- * matches, preserving correct semantics. The grammar layer
- * compares the result = 1.
- *
- * Note: a LIMIT 2 optimization (to short-circuit after two
- * matches) would require a nested subquery that breaks
- * correlated variable references. Deferred to a future
- * optimization pass.
- */
- FuncCall *count_call;
- Node *count_expr;
- Node *is_true_qual;
-
- /* WHERE pred IS TRUE -- NULLs are not counted */
- is_true_qual = make_boolean_test(pred, IS_TRUE);
-
- count_call = makeFuncCall(list_make1(makeString("count")),
- NIL, COERCE_SQL_SYNTAX, -1);
- count_call->agg_star = true;
-
- count_expr = transformExpr(child_pstate, (Node *) count_call,
- EXPR_KIND_SELECT_TARGET);
-
- te = makeTargetEntry((Expr *) count_expr,
- (AttrNumber) child_pstate->p_next_resno++,
- "count", false);
-
- query->targetList = lappend(query->targetList, te);
- query->jointree = makeFromExpr(child_pstate->p_joinlist,
- is_true_qual);
- query->rtable = child_pstate->p_rtable;
- query->rteperminfos = child_pstate->p_rteperminfos;
- query->hasAggs = child_pstate->p_hasAggs;
- query->hasSubLinks = child_pstate->p_hasSubLinks;
- query->hasTargetSRFs = child_pstate->p_hasTargetSRFs;
-
- assign_query_collations(child_pstate, query);
-
- if (child_pstate->p_hasAggs ||
- query->groupClause || query->groupingSets || query->havingQual)
- {
- parse_check_aggregates(child_pstate, query);
- }
-
- free_cypher_parsestate(child_cpstate);
-
- return query;
- }
- else
+ /*
+ * Build a CASE expression that preserves three-valued NULL semantics.
+ * No WHERE clause -- the logic is entirely in the SELECT list, so the
+ * CASE can see null predicates and react to them.
+ */
{
- /*
- * all()/any()/none(): Build a CASE expression with bool_or()
- * aggregates that preserves three-valued NULL semantics.
- * No WHERE clause -- the logic is entirely in the SELECT list.
- */
Node *case_expr;
case_expr = make_predicate_case_expr(child_pstate, pred,
diff --git a/src/backend/parser/cypher_gram.y b/src/backend/parser/cypher_gram.y
index ddd62d7e..71b95bde 100644
--- a/src/backend/parser/cypher_gram.y
+++ b/src/backend/parser/cypher_gram.y
@@ -3538,12 +3538,10 @@ static Node *build_list_comprehension_node(Node *var, Node *expr,
* none(x IN list WHERE predicate)
* single(x IN list WHERE predicate)
*
- * All four use EXPR_SUBLINK (scalar subquery). The transform layer
- * generates aggregate-based queries (using bool_or + CASE) for
- * all/any/none to preserve three-valued NULL semantics, and
- * count(*) with IS TRUE filtering for single().
- *
- * For single(), the subquery result is compared = 1.
+ * All four use EXPR_SUBLINK (scalar subquery). The transform layer
+ * generates aggregate-based queries that preserve three-valued NULL
+ * semantics: bool_or + CASE for all/any/none, and a CASE built on
+ * count(*) FILTER for single().
*/
static Node *build_predicate_function_node(cypher_predicate_function_kind kind,
Node *var, Node *expr,
@@ -3583,28 +3581,11 @@ static Node *build_predicate_function_node(cypher_predicate_function_kind kind,
sub->location = location;
sub->subLinkType = EXPR_SUBLINK;
- if (kind == CPFK_SINGLE)
- {
- /*
- * single() -> (subquery) = 1
- * The subquery returns count(*) with IS TRUE filtering.
- */
- Node *eq_expr;
-
- eq_expr = (Node *) makeSimpleA_Expr(AEXPR_OP, "=",
- (Node *) sub,
- make_int_const(1, location),
- location);
- result = (Node *) node_to_agtype(eq_expr, "boolean", location);
- }
- else
- {
- /*
- * all()/any()/none(): the subquery returns a boolean directly
- * from the CASE+bool_or() aggregate expression.
- */
- result = (Node *) node_to_agtype((Node *) sub, "boolean", location);
- }
+ /*
+ * The subquery returns a boolean directly from the CASE+bool_or()
+ * aggregate expression (count(*) FILTER for single()).
+ */
+ result = (Node *) node_to_agtype((Node *) sub, "boolean", location);
/*
* NULL-list guard: CASE WHEN expr IS NULL THEN NULL ELSE result END
diff --git a/src/backend/utils/adt/agtype.c b/src/backend/utils/adt/agtype.c
index 10d95ee4..cc9cc771 100644
--- a/src/backend/utils/adt/agtype.c
+++ b/src/backend/utils/adt/agtype.c
@@ -13103,12 +13103,28 @@ Datum age_unnest(PG_FUNCTION_ARGS)
HeapTuple tuple;
Datum values[1];
bool nulls[1] = {false};
- agtype *val = agtype_value_to_agtype(&v);
/* use the tmp context so we can clean up after each tuple is done */
old_cxt = MemoryContextSwitchTo(tmp_cxt);
- values[0] = PointerGetDatum(val);
+ /*
+ * Emit an agtype AGTV_NULL element as a SQL-NULL row so that
+ * `IS NULL` / `IS NOT NULL` on the unwound variable match
+ * openCypher's null semantics (issue #2393). Wrapping it as a
+ * non-SQL-NULL agtype container would leave SQL's IS NULL blind
+ * to it, dropping `WHERE x IS NULL` filters and passing through
+ * `WHERE x IS NOT NULL` filters.
+ */
+ if (v.type == AGTV_NULL)
+ {
+ values[0] = (Datum) 0;
+ nulls[0] = true;
+ }
+ else
+ {
+ agtype *val = agtype_value_to_agtype(&v);
+ values[0] = PointerGetDatum(val);
+ }
tuple = heap_form_tuple(ret_tdesc, values, nulls);
(age) 03/03: Fix installcheck fetch-depth parameter to 100 (#2461)
Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jrgemignani pushed a commit to branch PG19
in repository https://gitbox.apache.org/repos/asf/age.git
commit 9088e0108e9aa5482297e575c95e79059ff89e26
Author: John Gemignani <jr...@gmail.com>
AuthorDate: Fri Jul 3 08:23:05 2026 -0700
Fix installcheck fetch-depth parameter to 100 (#2461)
Fix the installcheck.yaml fetch-depth parameter to 100. This release,
being rather large, exceeded the original value of 75 (commits) and
caused the upgrade test to fail. The new value will resolve this and
make it unlikely to become a problem in the future.
NOTE: We need to keep releases under this number of commits.
modified: .github/workflows/installcheck.yaml
---
.github/workflows/installcheck.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/installcheck.yaml b/.github/workflows/installcheck.yaml
index 61687cd1..92cec983 100644
--- a/.github/workflows/installcheck.yaml
+++ b/.github/workflows/installcheck.yaml
@@ -69,7 +69,7 @@ jobs:
- uses: actions/checkout@v3
with:
- fetch-depth: 75
+ fetch-depth: 100
- name: Build AGE
id: build
(age) 02/03: Fix segfault on CREATE/MERGE/SET with generated or extra label columns (#2458)
Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jrgemignani pushed a commit to branch PG19
in repository https://gitbox.apache.org/repos/asf/age.git
commit 3ffbbc51c80bbf80921dbf16f8b9e0579836bf3c
Author: Greg Felice <gr...@gmail.com>
AuthorDate: Fri Jul 3 08:27:23 2026 -0400
Fix segfault on CREATE/MERGE/SET with generated or extra label columns (#2458)
AGE builds the insert/update tuple slot from the full label-table
descriptor (table_slot_create), but only populates the columns it
manages: id/properties for vertices and id/start_id/end_id/properties
for edges. A user-added column on the label table -- most notably a
GENERATED ALWAYS ... STORED column, but also any plain ADD COLUMN --
therefore left an uninitialized slot entry. ExecStoreVirtualTuple marks
all attributes valid, so heap_form_tuple() -> heap_compute_data_size()
read the uninitialized tts_isnull[]/tts_values[] for that column and
segfaulted dereferencing garbage as a varlena. This crashed the backend
on CREATE, MERGE and SET.
Fix in two parts:
- clear_entity_slot() clears the slot and marks every attribute NULL
before AGE fills in its own columns, so columns AGE does not manage
default to NULL instead of stale slot memory. It is used at every slot
build site: create_vertex, create_edge, merge_vertex, merge_edge, and
the populate_vertex_tts/populate_edge_tts helpers used by SET.
- insert_entity_tuple_cid (CREATE/MERGE) and update_entity_tuple (SET)
call ExecComputeStoredGenerated() before materializing the heap tuple
when the relation has stored generated columns, so those columns are
computed on insert and recomputed on update per PostgreSQL semantics.
Adds a generated_columns regression test covering stored generated
columns on vertex and edge labels across CREATE, MERGE and SET, plus a
plain user column that must not crash.
---
Makefile | 1 +
regress/expected/generated_columns.out | 222 +++++++++++++++++++++++++++++++++
regress/sql/generated_columns.sql | 129 +++++++++++++++++++
src/backend/executor/cypher_create.c | 4 +-
src/backend/executor/cypher_merge.c | 22 +++-
src/backend/executor/cypher_set.c | 23 ++++
src/backend/executor/cypher_utils.c | 47 +++++++
src/include/executor/cypher_utils.h | 1 +
8 files changed, 445 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index 32f34d6e..2ea8f64e 100644
--- a/Makefile
+++ b/Makefile
@@ -223,6 +223,7 @@ REGRESS = scan \
age_reduce \
map_projection \
direct_field_access \
+ generated_columns \
security \
reserved_keyword_alias \
agtype_jsonb_cast \
diff --git a/regress/expected/generated_columns.out b/regress/expected/generated_columns.out
new file mode 100644
index 00000000..4e929110
--- /dev/null
+++ b/regress/expected/generated_columns.out
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Regression test for issue #2450.
+ *
+ * A GENERATED ALWAYS ... STORED column (or any user-added column) on a label
+ * table adds an attribute AGE's CREATE/MERGE/SET paths do not populate. The
+ * slot's tuple descriptor is the full relation descriptor, so heap_form_tuple()
+ * used to read the uninitialized slot entry and segfault. AGE now null-inits the
+ * entity slot and computes stored generated columns before materializing the
+ * tuple. Generated columns must be computed on insert and recomputed on update;
+ * plain user columns must default to NULL rather than crash.
+ */
+LOAD 'age';
+SET search_path TO ag_catalog;
+SELECT create_graph('generated_columns');
+NOTICE: graph "generated_columns" has been created
+ create_graph
+--------------
+
+(1 row)
+
+--
+-- GENERATED ALWAYS ... STORED column on a vertex label
+--
+SELECT create_vlabel('generated_columns', 'Product');
+NOTICE: VLabel "Product" has been created
+ create_vlabel
+---------------
+
+(1 row)
+
+ALTER TABLE generated_columns."Product"
+ ADD COLUMN category varchar(25)
+ GENERATED ALWAYS AS (agtype_access_operator(properties, '"category"')) STORED;
+-- CREATE: the generated column is computed from the new properties
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (p:Product {category: 'disk', type: 'M1234'}) RETURN p
+$$) AS (p agtype);
+ p
+----------------------------------------------------------------------------------------------------------
+ {"id": 844424930131969, "label": "Product", "properties": {"type": "M1234", "category": "disk"}}::vertex
+(1 row)
+
+-- CREATE where the generation expression yields NULL (no such key)
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (p:Product {type: 'no-cat'}) RETURN p
+$$) AS (p agtype);
+ p
+---------------------------------------------------------------------------------------
+ {"id": 844424930131970, "label": "Product", "properties": {"type": "no-cat"}}::vertex
+(1 row)
+
+-- MERGE also computes the generated column
+SELECT * FROM cypher('generated_columns', $$
+ MERGE (p:Product {category: 'merged'}) RETURN p
+$$) AS (p agtype);
+ p
+-------------------------------------------------------------------------------------------
+ {"id": 844424930131971, "label": "Product", "properties": {"category": "merged"}}::vertex
+(1 row)
+
+-- MERGE again on the same pattern must MATCH (not re-insert); this exercises the
+-- matched path where the slot is intentionally left uncleared (issue #2450)
+SELECT * FROM cypher('generated_columns', $$
+ MERGE (p:Product {category: 'merged'}) RETURN p
+$$) AS (p agtype);
+ p
+-------------------------------------------------------------------------------------------
+ {"id": 844424930131971, "label": "Product", "properties": {"category": "merged"}}::vertex
+(1 row)
+
+-- SET recomputes the generated column from the updated properties
+SELECT * FROM cypher('generated_columns', $$
+ MATCH (p:Product {category: 'disk'}) SET p.category = 'ssd', p.note = 'x' RETURN p
+$$) AS (p agtype);
+ p
+----------------------------------------------------------------------------------------------------------------------
+ {"id": 844424930131969, "label": "Product", "properties": {"note": "x", "type": "M1234", "category": "ssd"}}::vertex
+(1 row)
+
+-- The stored generated column always mirrors properties.category
+SELECT category, properties FROM generated_columns."Product" ORDER BY category NULLS LAST;
+ category | properties
+----------+---------------------------------------------------
+ "merged" | {"category": "merged"}
+ "ssd" | {"note": "x", "type": "M1234", "category": "ssd"}
+ | {"type": "no-cat"}
+(3 rows)
+
+--
+-- GENERATED ALWAYS ... STORED column on an edge label
+--
+SELECT create_elabel('generated_columns', 'REL');
+NOTICE: ELabel "REL" has been created
+ create_elabel
+---------------
+
+(1 row)
+
+ALTER TABLE generated_columns."REL"
+ ADD COLUMN kind varchar(25)
+ GENERATED ALWAYS AS (agtype_access_operator(properties, '"kind"')) STORED;
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (:Product {category: 'a'})-[r:REL {kind: 'link'}]->(:Product {category: 'b'})
+ RETURN r
+$$) AS (r agtype);
+ r
+----------------------------------------------------------------------------------------------------------------------------------------
+ {"id": 1125899906842625, "label": "REL", "end_id": 844424930131973, "start_id": 844424930131972, "properties": {"kind": "link"}}::edge
+(1 row)
+
+SELECT kind FROM generated_columns."REL";
+ kind
+--------
+ "link"
+(1 row)
+
+--
+-- Plain (non-generated) user column: must not crash; defaults to NULL
+--
+SELECT create_vlabel('generated_columns', 'Plain');
+NOTICE: VLabel "Plain" has been created
+ create_vlabel
+---------------
+
+(1 row)
+
+ALTER TABLE generated_columns."Plain" ADD COLUMN tag text;
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (p:Plain {n: 1}) RETURN p
+$$) AS (p agtype);
+ p
+----------------------------------------------------------------------------
+ {"id": 1407374883553281, "label": "Plain", "properties": {"n": 1}}::vertex
+(1 row)
+
+SELECT * FROM cypher('generated_columns', $$
+ MATCH (p:Plain) SET p.n = 2 RETURN p
+$$) AS (p agtype);
+ p
+----------------------------------------------------------------------------
+ {"id": 1407374883553281, "label": "Plain", "properties": {"n": 2}}::vertex
+(1 row)
+
+SELECT properties, tag FROM generated_columns."Plain";
+ properties | tag
+------------+-----
+ {"n": 2} |
+(1 row)
+
+--
+-- Generated column referencing the tableoid system column: the entity slot must
+-- carry tts_tableOid before the generated columns are computed, otherwise the
+-- expression sees InvalidOid instead of the label table's OID (issue #2450).
+--
+SELECT create_vlabel('generated_columns', 'T');
+NOTICE: VLabel "T" has been created
+ create_vlabel
+---------------
+
+(1 row)
+
+ALTER TABLE generated_columns."T"
+ ADD COLUMN tbl oid GENERATED ALWAYS AS (tableoid) STORED;
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (n:T {k: 1}) RETURN n
+$$) AS (n agtype);
+ n
+------------------------------------------------------------------------
+ {"id": 1688849860263937, "label": "T", "properties": {"k": 1}}::vertex
+(1 row)
+
+SELECT * FROM cypher('generated_columns', $$
+ MATCH (n:T) SET n.k = 2 RETURN n
+$$) AS (n agtype);
+ n
+------------------------------------------------------------------------
+ {"id": 1688849860263937, "label": "T", "properties": {"k": 2}}::vertex
+(1 row)
+
+-- tbl must equal the real label-table OID on both the CREATE and SET paths
+SELECT tbl = 'generated_columns."T"'::regclass::oid AS tableoid_ok
+FROM generated_columns."T";
+ tableoid_ok
+-------------
+ t
+(1 row)
+
+--
+-- Cleanup
+--
+SELECT drop_graph('generated_columns', true);
+NOTICE: drop cascades to 6 other objects
+DETAIL: drop cascades to table generated_columns._ag_label_vertex
+drop cascades to table generated_columns._ag_label_edge
+drop cascades to table generated_columns."Product"
+drop cascades to table generated_columns."REL"
+drop cascades to table generated_columns."Plain"
+drop cascades to table generated_columns."T"
+NOTICE: graph "generated_columns" has been dropped
+ drop_graph
+------------
+
+(1 row)
+
diff --git a/regress/sql/generated_columns.sql b/regress/sql/generated_columns.sql
new file mode 100644
index 00000000..5229c28f
--- /dev/null
+++ b/regress/sql/generated_columns.sql
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Regression test for issue #2450.
+ *
+ * A GENERATED ALWAYS ... STORED column (or any user-added column) on a label
+ * table adds an attribute AGE's CREATE/MERGE/SET paths do not populate. The
+ * slot's tuple descriptor is the full relation descriptor, so heap_form_tuple()
+ * used to read the uninitialized slot entry and segfault. AGE now null-inits the
+ * entity slot and computes stored generated columns before materializing the
+ * tuple. Generated columns must be computed on insert and recomputed on update;
+ * plain user columns must default to NULL rather than crash.
+ */
+
+LOAD 'age';
+SET search_path TO ag_catalog;
+
+SELECT create_graph('generated_columns');
+
+--
+-- GENERATED ALWAYS ... STORED column on a vertex label
+--
+SELECT create_vlabel('generated_columns', 'Product');
+ALTER TABLE generated_columns."Product"
+ ADD COLUMN category varchar(25)
+ GENERATED ALWAYS AS (agtype_access_operator(properties, '"category"')) STORED;
+
+-- CREATE: the generated column is computed from the new properties
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (p:Product {category: 'disk', type: 'M1234'}) RETURN p
+$$) AS (p agtype);
+
+-- CREATE where the generation expression yields NULL (no such key)
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (p:Product {type: 'no-cat'}) RETURN p
+$$) AS (p agtype);
+
+-- MERGE also computes the generated column
+SELECT * FROM cypher('generated_columns', $$
+ MERGE (p:Product {category: 'merged'}) RETURN p
+$$) AS (p agtype);
+
+-- MERGE again on the same pattern must MATCH (not re-insert); this exercises the
+-- matched path where the slot is intentionally left uncleared (issue #2450)
+SELECT * FROM cypher('generated_columns', $$
+ MERGE (p:Product {category: 'merged'}) RETURN p
+$$) AS (p agtype);
+
+-- SET recomputes the generated column from the updated properties
+SELECT * FROM cypher('generated_columns', $$
+ MATCH (p:Product {category: 'disk'}) SET p.category = 'ssd', p.note = 'x' RETURN p
+$$) AS (p agtype);
+
+-- The stored generated column always mirrors properties.category
+SELECT category, properties FROM generated_columns."Product" ORDER BY category NULLS LAST;
+
+--
+-- GENERATED ALWAYS ... STORED column on an edge label
+--
+SELECT create_elabel('generated_columns', 'REL');
+ALTER TABLE generated_columns."REL"
+ ADD COLUMN kind varchar(25)
+ GENERATED ALWAYS AS (agtype_access_operator(properties, '"kind"')) STORED;
+
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (:Product {category: 'a'})-[r:REL {kind: 'link'}]->(:Product {category: 'b'})
+ RETURN r
+$$) AS (r agtype);
+
+SELECT kind FROM generated_columns."REL";
+
+--
+-- Plain (non-generated) user column: must not crash; defaults to NULL
+--
+SELECT create_vlabel('generated_columns', 'Plain');
+ALTER TABLE generated_columns."Plain" ADD COLUMN tag text;
+
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (p:Plain {n: 1}) RETURN p
+$$) AS (p agtype);
+
+SELECT * FROM cypher('generated_columns', $$
+ MATCH (p:Plain) SET p.n = 2 RETURN p
+$$) AS (p agtype);
+
+SELECT properties, tag FROM generated_columns."Plain";
+
+--
+-- Generated column referencing the tableoid system column: the entity slot must
+-- carry tts_tableOid before the generated columns are computed, otherwise the
+-- expression sees InvalidOid instead of the label table's OID (issue #2450).
+--
+SELECT create_vlabel('generated_columns', 'T');
+ALTER TABLE generated_columns."T"
+ ADD COLUMN tbl oid GENERATED ALWAYS AS (tableoid) STORED;
+
+SELECT * FROM cypher('generated_columns', $$
+ CREATE (n:T {k: 1}) RETURN n
+$$) AS (n agtype);
+
+SELECT * FROM cypher('generated_columns', $$
+ MATCH (n:T) SET n.k = 2 RETURN n
+$$) AS (n agtype);
+
+-- tbl must equal the real label-table OID on both the CREATE and SET paths
+SELECT tbl = 'generated_columns."T"'::regclass::oid AS tableoid_ok
+FROM generated_columns."T";
+
+--
+-- Cleanup
+--
+SELECT drop_graph('generated_columns', true);
diff --git a/src/backend/executor/cypher_create.c b/src/backend/executor/cypher_create.c
index 40f446bf..36ef61b3 100644
--- a/src/backend/executor/cypher_create.c
+++ b/src/backend/executor/cypher_create.c
@@ -396,7 +396,7 @@ static void create_edge(cypher_create_custom_scan_state *css,
estate->es_result_relations = &resultRelInfo;
- ExecClearTuple(elemTupleSlot);
+ clear_entity_slot(elemTupleSlot);
/* Graph Id for the edge */
id = ExecEvalExpr(node->id_expr_state, econtext, &isNull);
@@ -491,7 +491,7 @@ static Datum create_vertex(cypher_create_custom_scan_state *css,
estate->es_result_relations = &resultRelInfo;
- ExecClearTuple(elemTupleSlot);
+ clear_entity_slot(elemTupleSlot);
/* get the next graphid for this vertex. */
id = ExecEvalExpr(node->id_expr_state, econtext, &isNull);
diff --git a/src/backend/executor/cypher_merge.c b/src/backend/executor/cypher_merge.c
index 6f2e9376..9c52073c 100644
--- a/src/backend/executor/cypher_merge.c
+++ b/src/backend/executor/cypher_merge.c
@@ -1199,7 +1199,16 @@ static Datum merge_vertex(cypher_merge_custom_scan_state *css,
estate->es_result_relations = &resultRelInfo;
- ExecClearTuple(elemTupleSlot);
+ /*
+ * Only clear and null-init the slot when we will actually insert. On a
+ * matched MERGE the slot is never materialized (the output is built from
+ * id/prop directly), so the null-init memset would be wasted work that
+ * scales with any user-added columns (issue #2450 review follow-up).
+ */
+ if (should_insert)
+ {
+ clear_entity_slot(elemTupleSlot);
+ }
/* if we not are going to insert, we need our structure pointers */
if (should_insert == false &&
@@ -1526,7 +1535,16 @@ static void merge_edge(cypher_merge_custom_scan_state *css,
estate->es_result_relations = &resultRelInfo;
- ExecClearTuple(elemTupleSlot);
+ /*
+ * Only clear and null-init the slot when we will actually insert. On a
+ * matched MERGE the slot is never materialized (the output is built from
+ * id/prop directly), so the null-init memset would be wasted work that
+ * scales with any user-added columns (issue #2450 review follow-up).
+ */
+ if (should_insert)
+ {
+ clear_entity_slot(elemTupleSlot);
+ }
/* if we not are going to insert, we need our structure pointers */
if (should_insert == false &&
diff --git a/src/backend/executor/cypher_set.c b/src/backend/executor/cypher_set.c
index fe3633f8..7a0d48f0 100644
--- a/src/backend/executor/cypher_set.c
+++ b/src/backend/executor/cypher_set.c
@@ -21,6 +21,7 @@
#include "common/hashfn.h"
#include "executor/executor.h"
+#include "executor/nodeModifyTable.h"
#include "storage/bufmgr.h"
#include "utils/rls.h"
@@ -131,6 +132,28 @@ static HeapTuple update_entity_tuple(ResultRelInfo *resultRelInfo,
close_indices = true;
}
ExecStoreVirtualTuple(elemTupleSlot);
+
+ /*
+ * Recompute any stored generated columns before materializing the heap
+ * tuple. The slot's tuple descriptor is the full relation descriptor,
+ * which may include a GENERATED ALWAYS ... STORED column that the SET
+ * path does not populate; leaving those slot entries uninitialized makes
+ * heap_form_tuple() segfault on the garbage values (issue #2450).
+ */
+ if (resultRelInfo->ri_RelationDesc->rd_att->constr != NULL &&
+ resultRelInfo->ri_RelationDesc->rd_att->constr->has_generated_stored)
+ {
+ /*
+ * A generation expression may reference the tableoid system column,
+ * so the slot must carry the relation's OID before we recompute the
+ * stored generated columns (mirrors PostgreSQL's own ExecUpdate path).
+ */
+ elemTupleSlot->tts_tableOid =
+ RelationGetRelid(resultRelInfo->ri_RelationDesc);
+ ExecComputeStoredGenerated(resultRelInfo, estate, elemTupleSlot,
+ CMD_UPDATE);
+ }
+
tuple = ExecFetchSlotHeapTuple(elemTupleSlot, true, NULL);
tuple->t_self = old_tuple->t_self;
diff --git a/src/backend/executor/cypher_utils.c b/src/backend/executor/cypher_utils.c
index 8237cdcc..c697a560 100644
--- a/src/backend/executor/cypher_utils.c
+++ b/src/backend/executor/cypher_utils.c
@@ -25,6 +25,7 @@
#include "postgres.h"
#include "executor/executor.h"
+#include "executor/nodeModifyTable.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "parser/parse_relation.h"
@@ -128,6 +129,24 @@ void destroy_entity_result_rel_info(ResultRelInfo *result_rel_info)
table_close(result_rel_info->ri_RelationDesc, RowExclusiveLock);
}
+/*
+ * Clear an entity slot and mark every attribute NULL before AGE fills in the
+ * columns it manages (id/start_id/end_id/properties).
+ *
+ * The slot's tuple descriptor is the full label-table descriptor, which may
+ * contain columns AGE does not populate -- e.g. a user-added plain column, or a
+ * GENERATED ALWAYS ... STORED column. Without this, those attributes keep stale
+ * slot memory and heap_form_tuple() segfaults dereferencing the garbage
+ * (issue #2450). Plain columns then default to NULL; generated columns are
+ * recomputed via ExecComputeStoredGenerated() before the tuple is materialized.
+ */
+void clear_entity_slot(TupleTableSlot *elemTupleSlot)
+{
+ ExecClearTuple(elemTupleSlot);
+ memset(elemTupleSlot->tts_isnull, true,
+ elemTupleSlot->tts_tupleDescriptor->natts * sizeof(bool));
+}
+
TupleTableSlot *populate_vertex_tts(
TupleTableSlot *elemTupleSlot, agtype_value *id, agtype_value *properties)
{
@@ -139,6 +158,8 @@ TupleTableSlot *populate_vertex_tts(
errmsg("vertex id field cannot be NULL")));
}
+ clear_entity_slot(elemTupleSlot);
+
properties_isnull = properties == NULL;
elemTupleSlot->tts_values[vertex_tuple_id] = GRAPHID_GET_DATUM(id->val.int_value);
@@ -174,6 +195,8 @@ TupleTableSlot *populate_edge_tts(
errmsg("edge end_id field cannot be NULL")));
}
+ clear_entity_slot(elemTupleSlot);
+
properties_isnull = properties == NULL;
elemTupleSlot->tts_values[edge_tuple_id] =
@@ -318,6 +341,30 @@ HeapTuple insert_entity_tuple_cid(ResultRelInfo *resultRelInfo,
HeapTuple tuple = NULL;
ExecStoreVirtualTuple(elemTupleSlot);
+
+ /*
+ * The slot's tuple descriptor is the full relation descriptor, which may
+ * contain columns AGE does not populate itself -- most notably a
+ * GENERATED ALWAYS ... STORED column added to the label table. Those slot
+ * entries are left uninitialized by the create/merge/set paths, so we must
+ * compute the stored generated columns here before materializing the heap
+ * tuple. Otherwise heap_form_tuple() reads the uninitialized slot values
+ * and segfaults dereferencing garbage (issue #2450).
+ */
+ if (resultRelInfo->ri_RelationDesc->rd_att->constr != NULL &&
+ resultRelInfo->ri_RelationDesc->rd_att->constr->has_generated_stored)
+ {
+ /*
+ * A generation expression may reference the tableoid system column, so
+ * the slot must carry the relation's OID before we compute the stored
+ * generated columns (mirrors PostgreSQL's own ExecInsert path).
+ */
+ elemTupleSlot->tts_tableOid =
+ RelationGetRelid(resultRelInfo->ri_RelationDesc);
+ ExecComputeStoredGenerated(resultRelInfo, estate, elemTupleSlot,
+ CMD_INSERT);
+ }
+
tuple = ExecFetchSlotHeapTuple(elemTupleSlot, true, NULL);
/* Check the constraints of the tuple */
diff --git a/src/include/executor/cypher_utils.h b/src/include/executor/cypher_utils.h
index ac4b5ea5..8b65bc96 100644
--- a/src/include/executor/cypher_utils.h
+++ b/src/include/executor/cypher_utils.h
@@ -119,6 +119,7 @@ typedef struct cypher_merge_custom_scan_state
void apply_update_list(CustomScanState *node,
cypher_update_information *set_info);
+void clear_entity_slot(TupleTableSlot *elemTupleSlot);
TupleTableSlot *populate_vertex_tts(TupleTableSlot *elemTupleSlot,
agtype_value *id, agtype_value *properties);
TupleTableSlot *populate_edge_tts(