Skip to content

Commit

Permalink
modify exists execution plan (TuGraph-family#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
lipanpan03 authored Sep 20, 2024
1 parent ebbd863 commit 1a665ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
13 changes: 5 additions & 8 deletions src/cypher/execution_plan/execution_plan_maker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ std::any ExecutionPlanMaker::visit(geax::frontend::PathChain* node) {
++filter_level_;
}
std::reverse(expand_ops.begin(), expand_ops.end());
// For the exists pattern query, SemiAllpy is simulated by combining Limit Optional and
// For the exists pattern query, SemiApply is simulated by combining Limit Optional and
// ExpandAll operators. e.g MATCH (n {name:'Rachel Kempson'}),(m:Person) RETURN
// exists((n)-[:MARRIED]->(m)) The resulting execution plan is as follows Produce Results
// Project [exists((n)-[:MARRIED]->(m))]
Expand All @@ -431,13 +431,10 @@ std::any ExecutionPlanMaker::visit(geax::frontend::PathChain* node) {
if (ClauseGuard::InClause(geax::frontend::AstNodeType::kExists, cur_types_)) {
auto& sym_tab = pattern_graphs_[cur_pattern_graph_].symbol_table;
std::vector<OpBase*> rewriter;
if (ClauseGuard::InClause(geax::frontend::AstNodeType::kPrimitiveResultStatement,
cur_types_)) {
auto limit = new Limit(1);
rewriter.push_back(limit);
auto optional = new Optional();
rewriter.push_back(optional);
}
auto limit = new Limit(1);
rewriter.push_back(limit);
auto optional = new Optional();
rewriter.push_back(optional);
rewriter.insert(rewriter.end(), expand_ops.begin(), expand_ops.end());
auto argument = new Argument(&sym_tab);
rewriter.push_back(argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ CALL db.createLabel('edge', 'WROTE_MUSIC_FOR', '[]');
[]
CALL db.createLabel('edge', 'ACTED_IN', '[]', ['charactername', 'string', true]);
[]
CREATE (rachel:Person:Actor {name: 'Rachel Kempson', birthyear: 1910}) CREATE (michael:Person:Actor {name: 'Michael Redgrave', birthyear: 1908}) CREATE (vanessa:Person:Actor {name: 'Vanessa Redgrave', birthyear: 1937}) CREATE (corin:Person:Actor {name: 'Corin Redgrave', birthyear: 1939}) CREATE (liam:Person:Actor {name: 'Liam Neeson', birthyear: 1952}) CREATE (natasha:Person:Actor {name: 'Natasha Richardson', birthyear: 1963}) CREATE (richard:Person:Actor {name: 'Richard Harris', birthyear: 1930}) CREATE (dennis:Person:Actor {name: 'Dennis Quaid', birthyear: 1954}) CREATE (lindsay:Person:Actor {name: 'Lindsay Lohan', birthyear: 1986}) CREATE (jemma:Person:Actor {name: 'Jemma Redgrave', birthyear: 1965}) CREATE (roy:Person:Actor {name: 'Roy Redgrave', birthyear: 1873}) CREATE (john:Person {name: 'John Williams', birthyear: 1932}) CREATE (christopher:Person {name: 'Christopher Nolan', birthyear: 1970}) CREATE (newyork:City {name: 'New York'}) CREATE (london:City {name: 'London'}) CREATE (houston:City {name: 'Houston'}) CREATE (mrchips:Film {title: 'Goodbye, Mr. Chips'}) CREATE (batmanbegins:Film {title: 'Batman Begins'}) CREATE (harrypotter:Film {title: 'Harry Potter and the Sorcerer\'s Stone'}) CREATE (parent:Film {title: 'The Parent Trap'}) CREATE (camelot:Film {title: 'Camelot'}) CREATE (rachel)-[:HAS_CHILD]->(vanessa), (rachel)-[:HAS_CHILD]->(corin), (michael)-[:HAS_CHILD]->(vanessa), (michael)-[:HAS_CHILD]->(corin), (corin)-[:HAS_CHILD]->(jemma), (vanessa)-[:HAS_CHILD]->(natasha), (roy)-[:HAS_CHILD]->(michael), (rachel)-[:MARRIED]->(michael), (michael)-[:MARRIED]->(rachel), (natasha)-[:MARRIED]->(liam), (liam)-[:MARRIED]->(natasha), (vanessa)-[:BORN_IN]->(london),(natasha)-[:BORN_IN]->(london), (christopher)-[:BORN_IN]->(london), (dennis)-[:BORN_IN]->(houston), (lindsay)-[:BORN_IN]->(newyork), (john)-[:BORN_IN]->(newyork), (christopher)-[:DIRECTED]->(batmanbegins), (john)-[:WROTE_MUSIC_FOR]->(harrypotter), (john)-[:WROTE_MUSIC_FOR]->(mrchips), (michael)-[:ACTED_IN {charactername: 'The Headmaster'}]->(mrchips), (vanessa)-[:ACTED_IN {charactername: 'Guenevere'}]->(camelot), (richard)-[:ACTED_IN {charactername: 'King Arthur'}]->(camelot), (richard)-[:ACTED_IN {charactername: 'Albus Dumbledore'}]->(harrypotter), (natasha)-[:ACTED_IN {charactername: 'Liz James'}]->(parent), (dennis)-[:ACTED_IN {charactername: 'Nick Parker'}]->(parent), (lindsay)-[:ACTED_IN {charactername: 'Halle/Annie'}]->(parent), (liam)-[:ACTED_IN {charactername: 'Henri Ducard'}]->(batmanbegins) ;
CREATE (rachel:Person:Actor {name: 'HaHa', birthyear: 1910});
[{"<SUMMARY>":"created 1 vertices, created 0 edges."}]
MATCH (n) WHERE NOT EXISTS ((n)-[]-()) RETURN n;
[{"n":{"identity":0,"label":"Person","properties":{"birthyear":1910,"name":"HaHa"}}}]
CREATE (rachel:Person:Actor {name: 'Rachel Kempson', birthyear: 1910}) CREATE (michael:Person:Actor {name: 'Michael Redgrave', birthyear: 1908}) CREATE (vanessa:Person:Actor {name: 'Vanessa Redgrave', birthyear: 1937}) CREATE (corin:Person:Actor {name: 'Corin Redgrave', birthyear: 1939}) CREATE (liam:Person:Actor {name: 'Liam Neeson', birthyear: 1952}) CREATE (natasha:Person:Actor {name: 'Natasha Richardson', birthyear: 1963}) CREATE (richard:Person:Actor {name: 'Richard Harris', birthyear: 1930}) CREATE (dennis:Person:Actor {name: 'Dennis Quaid', birthyear: 1954}) CREATE (lindsay:Person:Actor {name: 'Lindsay Lohan', birthyear: 1986}) CREATE (jemma:Person:Actor {name: 'Jemma Redgrave', birthyear: 1965}) CREATE (roy:Person:Actor {name: 'Roy Redgrave', birthyear: 1873}) CREATE (john:Person {name: 'John Williams', birthyear: 1932}) CREATE (christopher:Person {name: 'Christopher Nolan', birthyear: 1970}) CREATE (newyork:City {name: 'New York'}) CREATE (london:City {name: 'London'}) CREATE (houston:City {name: 'Houston'}) CREATE (mrchips:Film {title: 'Goodbye, Mr. Chips'}) CREATE (batmanbegins:Film {title: 'Batman Begins'}) CREATE (harrypotter:Film {title: 'Harry Potter and the Sorcerer\'s Stone'}) CREATE (parent:Film {title: 'The Parent Trap'}) CREATE (camelot:Film {title: 'Camelot'}) CREATE (rachel)-[:HAS_CHILD]->(vanessa), (rachel)-[:HAS_CHILD]->(corin), (michael)-[:HAS_CHILD]->(vanessa), (michael)-[:HAS_CHILD]->(corin), (corin)-[:HAS_CHILD]->(jemma), (vanessa)-[:HAS_CHILD]->(natasha), (roy)-[:HAS_CHILD]->(michael), (rachel)-[:MARRIED]->(michael), (michael)-[:MARRIED]->(rachel), (natasha)-[:MARRIED]->(liam), (liam)-[:MARRIED]->(natasha), (vanessa)-[:BORN_IN]->(london),(natasha)-[:BORN_IN]->(london), (christopher)-[:BORN_IN]->(london), (dennis)-[:BORN_IN]->(houston), (lindsay)-[:BORN_IN]->(newyork), (john)-[:BORN_IN]->(newyork), (christopher)-[:DIRECTED]->(batmanbegins), (john)-[:WROTE_MUSIC_FOR]->(harrypotter), (john)-[:WROTE_MUSIC_FOR]->(mrchips), (michael)-[:ACTED_IN {charactername: 'The Headmaster'}]->(mrchips), (vanessa)-[:ACTED_IN {charactername: 'Guenevere'}]->(camelot), (richard)-[:ACTED_IN {charactername: 'King Arthur'}]->(camelot), (richard)-[:ACTED_IN {charactername: 'Albus Dumbledore'}]->(harrypotter), (natasha)-[:ACTED_IN {charactername: 'Liz James'}]->(parent), (dennis)-[:ACTED_IN {charactername: 'Nick Parker'}]->(parent), (lindsay)-[:ACTED_IN {charactername: 'Halle/Annie'}]->(parent), (liam)-[:ACTED_IN {charactername: 'Henri Ducard'}]->(batmanbegins) ;
[{"<SUMMARY>":"created 21 vertices, created 28 edges."}]
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ CALL db.createLabel('edge', 'BORN_IN', '[]');
CALL db.createLabel('edge', 'DIRECTED', '[]');
CALL db.createLabel('edge', 'WROTE_MUSIC_FOR', '[]');
CALL db.createLabel('edge', 'ACTED_IN', '[]', ['charactername', 'string', true]);
CREATE (rachel:Person:Actor {name: 'Rachel Kempson', birthyear: 1910}) CREATE (michael:Person:Actor {name: 'Michael Redgrave', birthyear: 1908}) CREATE (vanessa:Person:Actor {name: 'Vanessa Redgrave', birthyear: 1937}) CREATE (corin:Person:Actor {name: 'Corin Redgrave', birthyear: 1939}) CREATE (liam:Person:Actor {name: 'Liam Neeson', birthyear: 1952}) CREATE (natasha:Person:Actor {name: 'Natasha Richardson', birthyear: 1963}) CREATE (richard:Person:Actor {name: 'Richard Harris', birthyear: 1930}) CREATE (dennis:Person:Actor {name: 'Dennis Quaid', birthyear: 1954}) CREATE (lindsay:Person:Actor {name: 'Lindsay Lohan', birthyear: 1986}) CREATE (jemma:Person:Actor {name: 'Jemma Redgrave', birthyear: 1965}) CREATE (roy:Person:Actor {name: 'Roy Redgrave', birthyear: 1873}) CREATE (john:Person {name: 'John Williams', birthyear: 1932}) CREATE (christopher:Person {name: 'Christopher Nolan', birthyear: 1970}) CREATE (newyork:City {name: 'New York'}) CREATE (london:City {name: 'London'}) CREATE (houston:City {name: 'Houston'}) CREATE (mrchips:Film {title: 'Goodbye, Mr. Chips'}) CREATE (batmanbegins:Film {title: 'Batman Begins'}) CREATE (harrypotter:Film {title: 'Harry Potter and the Sorcerer\'s Stone'}) CREATE (parent:Film {title: 'The Parent Trap'}) CREATE (camelot:Film {title: 'Camelot'}) CREATE (rachel)-[:HAS_CHILD]->(vanessa), (rachel)-[:HAS_CHILD]->(corin), (michael)-[:HAS_CHILD]->(vanessa), (michael)-[:HAS_CHILD]->(corin), (corin)-[:HAS_CHILD]->(jemma), (vanessa)-[:HAS_CHILD]->(natasha), (roy)-[:HAS_CHILD]->(michael), (rachel)-[:MARRIED]->(michael), (michael)-[:MARRIED]->(rachel), (natasha)-[:MARRIED]->(liam), (liam)-[:MARRIED]->(natasha), (vanessa)-[:BORN_IN]->(london),(natasha)-[:BORN_IN]->(london), (christopher)-[:BORN_IN]->(london), (dennis)-[:BORN_IN]->(houston), (lindsay)-[:BORN_IN]->(newyork), (john)-[:BORN_IN]->(newyork), (christopher)-[:DIRECTED]->(batmanbegins), (john)-[:WROTE_MUSIC_FOR]->(harrypotter), (john)-[:WROTE_MUSIC_FOR]->(mrchips), (michael)-[:ACTED_IN {charactername: 'The Headmaster'}]->(mrchips), (vanessa)-[:ACTED_IN {charactername: 'Guenevere'}]->(camelot), (richard)-[:ACTED_IN {charactername: 'King Arthur'}]->(camelot), (richard)-[:ACTED_IN {charactername: 'Albus Dumbledore'}]->(harrypotter), (natasha)-[:ACTED_IN {charactername: 'Liz James'}]->(parent), (dennis)-[:ACTED_IN {charactername: 'Nick Parker'}]->(parent), (lindsay)-[:ACTED_IN {charactername: 'Halle/Annie'}]->(parent), (liam)-[:ACTED_IN {charactername: 'Henri Ducard'}]->(batmanbegins) ;
CREATE (rachel:Person:Actor {name: 'HaHa', birthyear: 1910});
MATCH (n) WHERE NOT EXISTS ((n)-[]-()) RETURN n;
CREATE (rachel:Person:Actor {name: 'Rachel Kempson', birthyear: 1910}) CREATE (michael:Person:Actor {name: 'Michael Redgrave', birthyear: 1908}) CREATE (vanessa:Person:Actor {name: 'Vanessa Redgrave', birthyear: 1937}) CREATE (corin:Person:Actor {name: 'Corin Redgrave', birthyear: 1939}) CREATE (liam:Person:Actor {name: 'Liam Neeson', birthyear: 1952}) CREATE (natasha:Person:Actor {name: 'Natasha Richardson', birthyear: 1963}) CREATE (richard:Person:Actor {name: 'Richard Harris', birthyear: 1930}) CREATE (dennis:Person:Actor {name: 'Dennis Quaid', birthyear: 1954}) CREATE (lindsay:Person:Actor {name: 'Lindsay Lohan', birthyear: 1986}) CREATE (jemma:Person:Actor {name: 'Jemma Redgrave', birthyear: 1965}) CREATE (roy:Person:Actor {name: 'Roy Redgrave', birthyear: 1873}) CREATE (john:Person {name: 'John Williams', birthyear: 1932}) CREATE (christopher:Person {name: 'Christopher Nolan', birthyear: 1970}) CREATE (newyork:City {name: 'New York'}) CREATE (london:City {name: 'London'}) CREATE (houston:City {name: 'Houston'}) CREATE (mrchips:Film {title: 'Goodbye, Mr. Chips'}) CREATE (batmanbegins:Film {title: 'Batman Begins'}) CREATE (harrypotter:Film {title: 'Harry Potter and the Sorcerer\'s Stone'}) CREATE (parent:Film {title: 'The Parent Trap'}) CREATE (camelot:Film {title: 'Camelot'}) CREATE (rachel)-[:HAS_CHILD]->(vanessa), (rachel)-[:HAS_CHILD]->(corin), (michael)-[:HAS_CHILD]->(vanessa), (michael)-[:HAS_CHILD]->(corin), (corin)-[:HAS_CHILD]->(jemma), (vanessa)-[:HAS_CHILD]->(natasha), (roy)-[:HAS_CHILD]->(michael), (rachel)-[:MARRIED]->(michael), (michael)-[:MARRIED]->(rachel), (natasha)-[:MARRIED]->(liam), (liam)-[:MARRIED]->(natasha), (vanessa)-[:BORN_IN]->(london),(natasha)-[:BORN_IN]->(london), (christopher)-[:BORN_IN]->(london), (dennis)-[:BORN_IN]->(houston), (lindsay)-[:BORN_IN]->(newyork), (john)-[:BORN_IN]->(newyork), (christopher)-[:DIRECTED]->(batmanbegins), (john)-[:WROTE_MUSIC_FOR]->(harrypotter), (john)-[:WROTE_MUSIC_FOR]->(mrchips), (michael)-[:ACTED_IN {charactername: 'The Headmaster'}]->(mrchips), (vanessa)-[:ACTED_IN {charactername: 'Guenevere'}]->(camelot), (richard)-[:ACTED_IN {charactername: 'King Arthur'}]->(camelot), (richard)-[:ACTED_IN {charactername: 'Albus Dumbledore'}]->(harrypotter), (natasha)-[:ACTED_IN {charactername: 'Liz James'}]->(parent), (dennis)-[:ACTED_IN {charactername: 'Nick Parker'}]->(parent), (lindsay)-[:ACTED_IN {charactername: 'Halle/Annie'}]->(parent), (liam)-[:ACTED_IN {charactername: 'Henri Ducard'}]->(batmanbegins) ;

0 comments on commit 1a665ef

Please sign in to comment.