Skip to content

Commit

Permalink
Fix bug in CorrelatedSubqueryUnnestSolver (#4088)
Browse files Browse the repository at this point in the history
* Fix issue 4080

* Run clang-format

---------

Co-authored-by: CI Bot <andyfengHKU@users.noreply.github.com>
  • Loading branch information
andyfengHKU and andyfengHKU authored Aug 15, 2024
1 parent b579299 commit 2067ffa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/optimizer/correlated_subquery_unnest_solver.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "optimizer/correlated_subquery_unnest_solver.h"

#include "common/exception/internal.h"
#include "planner/operator/logical_hash_join.h"
#include "planner/operator/scan/logical_expressions_scan.h"

using namespace kuzu::planner;

namespace kuzu {
Expand Down Expand Up @@ -30,13 +32,18 @@ void CorrelatedSubqueryUnnestSolver::solveAccHashJoin(LogicalOperator* op) const
auto acc = op->getChild(0).get();
auto rightSolver = std::make_unique<CorrelatedSubqueryUnnestSolver>(acc);
rightSolver->solve(hashJoin.getChild(1).get());
auto leftSolver = std::make_unique<CorrelatedSubqueryUnnestSolver>(nullptr);
auto leftSolver = std::make_unique<CorrelatedSubqueryUnnestSolver>(accumulateOp);
leftSolver->solve(acc->getChild(0).get());
}

void CorrelatedSubqueryUnnestSolver::visitExpressionsScan(LogicalOperator* op) {
auto expressionsScan = op->ptrCast<LogicalExpressionsScan>();
KU_ASSERT(accumulateOp != nullptr);
// LCOV_EXCL_START
if (accumulateOp == nullptr) {
throw common::InternalException(
"Failed to execute CorrelatedSubqueryUnnestSolver. This should not happen.");
}
// LCOV_EXCL_STOP
expressionsScan->setOuterAccumulate(accumulateOp);
}

Expand Down
19 changes: 19 additions & 0 deletions test/test_files/issue/issue.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

--

-CASE 4080
-STATEMENT CREATE NODE TABLE V(id INT, PRIMARY KEY(id));
---- ok
-STATEMENT CREATE REL TABLE links_to(FROM V to V);
---- ok
-STATEMENT CREATE REL TABLE parent(FROM V to V);
---- ok
-STATEMENT CREATE (:V {id: 1}), (:V {id: 2});
---- ok
-STATEMENT MATCH (v1:V {id: 1}), (v2:V {id: 2})
CREATE (v1)-[:links_to]->(v2), (v1)-[:parent]->(v2)
---- ok
-STATEMENT WITH 2 as parent_id
OPTIONAL MATCH (v1:V)-[:links_to*1..]->(:V)
WHERE EXISTS {MATCH (v1)-[:parent]->(:V {id: parent_id})}
RETURN v1.id;
---- 1
1

-CASE listContainsCast
-STATEMENT CREATE NODE TABLE A(id SERIAL, primary key(id));
---- ok
Expand Down

0 comments on commit 2067ffa

Please sign in to comment.