Add support for label conjunction (&) in SQL/PGQ

From: ayoub(dot)kazar(at)data-bene(dot)io
To: pgsql-hackers(at)postgresql(dot)org
Subject: Add support for label conjunction (&) in SQL/PGQ
Date: 2026-07-22 09:31:48
Message-ID: 2dfda6847b31d8fee62b7b80441bfa62@data-bene.io
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello everyone,

I'm proposing a patch that adds support for label conjunction in
SQL/PGQ, i'll quote from the commit message since its already a
semi-complete description:

The SQL/PGQ standard allows label expressions to use boolean operators,
such as conjunction of labels: MATCH (a IS label1 & label2). Previously,
only
disjunction (|) was supported in graph element patterns.

Supporting label conjunction, disjunction and in the future ; label
negation, requires an evaluation of a full label expression. Previously
get_path_elements_for_path_factor() considered only flat BoolExpr
evaluation (as it only knew about disjunctions).

As required, this commit adds a recursive label expression evaluator,
get_path_elements_for_path_factor() now fetches all candidate table
elements for the path factor kind once and evaluates each table
element's label OIDs against the label expression tree.

I'm not sure if the current approach of getting all elements and then
iteratively pulling their corresponding labels from catalog ; which
might seem costly (if doing many `table_open`s every time is a lot and
pg_propgraph_element is large enough), we can change it to keep
`pg_propgraph_element_label` open until all element OIDs are treated.

This also allows to support label conjunction for a path factor
appearing with different label expressions in multiple path elements. I
think this is also required for correct support of multi path patterns
later ; example: MATCH (a IS Person)-[]-(), (a IS Gamer) requires path
factor `a` label expressions to conjunct.

We add a new error "ERROR: label expression for variable "a" is not
satisfied in property graph "g1"" when a path factor's label expression
can't be satisfied for any element table possible.

Thoughts ?

Regards,
Ayoub

Attachment Content-Type Size
0001-Add-support-for-label-conjunction-in-SQL-PGQ.patch text/x-diff 21.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Rafia Sabih 2026-07-22 09:47:22 Re: postgres_fdw: Emit message when batch_size is reduced
Previous Message Fujii Masao 2026-07-22 09:15:15 Re: Don't use pq_putmessage in socket comm function