Add support for label conjunction (&) in SQL/PGQ - Mailing list pgsql-hackers

From ayoub.kazar@data-bene.io
Subject Add support for label conjunction (&) in SQL/PGQ
Date
Msg-id 2dfda6847b31d8fee62b7b80441bfa62@data-bene.io
Whole thread
List 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

pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: Don't use pq_putmessage in socket comm function
Next
From: Rafia Sabih
Date:
Subject: Re: postgres_fdw: Emit message when batch_size is reduced