SlideShare a Scribd company logo
Nested subqueries and
subquery chaining
Stefan Plantikow
stefan.plantikow@neo4j.org
Petra Selmer
petra.selmer@neo4j.org
Subqueries are self-contained queries running within the scope of
an outer query
<outer-query>
{
<inner-query>
}
<next-outer-query> (continued)
2
What?
1. Read-only nested subqueries
2. Read/Write updating subqueries
3. Set operations
4. Chained subqueries
Not in this talk: Subqueries in expressions (scalar, lists, existential)
3
What?
CIP2017-04-20 - Query combinators for set operations
https://github.com/opencypher/openCypher/pull/227
CIP2016-06-22 - Nested, updating, and chained subqueries
https://github.com/opencypher/openCypher/pull/100
+ CIPs for subqueries in expressions not covered by this talk
4
Relevant CIPs
Queries are easier to:
• construct
• maintain
• read
5
Why?
Subqueries enable:
• Composition of query pipelines
• Programmatic query composition
• Post-processing of results
• Multiple write actions for each record
6
Why?
7
1. Read-only, nested
subqueries
<inner-query>
Any complete, read-only query "... RETURN" enclosed within { }
May be uncorrelated or correlated
(<inner-query> may use variables from the outer query)
Read-only subqueries may be nested at an arbitrary depth
8
Preliminaries
Regular subqueries
MATCH { <inner-query> }
Optional subqueries
OPTIONAL MATCH { <inner-query> }
Mandatory subqueries
MANDATORY MATCH { <inner-query> }
9
Variants
<inner-query> is evaluated for each record from <outer-query>
Variables varouter
from <outer-query> are visible to <inner-query>
Variables varinner
are introduced and returned by <inner-query>
(as output records)
Variables from varouter
and varinner
are available to <next-outer-query>
(as result records)
10
Semantics
<inner-query> may omit variables from varouter
But omitted variables are re-added to the final result records
<inner-query> may shadow and thus alter any variable in varouter
But CIP recommends warning if <inner-query>:
• Discards a variable vi
in varouter
• Re-introduces vi
11
Semantics
result records available to the <next-outer-query>
All output records returned by the <inner-query>
amended with missing variables from varouter
12
Semantics: Regular MATCH
result records available to the <next-outer-query>
All output records returned by the <inner-query>
amended with missing variables from varouter
Generate an error if no output records are returned by <inner-query>
13
Semantics: Mandatory MATCH
result records available to the <next-outer-query>
{
All output records returned by the <inner-query>
(if at least one of these), or a single record with the same
fields as the output records, where any vi
in varinner
is set to
null
}
and amended with missing variables from varouter
14
Semantics: Optional MATCH
MATCH {
MATCH ...
RETURN *
UNION
MATCH ...
RETURN *
}
WITH *
WHERE ...
RETURN *
15
Example: Post-UNION processing
MATCH (u:User {id: $userId})
MATCH (f:Farm {id: $farmId})-[:IS_IN]->(country:Country)
MATCH {
MATCH (u)-[:LIKES]->(b:Brand)-[:PRODUCES]->(p:Lawnmower)
RETURN b.name AS name
UNION
MATCH (u)-[:LIKES]->(b:Brand)-[:PRODUCES]->(v:Vehicle)
WHERE v.leftHandDrive = country.leftHandDrive
RETURN b.name AS name
}
RETURN f, name
16
Example: Correlated subquery
17
2. Read/Write updating
subqueries
<updating-query>
Can be any updating query, and may not end with RETURN
(No data is returned)
18
Preliminaries
<updating-query>
May be uncorrelated or correlated
(<updating-query> may use variables from the outer query)
Updating subqueries may be nested at an arbitrary depth
Read-only nested subqueries may not contain updating subqueries
FOREACH removed from Cypher - now obsolete
19
Preliminaries
Simple updating subqueries
DO { <updating-query> }
Conditionally-updating subqueries
DO
[WHEN <predicate> THEN { <updating-query> }+
[ELSE { <updating-query> }]
END
20
Variants
<updating-query> is run for each incoming record
Executing DO does not affect the cardinality
Input records are passed on to <next-outer-query>
Conditional DO:
This happens whether or not the incoming record is eligible
for processing by <updating-query>
21
Semantics
A query can end with a DO subquery in the same way as an
updating query currently can end with any update clause
All varinner
introduced by <updating-query> are suppressed by DO
DO can be nested within another DO
22
Semantics
DO
[WHEN <predicate> THEN { <updating-query> }+
[ELSE { <updating-query> }]
END
Conditions in WHEN evaluated in order
<updating-query> evaluated for the first true condition, falling
through to ELSE if no true conditions found
Otherwise, no updates will occur
23
Semantics: conditional variant
Old version:
MATCH (r:Root)
FOREACH(x IN range(1, 10) |
MERGE (c:Child {id: x})
MERGE (r)-[:PARENT]->(c)
)
24
Example: FOREACH vs DO
New version:
MATCH (r:Root)
UNWIND range(1, 10) AS x
DO {
MERGE (c:Child {id: x})
MERGE (r)-[:PARENT]->(c)
}
MATCH (r:Root)
UNWIND range(1, 10) AS x
DO WHEN x % 2 = 1 THEN {
MERGE (c:Odd:Child {id: x})
MERGE (r)-[:PARENT]->(c)
}
ELSE {
MERGE (c:Even:Child {id: x})
MERGE (r)-[:PARENT]->(c)
}
END
25
Example: Conditional DO
26
3. Set operations
Set operations combine results from two queries into one
<left-hand-query>
<SET-OPERATION>
<right-hand-query>
27
What?
UNION
UNION ALL
UNION MAX
INTERSECT
INTERSECT ALL
EXCEPT
EXCEPT ALL
EXCLUSIVE UNION
EXCLUSIVE UNION MAX
28
What?
• Rule: <left-hand-query> and <right-hand-query>
return same variables (fields) in same order
• UNION set union
• INTERSECT set intersection
• EXCEPT set difference
• EXCLUSIVE UNION set union
Set operation semantics
29
Set operation semantics
30
• UNION
• INTERSECT
Set operation semantics
31
• EXCLUSIVE UNION
• EXCLUDE
Multiset operations
• UNION ALL n + k
• INTERSECT ALL min(n, k)
• EXCLUDE ALL max(0, n-k)
• UNION MAX max(n, k)
• EXCLUSIVE UNION MAX max(n, k) - min(n,k)
• Rule: <left-hand-query> and <right-hand-query>
return same variables (fields) in same order
• UNION ALL multiset union
• INTERSECT ALL multiset intersection
• EXCEPT ALL multiset difference (0-bounded)
Multiset operation semantics
33
• Rule: <left-hand-query> and <right-hand-query>
return same variables (fields) in same order
• UNION MAX max-bounded multiset union
(largest number of duplicates from either input query)
• EXCLUSIVE UNION MAX exclusive union
(excess duplicates from either input query over the other)
Multiset operation semantics
34
All set operations are left-associative
Q1 UNION Q2 INTERSECT Q3
is equivalent to
((Q1 UNION Q2) INTERSECT Q3)
35
Using multiple set operations
• OTHERWISE [ALL] computes the logical choice between
<left-hand-query> and <right-hand-query>
• Becomes <left-hand-query> if non-empty,
<right-hand-query> otherwise
• OTHERWISE does not preserve duplicates
• OTHERWISE ALL preserves duplicates
• Rule: <left-hand-query> and <right-hand-query>
return same variables (fields) in same order
OTHERWISE [ALL]
36
• CROSS computes the cross product (cartesian product) between
<left-hand-query> and <right-hand-query>
• Rule: <left-hand-query> and <right-hand-query>
must return different variables
CROSS
37
38
4. Chained subqueries
Chain arbitrary queries:
<query1> composedWith <query2> composedWith <query3> ...
Returned variables from <queryN> are passed on to <queryN+1>
39
What?
• Query pipeline construction:
• Factor out subqueries
• Post-union processing
• Execute read-only query after updating query
• Programmatic composition:
• result.cypher("WITH a")
40
Why?
MATCH {
MATCH {
MATCH {
...
// death by curly
...
}
}
}
41
What won't work
● Requires deep nesting
● Would require putting updating queries
inside read-only queries
(instead of after them)
MATCH ...RETURN ...
UNION
MATCH ...RETURN ...
WITH
...
MATCH ...RETURN ...
42
Our proposal
Recast WITH after RETURN as query combinator
(similar to UNION)
● Linear flow of subqueries
● Post-union processing
<query-without-combinator>
<query-combinator>
<query-without-combinator>
...
43
Our proposal
Integrate query combinators and set operations
● Halve level of nesting
<query1>
WITH ...
<query2>
WITH ...
<query3>
...
44
Data-dependent composition
Pass variables and rows
from one query to the next
<query1>
THEN
<query2>
THEN
<query3>
...
45
Data-independent composition
Passes no variables and records
from one query to the next
Instead:
Reduces cardinality to single empty record
WITH ... <query>
Declares expected input variables
Useful for programmatic composition: result.cypher("WITH a")
THEN ... <query>
Drops incoming records
(Reduces cardinality to single empty record)
46
WITH and THEN at start of query
Like set operations, chained subqueries are left-associative!
<query1> WITH ... <query2> THEN <query3> ...
is equivalent to
(((<query1> WITH ... <query2>) THEN <query3>) ...)
47
Complex chained queries
<queryN> cannot contain set operations or query combinators
But it can contain nested subqueries again!
MATCH { ... } RETURN ...
UNION
MATCH { ... } RETURN ...
WITH ...
RETURN ...
48
Complex chained queries
49
Discussion
Multiple Graphs add returning of graphs besides variables
Set operations are defined over sets of records
Set operations may also be defined for graphs
=> This extends to Cypher with support for multiple graphs
Chaining is about passing variables to the follow-up query
=> This extends to Cypher with support for multiple graphs
50
Extension to multiple graphs
Adding subqueries to Cypher will massively increase expressivity
Chained subqueries provide a powerful composition mechanism
Subqueries naturally extends to Cypher for multiple graphs
51
Summary
52
Thank you

More Related Content

What's hot

Using histograms to get better performance
Using histograms to get better performanceUsing histograms to get better performance
Using histograms to get better performance
Sergey Petrunya
 
New SQL features in latest MySQL releases
New SQL features in latest MySQL releasesNew SQL features in latest MySQL releases
New SQL features in latest MySQL releases
Georgi Sotirov
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
Zohar Elkayam
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZE
Norvald Ryeng
 
Table functions - Planboard Symposium 2013
Table functions - Planboard Symposium 2013Table functions - Planboard Symposium 2013
Table functions - Planboard Symposium 2013
Getting value from IoT, Integration and Data Analytics
 
New SQL Features in Firebird 3, by Vlad Khorsun
New SQL Features in Firebird 3, by Vlad KhorsunNew SQL Features in Firebird 3, by Vlad Khorsun
New SQL Features in Firebird 3, by Vlad Khorsun
Mind The Firebird
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performance
oysteing
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace Walkthrough
Sergey Petrunya
 
The MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer TraceThe MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer Trace
oysteing
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
Andrej Pashchenko
 
ANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gemANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gem
Sergey Petrunya
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]s
Sveta Smirnova
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Jaime Crespo
 
Cube rollup slides
Cube rollup slidesCube rollup slides
Cube rollup slides
Saravanan Sevagan
 
Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4
Sergey Petrunya
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
Olav Sandstå
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmark
Sergey Petrunya
 
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZEMySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
Norvald Ryeng
 
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
Rainer Schuettengruber
 

What's hot (20)

Using histograms to get better performance
Using histograms to get better performanceUsing histograms to get better performance
Using histograms to get better performance
 
New SQL features in latest MySQL releases
New SQL features in latest MySQL releasesNew SQL features in latest MySQL releases
New SQL features in latest MySQL releases
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZE
 
Table functions - Planboard Symposium 2013
Table functions - Planboard Symposium 2013Table functions - Planboard Symposium 2013
Table functions - Planboard Symposium 2013
 
New SQL Features in Firebird 3, by Vlad Khorsun
New SQL Features in Firebird 3, by Vlad KhorsunNew SQL Features in Firebird 3, by Vlad Khorsun
New SQL Features in Firebird 3, by Vlad Khorsun
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performance
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace Walkthrough
 
The MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer TraceThe MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer Trace
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
ANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gemANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gem
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]s
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
 
Cube rollup slides
Cube rollup slidesCube rollup slides
Cube rollup slides
 
Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmark
 
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZEMySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
 
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
 

Similar to Nested subqueries and subquery chaining in openCypher

SQL Optimizer vs Hive
SQL Optimizer vs Hive SQL Optimizer vs Hive
SQL Optimizer vs Hive
Vishaka Balasubramanian Sekar
 
Write Faster SQL with Trino.pdf
Write Faster SQL with Trino.pdfWrite Faster SQL with Trino.pdf
Write Faster SQL with Trino.pdf
Eric Xiao
 
Hands on training on DbFit Part-I
Hands on training on DbFit Part-IHands on training on DbFit Part-I
Hands on training on DbFit Part-I
Babul Mirdha
 
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin HuaiA Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
Databricks
 
Code instrumentation
Code instrumentationCode instrumentation
Code instrumentation
Bryan Reinero
 
Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)
Zohar Elkayam
 
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
EDB
 
Understanding the firebird optimizer
Understanding the firebird optimizerUnderstanding the firebird optimizer
Understanding the firebird optimizer
Marius Adrian Popa
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
Fons Sonnemans
 
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
Mahmoud Ouf
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
Olav Sandstå
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
Bo-Young Park
 
Oracle Database Advanced Querying
Oracle Database Advanced QueryingOracle Database Advanced Querying
Oracle Database Advanced Querying
Zohar Elkayam
 
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
InfluxData
 
Apache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationApache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customization
Bartosz Konieczny
 
Optimizing the Catalyst Optimizer for Complex Plans
Optimizing the Catalyst Optimizer for Complex PlansOptimizing the Catalyst Optimizer for Complex Plans
Optimizing the Catalyst Optimizer for Complex Plans
Databricks
 
Odoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 APIOdoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 API
Mustufa Rangwala
 
Odoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new api
Odoo
 
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index WiselySQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
Enkitec
 
Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman Oracle
mCloud
 

Similar to Nested subqueries and subquery chaining in openCypher (20)

SQL Optimizer vs Hive
SQL Optimizer vs Hive SQL Optimizer vs Hive
SQL Optimizer vs Hive
 
Write Faster SQL with Trino.pdf
Write Faster SQL with Trino.pdfWrite Faster SQL with Trino.pdf
Write Faster SQL with Trino.pdf
 
Hands on training on DbFit Part-I
Hands on training on DbFit Part-IHands on training on DbFit Part-I
Hands on training on DbFit Part-I
 
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin HuaiA Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
 
Code instrumentation
Code instrumentationCode instrumentation
Code instrumentation
 
Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)
 
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
Understand the Query Plan to Optimize Performance with EXPLAIN and EXPLAIN AN...
 
Understanding the firebird optimizer
Understanding the firebird optimizerUnderstanding the firebird optimizer
Understanding the firebird optimizer
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
 
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
 
Oracle Database Advanced Querying
Oracle Database Advanced QueryingOracle Database Advanced Querying
Oracle Database Advanced Querying
 
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
 
Apache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationApache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customization
 
Optimizing the Catalyst Optimizer for Complex Plans
Optimizing the Catalyst Optimizer for Complex PlansOptimizing the Catalyst Optimizer for Complex Plans
Optimizing the Catalyst Optimizer for Complex Plans
 
Odoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 APIOdoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 API
 
Odoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new api
 
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index WiselySQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
 
Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman Oracle
 

More from openCypher

Learning Timed Automata with Cypher
Learning Timed Automata with CypherLearning Timed Automata with Cypher
Learning Timed Automata with Cypher
openCypher
 
Incremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher QueriesIncremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher Queries
openCypher
 
Formal semantics for Cypher queries and updates
Formal semantics for Cypher queries and updatesFormal semantics for Cypher queries and updates
Formal semantics for Cypher queries and updates
openCypher
 
Cypher.PL: an executable specification of Cypher semantics
Cypher.PL: an executable specification of Cypher semanticsCypher.PL: an executable specification of Cypher semantics
Cypher.PL: an executable specification of Cypher semantics
openCypher
 
Multiple Graphs: Updatable Views
Multiple Graphs: Updatable ViewsMultiple Graphs: Updatable Views
Multiple Graphs: Updatable Views
openCypher
 
Micro-Servicing Linked Data
Micro-Servicing Linked DataMicro-Servicing Linked Data
Micro-Servicing Linked Data
openCypher
 
Graph abstraction
Graph abstractionGraph abstraction
Graph abstraction
openCypher
 
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
openCypher
 
Cypher for Gremlin
Cypher for GremlinCypher for Gremlin
Cypher for Gremlin
openCypher
 
Comparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and CypherComparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and Cypher
openCypher
 
Multiple graphs in openCypher
Multiple graphs in openCypherMultiple graphs in openCypher
Multiple graphs in openCypher
openCypher
 
Eighth openCypher Implementers Group Meeting: Status Update
Eighth openCypher Implementers Group Meeting: Status UpdateEighth openCypher Implementers Group Meeting: Status Update
Eighth openCypher Implementers Group Meeting: Status Update
openCypher
 
Cypher for Gremlin
Cypher for GremlinCypher for Gremlin
Cypher for Gremlin
openCypher
 
Supporting dates and times in Cypher
Supporting dates and times in CypherSupporting dates and times in Cypher
Supporting dates and times in Cypher
openCypher
 
Seventh openCypher Implementers Group Meeting: Status Update
Seventh openCypher Implementers Group Meeting: Status UpdateSeventh openCypher Implementers Group Meeting: Status Update
Seventh openCypher Implementers Group Meeting: Status Update
openCypher
 
Academic research on graph processing: connecting recent findings to industri...
Academic research on graph processing: connecting recent findings to industri...Academic research on graph processing: connecting recent findings to industri...
Academic research on graph processing: connecting recent findings to industri...
openCypher
 
Property Graphs with Time
Property Graphs with TimeProperty Graphs with Time
Property Graphs with Time
openCypher
 
Cypher.PL: Executable Specification of Cypher written in Prolog
Cypher.PL: Executable Specification of Cypher written in PrologCypher.PL: Executable Specification of Cypher written in Prolog
Cypher.PL: Executable Specification of Cypher written in Prolog
openCypher
 
Use case: processing multiple graphs
Use case: processing multiple graphsUse case: processing multiple graphs
Use case: processing multiple graphs
openCypher
 
openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)
openCypher
 

More from openCypher (20)

Learning Timed Automata with Cypher
Learning Timed Automata with CypherLearning Timed Automata with Cypher
Learning Timed Automata with Cypher
 
Incremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher QueriesIncremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher Queries
 
Formal semantics for Cypher queries and updates
Formal semantics for Cypher queries and updatesFormal semantics for Cypher queries and updates
Formal semantics for Cypher queries and updates
 
Cypher.PL: an executable specification of Cypher semantics
Cypher.PL: an executable specification of Cypher semanticsCypher.PL: an executable specification of Cypher semantics
Cypher.PL: an executable specification of Cypher semantics
 
Multiple Graphs: Updatable Views
Multiple Graphs: Updatable ViewsMultiple Graphs: Updatable Views
Multiple Graphs: Updatable Views
 
Micro-Servicing Linked Data
Micro-Servicing Linked DataMicro-Servicing Linked Data
Micro-Servicing Linked Data
 
Graph abstraction
Graph abstractionGraph abstraction
Graph abstraction
 
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
 
Cypher for Gremlin
Cypher for GremlinCypher for Gremlin
Cypher for Gremlin
 
Comparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and CypherComparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and Cypher
 
Multiple graphs in openCypher
Multiple graphs in openCypherMultiple graphs in openCypher
Multiple graphs in openCypher
 
Eighth openCypher Implementers Group Meeting: Status Update
Eighth openCypher Implementers Group Meeting: Status UpdateEighth openCypher Implementers Group Meeting: Status Update
Eighth openCypher Implementers Group Meeting: Status Update
 
Cypher for Gremlin
Cypher for GremlinCypher for Gremlin
Cypher for Gremlin
 
Supporting dates and times in Cypher
Supporting dates and times in CypherSupporting dates and times in Cypher
Supporting dates and times in Cypher
 
Seventh openCypher Implementers Group Meeting: Status Update
Seventh openCypher Implementers Group Meeting: Status UpdateSeventh openCypher Implementers Group Meeting: Status Update
Seventh openCypher Implementers Group Meeting: Status Update
 
Academic research on graph processing: connecting recent findings to industri...
Academic research on graph processing: connecting recent findings to industri...Academic research on graph processing: connecting recent findings to industri...
Academic research on graph processing: connecting recent findings to industri...
 
Property Graphs with Time
Property Graphs with TimeProperty Graphs with Time
Property Graphs with Time
 
Cypher.PL: Executable Specification of Cypher written in Prolog
Cypher.PL: Executable Specification of Cypher written in PrologCypher.PL: Executable Specification of Cypher written in Prolog
Cypher.PL: Executable Specification of Cypher written in Prolog
 
Use case: processing multiple graphs
Use case: processing multiple graphsUse case: processing multiple graphs
Use case: processing multiple graphs
 
openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)
 

Recently uploaded

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 

Recently uploaded (20)

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 

Nested subqueries and subquery chaining in openCypher

  • 1. Nested subqueries and subquery chaining Stefan Plantikow stefan.plantikow@neo4j.org Petra Selmer petra.selmer@neo4j.org
  • 2. Subqueries are self-contained queries running within the scope of an outer query <outer-query> { <inner-query> } <next-outer-query> (continued) 2 What?
  • 3. 1. Read-only nested subqueries 2. Read/Write updating subqueries 3. Set operations 4. Chained subqueries Not in this talk: Subqueries in expressions (scalar, lists, existential) 3 What?
  • 4. CIP2017-04-20 - Query combinators for set operations https://github.com/opencypher/openCypher/pull/227 CIP2016-06-22 - Nested, updating, and chained subqueries https://github.com/opencypher/openCypher/pull/100 + CIPs for subqueries in expressions not covered by this talk 4 Relevant CIPs
  • 5. Queries are easier to: • construct • maintain • read 5 Why?
  • 6. Subqueries enable: • Composition of query pipelines • Programmatic query composition • Post-processing of results • Multiple write actions for each record 6 Why?
  • 8. <inner-query> Any complete, read-only query "... RETURN" enclosed within { } May be uncorrelated or correlated (<inner-query> may use variables from the outer query) Read-only subqueries may be nested at an arbitrary depth 8 Preliminaries
  • 9. Regular subqueries MATCH { <inner-query> } Optional subqueries OPTIONAL MATCH { <inner-query> } Mandatory subqueries MANDATORY MATCH { <inner-query> } 9 Variants
  • 10. <inner-query> is evaluated for each record from <outer-query> Variables varouter from <outer-query> are visible to <inner-query> Variables varinner are introduced and returned by <inner-query> (as output records) Variables from varouter and varinner are available to <next-outer-query> (as result records) 10 Semantics
  • 11. <inner-query> may omit variables from varouter But omitted variables are re-added to the final result records <inner-query> may shadow and thus alter any variable in varouter But CIP recommends warning if <inner-query>: • Discards a variable vi in varouter • Re-introduces vi 11 Semantics
  • 12. result records available to the <next-outer-query> All output records returned by the <inner-query> amended with missing variables from varouter 12 Semantics: Regular MATCH
  • 13. result records available to the <next-outer-query> All output records returned by the <inner-query> amended with missing variables from varouter Generate an error if no output records are returned by <inner-query> 13 Semantics: Mandatory MATCH
  • 14. result records available to the <next-outer-query> { All output records returned by the <inner-query> (if at least one of these), or a single record with the same fields as the output records, where any vi in varinner is set to null } and amended with missing variables from varouter 14 Semantics: Optional MATCH
  • 15. MATCH { MATCH ... RETURN * UNION MATCH ... RETURN * } WITH * WHERE ... RETURN * 15 Example: Post-UNION processing
  • 16. MATCH (u:User {id: $userId}) MATCH (f:Farm {id: $farmId})-[:IS_IN]->(country:Country) MATCH { MATCH (u)-[:LIKES]->(b:Brand)-[:PRODUCES]->(p:Lawnmower) RETURN b.name AS name UNION MATCH (u)-[:LIKES]->(b:Brand)-[:PRODUCES]->(v:Vehicle) WHERE v.leftHandDrive = country.leftHandDrive RETURN b.name AS name } RETURN f, name 16 Example: Correlated subquery
  • 18. <updating-query> Can be any updating query, and may not end with RETURN (No data is returned) 18 Preliminaries
  • 19. <updating-query> May be uncorrelated or correlated (<updating-query> may use variables from the outer query) Updating subqueries may be nested at an arbitrary depth Read-only nested subqueries may not contain updating subqueries FOREACH removed from Cypher - now obsolete 19 Preliminaries
  • 20. Simple updating subqueries DO { <updating-query> } Conditionally-updating subqueries DO [WHEN <predicate> THEN { <updating-query> }+ [ELSE { <updating-query> }] END 20 Variants
  • 21. <updating-query> is run for each incoming record Executing DO does not affect the cardinality Input records are passed on to <next-outer-query> Conditional DO: This happens whether or not the incoming record is eligible for processing by <updating-query> 21 Semantics
  • 22. A query can end with a DO subquery in the same way as an updating query currently can end with any update clause All varinner introduced by <updating-query> are suppressed by DO DO can be nested within another DO 22 Semantics
  • 23. DO [WHEN <predicate> THEN { <updating-query> }+ [ELSE { <updating-query> }] END Conditions in WHEN evaluated in order <updating-query> evaluated for the first true condition, falling through to ELSE if no true conditions found Otherwise, no updates will occur 23 Semantics: conditional variant
  • 24. Old version: MATCH (r:Root) FOREACH(x IN range(1, 10) | MERGE (c:Child {id: x}) MERGE (r)-[:PARENT]->(c) ) 24 Example: FOREACH vs DO New version: MATCH (r:Root) UNWIND range(1, 10) AS x DO { MERGE (c:Child {id: x}) MERGE (r)-[:PARENT]->(c) }
  • 25. MATCH (r:Root) UNWIND range(1, 10) AS x DO WHEN x % 2 = 1 THEN { MERGE (c:Odd:Child {id: x}) MERGE (r)-[:PARENT]->(c) } ELSE { MERGE (c:Even:Child {id: x}) MERGE (r)-[:PARENT]->(c) } END 25 Example: Conditional DO
  • 27. Set operations combine results from two queries into one <left-hand-query> <SET-OPERATION> <right-hand-query> 27 What?
  • 28. UNION UNION ALL UNION MAX INTERSECT INTERSECT ALL EXCEPT EXCEPT ALL EXCLUSIVE UNION EXCLUSIVE UNION MAX 28 What?
  • 29. • Rule: <left-hand-query> and <right-hand-query> return same variables (fields) in same order • UNION set union • INTERSECT set intersection • EXCEPT set difference • EXCLUSIVE UNION set union Set operation semantics 29
  • 30. Set operation semantics 30 • UNION • INTERSECT
  • 31. Set operation semantics 31 • EXCLUSIVE UNION • EXCLUDE
  • 32. Multiset operations • UNION ALL n + k • INTERSECT ALL min(n, k) • EXCLUDE ALL max(0, n-k) • UNION MAX max(n, k) • EXCLUSIVE UNION MAX max(n, k) - min(n,k)
  • 33. • Rule: <left-hand-query> and <right-hand-query> return same variables (fields) in same order • UNION ALL multiset union • INTERSECT ALL multiset intersection • EXCEPT ALL multiset difference (0-bounded) Multiset operation semantics 33
  • 34. • Rule: <left-hand-query> and <right-hand-query> return same variables (fields) in same order • UNION MAX max-bounded multiset union (largest number of duplicates from either input query) • EXCLUSIVE UNION MAX exclusive union (excess duplicates from either input query over the other) Multiset operation semantics 34
  • 35. All set operations are left-associative Q1 UNION Q2 INTERSECT Q3 is equivalent to ((Q1 UNION Q2) INTERSECT Q3) 35 Using multiple set operations
  • 36. • OTHERWISE [ALL] computes the logical choice between <left-hand-query> and <right-hand-query> • Becomes <left-hand-query> if non-empty, <right-hand-query> otherwise • OTHERWISE does not preserve duplicates • OTHERWISE ALL preserves duplicates • Rule: <left-hand-query> and <right-hand-query> return same variables (fields) in same order OTHERWISE [ALL] 36
  • 37. • CROSS computes the cross product (cartesian product) between <left-hand-query> and <right-hand-query> • Rule: <left-hand-query> and <right-hand-query> must return different variables CROSS 37
  • 39. Chain arbitrary queries: <query1> composedWith <query2> composedWith <query3> ... Returned variables from <queryN> are passed on to <queryN+1> 39 What?
  • 40. • Query pipeline construction: • Factor out subqueries • Post-union processing • Execute read-only query after updating query • Programmatic composition: • result.cypher("WITH a") 40 Why?
  • 41. MATCH { MATCH { MATCH { ... // death by curly ... } } } 41 What won't work ● Requires deep nesting ● Would require putting updating queries inside read-only queries (instead of after them)
  • 42. MATCH ...RETURN ... UNION MATCH ...RETURN ... WITH ... MATCH ...RETURN ... 42 Our proposal Recast WITH after RETURN as query combinator (similar to UNION) ● Linear flow of subqueries ● Post-union processing
  • 44. <query1> WITH ... <query2> WITH ... <query3> ... 44 Data-dependent composition Pass variables and rows from one query to the next
  • 45. <query1> THEN <query2> THEN <query3> ... 45 Data-independent composition Passes no variables and records from one query to the next Instead: Reduces cardinality to single empty record
  • 46. WITH ... <query> Declares expected input variables Useful for programmatic composition: result.cypher("WITH a") THEN ... <query> Drops incoming records (Reduces cardinality to single empty record) 46 WITH and THEN at start of query
  • 47. Like set operations, chained subqueries are left-associative! <query1> WITH ... <query2> THEN <query3> ... is equivalent to (((<query1> WITH ... <query2>) THEN <query3>) ...) 47 Complex chained queries
  • 48. <queryN> cannot contain set operations or query combinators But it can contain nested subqueries again! MATCH { ... } RETURN ... UNION MATCH { ... } RETURN ... WITH ... RETURN ... 48 Complex chained queries
  • 50. Multiple Graphs add returning of graphs besides variables Set operations are defined over sets of records Set operations may also be defined for graphs => This extends to Cypher with support for multiple graphs Chaining is about passing variables to the follow-up query => This extends to Cypher with support for multiple graphs 50 Extension to multiple graphs
  • 51. Adding subqueries to Cypher will massively increase expressivity Chained subqueries provide a powerful composition mechanism Subqueries naturally extends to Cypher for multiple graphs 51 Summary