Skip to content

Commit

Permalink
Push recursive join length into operator
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed May 20, 2023
1 parent d831e85 commit ac685e4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/binder/bind_expression/bind_function_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ std::unique_ptr<Expression> ExpressionBinder::createInternalLengthExpression(

std::shared_ptr<Expression> ExpressionBinder::bindRecursiveJoinLengthFunction(
const Expression& expression) {
if ( expression.getDataType().getLogicalTypeID() != common::LogicalTypeID::RECURSIVE_REL) {
if (expression.getDataType().getLogicalTypeID() != common::LogicalTypeID::RECURSIVE_REL) {
return nullptr;
}
auto& rel = (RelExpression&)expression;
Expand Down
14 changes: 12 additions & 2 deletions src/optimizer/projection_push_down_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,18 @@ binder::expression_vector ProjectionPushDownOptimizer::pruneExpressions(
const binder::expression_vector& expressions) {
expression_set expressionsAfterPruning;
for (auto& expression : expressions) {
if (expression->expressionType != common::PROPERTY ||
propertiesInUse.contains(expression)) {
switch (expression->expressionType) {
case common::VARIABLE: {
if (variablesInUse.contains(expression)) {
expressionsAfterPruning.insert(expression);
}
} break;
case common::PROPERTY: {
if (propertiesInUse.contains(expression)) {
expressionsAfterPruning.insert(expression);
}
} break;
default: // We don't track other expression types so always assume they will be in use.
expressionsAfterPruning.insert(expression);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/planner/projection_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ expression_vector ProjectionPlanner::rewriteExpressionsToProject(
}
} break;
case LogicalTypeID::RECURSIVE_REL: {
// TODO
auto& rel = (RelExpression&)*expression;
result.push_back(rel.getInternalLengthExpression());
result.push_back(expression);
} break;
default:
Expand Down
10 changes: 10 additions & 0 deletions test/optimizer/optimizer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "graph_test/graph_test.h"
#include "planner/logical_plan/logical_operator/logical_recursive_extend.h"
#include "planner/logical_plan/logical_plan_util.h"

namespace kuzu {
Expand Down Expand Up @@ -92,5 +93,14 @@ TEST_F(OptimizerTest, RecursiveJoinTest) {
ASSERT_STREQ(encodedPlan.c_str(), "HJ(a._id){RE(a)S(b)}{S(a)}");
}

TEST_F(OptimizerTest, RecursiveJoinNoTrackPathTest) {
auto op = getRoot("MATCH (a:person)-[e:knows* SHORTEST 2..3]->(b:person) RETURN length(e);");
while (op->getOperatorType() != planner::LogicalOperatorType::RECURSIVE_EXTEND) {
op = op->getChild(0);
}
auto recursiveExtend = (planner::LogicalRecursiveExtend*)op.get();
ASSERT_FALSE(recursiveExtend->trackPath());
}

} // namespace testing
} // namespace kuzu

0 comments on commit ac685e4

Please sign in to comment.