gregfelice commented on issue #2450:
URL: https://github.com/apache/age/issues/2450#issuecomment-4875513568
Thanks for the clear reproducer, @bilalsp — that made this quick to pin down.
**Root cause.** AGE's CREATE/MERGE/SET paths build the insert/update tuple
slot from the full label-table descriptor but only populate the columns AGE
manages (`id`/`properties` for vertices, `id`/`start_id`/`end_id`/`properties`
for edges). Your `GENERATED ALWAYS ... STORED` column is an extra attribute AGE
never initialized, so `heap_form_tuple()` read the uninitialized slot entry and
segfaulted dereferencing garbage. The same happens for a plain added column,
and on SET as well as CREATE.
**Fix** (PR incoming):
- The entity slot is now null-initialized before AGE fills its own columns,
so any column AGE doesn't manage defaults to NULL instead of stale memory.
- Stored generated columns are computed via `ExecComputeStoredGenerated()`
before the tuple is materialized — on insert (CREATE/MERGE) and recomputed on
update (SET) — matching PostgreSQL semantics.
Verified against your exact repro plus a new regression test: your case now
works and the generated column is correctly computed:
```
CREATE (p:Product {category: 'disk', ...}) --> "Product".category = 'disk'
MATCH (p:Product {category:'disk'}) SET p.category='ssd' --> recomputes to
'ssd'
```
**One caveat worth flagging:** on `SET`, AGE rebuilds the row from
`id`/`properties`, so a *generated* column recomputes correctly, but a *plain*
(non-generated) column would be reset to NULL. If you need a value preserved
across updates, use a `GENERATED ... STORED` column derived from `properties`
(as in your example) rather than a plain column — that path is fully supported.
**Workaround until the PR lands:** if you can't wait, computing `category`
at query time via an expression index instead of a stored generated column
avoids the crash:
```sql
CREATE INDEX ON age_bug."Product" ((agtype_access_operator(properties,
'"category"')));
```
I'll link the PR here shortly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]