Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in CorrelatedSubqueryUnnestSolver #4088

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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