YMatrix
Quick Start
Connecting
Benchmarks
Deployment
Data Usage
Manage Clusters
Upgrade
Global Maintenance
Expansion
Monitoring
Security
Best Practice
Technical Principles
Data Type
Storage Engine
Execution Engine
Streaming Engine(Domino)
MARS3 Index
Extension
Advanced Features
Advanced Query
Federal Query
Grafana
Backup and Restore
Disaster Recovery
Graph Database
Introduction
Clauses
Functions
Advanced
Guide
Performance Tuning
Troubleshooting
Tools
Configuration Parameters
SQL Reference
Predicates are Boolean functions that return true or false for a given set of inputs. They are most commonly used in the WHERE clause of queries to filter subgraphs.
exists(property)exists(property) returns true if the specified property exists on a vertex, edge, or map. This function is distinct from the EXISTS subquery clause.
Syntax: exists(property)
Returns:
An agtype Boolean value.
Parameters:
| Name | Description |
|---|---|
property |
A property from a vertex or edge. |
Query:
SELECT *
FROM cypher('graph_name', $$MATCH (n)
WHERE exists(n.surname)
RETURN n.first_name, n.last_name
$$) as (first_name agtype, last_name agtype);
Result:
| first_name | last_name |
|---|---|
| 'John' | 'Smith' |
| 'Patty' | 'Patterson' |
EXISTS(path)EXISTS(path) returns true if the specified path pattern matches at least one path in the graph.
Note!
Known limitation ofEXISTSsubqueries
In YMatrix AGE, anEXISTSsubquery that references variables from an outer scope may fail with the error:
ERROR: could not devise a query plan for the given query.
Trigger condition:
This occurs whenEXISTSappears in theWHEREclause of anOPTIONAL MATCH, and theEXISTSpattern references a variable defined before thatOPTIONAL MATCH.Examples:
Fails:MATCH (a:A) WITH a OPTIONAL MATCH (a)-[:incs]->(c) WHERE EXISTS((c)<-[:incs]-(a)) RETURN a, c;
Succeeds:MATCH (a:A) WITH a OPTIONAL MATCH (a)-[:incs]->(c) WHERE EXISTS((c)<-[:incs]-()) RETURN a, c.Cause:
AGE translatesOPTIONAL MATCHinto a SQLLATERAL LEFT JOIN, andEXISTSinto a SQLEXISTS SubLink. When theEXISTSsublink references an outer-scope variable, it creates a deeply nested structure: aLATERALsubquery containing anEXISTSsublink that references variables two levels up. YMatrix’s distributed query planner cannot generate a valid execution plan for such multi-level outer-variable references — a limitation of the underlying distributed planner.Recommended workarounds:
- Merge the
EXISTSpattern directly into theOPTIONAL MATCHpattern:
MATCH (a:A) WITH a OPTIONAL MATCH (a)-[:incs]->(c)<-[:incs]-(a) RETURN a, c;- Split the query into multiple steps to avoid referencing outer variables inside
EXISTSwithinOPTIONAL MATCH:
MATCH (a:A) WITH a OPTIONAL MATCH (a)-[:incs]->(c) WITH a, c WHERE c IS NULL OR EXISTS((c)<-[:incs]-()) RETURN a, c.
Note!
Scope of impact: This limitation applies only when all of the following conditions hold simultaneously:
- An
OPTIONAL MATCHis used (which generates aLATERAL LEFT JOIN);EXISTSis used in itsWHEREclause;- The
EXISTSpattern references a variable from the outer scope of thatOPTIONAL MATCH.
EXISTSin regularMATCH, property existence checks (EXISTS(n.prop)), andEXISTSpatterns that do not reference outer variables are unaffected.
Query:
SELECT *
FROM cypher('graph_name', $$
MATCH (n)
WHERE exists((n)-[]-({name: 'Willem Defoe'}))
RETURN n.full_name
$$) as (full_name agtype);
Result:
| full_name |
|---|
| 'Toby Maguire' |
| 'Tom Holland' |