Skip to content

Commit

Permalink
This now seems to work,
Browse files Browse the repository at this point in the history
feed it to the tools and comment it.

Signed-off-by: Johannes Kalmbach <[email protected]>
  • Loading branch information
joka921 committed Apr 19, 2024
1 parent a6c6dab commit 6a52ae5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
16 changes: 12 additions & 4 deletions src/engine/TransitivePathBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,17 @@ std::shared_ptr<TransitivePathBase> TransitivePathBase::bindLeftOrRightSide(
} else {
rhs.treeAndCol_ = {leftOrRightOp, inputCol};
}
std::shared_ptr<TransitivePathBase> p =
TransitivePathBase::makeTransitivePath(getExecutionContext(), subtree_,
lhs, rhs, minDist_, maxDist_);
std::vector<std::shared_ptr<TransitivePathBase>> candidates;
candidates.push_back(TransitivePathBase::makeTransitivePath(
getExecutionContext(), subtree_, lhs, rhs, minDist_, maxDist_));
for (const auto& alternativeSubtree : alternativeSubtrees()) {
candidates.push_back(TransitivePathBase::makeTransitivePath(
getExecutionContext(), alternativeSubtree, lhs, rhs, minDist_,
maxDist_));
}

auto& p = *std::ranges::min_element(
candidates, {}, [](const auto& tree) { return tree->getCostEstimate(); });

// Note: The `variable` in the following structured binding is `const`, even
// if we bind by value. We deliberately make one unnecessary copy of the
Expand All @@ -374,7 +382,7 @@ std::shared_ptr<TransitivePathBase> TransitivePathBase::bindLeftOrRightSide(
p->variableColumns_[variable] = columnIndexWithType;
p->resultWidth_++;
}
return p;
return std::move(p);
}

// _____________________________________________________________________________
Expand Down
8 changes: 6 additions & 2 deletions src/engine/TransitivePathBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ struct TransitivePathSide {
os << "Id: " << std::get<Id>(value_);
}

os << ", subColumn: " <<
subCol_ << "to " << outputCol_;
os << ", subColumn: " << subCol_ << "to " << outputCol_;

if (treeAndCol_.has_value()) {
const auto& [tree, col] = treeAndCol_.value();
Expand Down Expand Up @@ -270,4 +269,9 @@ class TransitivePathBase : public Operation {
virtual std::shared_ptr<TransitivePathBase> bindLeftOrRightSide(
std::shared_ptr<QueryExecutionTree> leftOrRightOp, size_t inputCol,
bool isLeft) const;

virtual std::span<const std::shared_ptr<QueryExecutionTree>>
alternativeSubtrees() const {
return {};
}
};
2 changes: 1 addition & 1 deletion src/engine/TransitivePathBinSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TransitivePathBinSearch::TransitivePathBinSearch(
std::move(rightSide), minDist, maxDist) {
auto [startSide, targetSide] = decideDirection();
alternativelySortedSubtree_ = QueryExecutionTree::createSortedTree(
subtree_, {targetSide.subCol_, targetSide.subCol_});
subtree_, {targetSide.subCol_, startSide.subCol_});
subtree_ = QueryExecutionTree::createSortedTree(
subtree_, {startSide.subCol_, targetSide.subCol_});
}
Expand Down
10 changes: 4 additions & 6 deletions src/engine/TransitivePathBinSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,17 @@ class TransitivePathBinSearch : public TransitivePathImpl<BinSearchMap> {
TransitivePathSide rightSide, size_t minDist,
size_t maxDist);


std::vector<ColumnIndex> resultSortedOn() const override;

// TODO<joka921> Overwrite s.t. we can do this with the alternative subtree.
virtual std::shared_ptr<TransitivePathBase> bindLeftOrRightSide(
std::shared_ptr<QueryExecutionTree> leftOrRightOp, size_t inputCol,
bool isLeft) const;

private:
// initialize the map from the subresult
BinSearchMap setupEdgesMap(
const IdTable& dynSub, const TransitivePathSide& startSide,
const TransitivePathSide& targetSide) const override;

std::shared_ptr<QueryExecutionTree> alternativelySortedSubtree_;
std::span<const std::shared_ptr<QueryExecutionTree>> alternativeSubtrees()
const override {
return {&alternativelySortedSubtree_, 1};
}
};
10 changes: 5 additions & 5 deletions test/QueryPlannerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,8 @@ TEST(QueryPlanner, TransitivePathBindLeft) {

TEST(QueryPlanner, TransitivePathBindRight) {
auto scan = h::IndexScanFromStrings;
TransitivePathSide left{std::nullopt, 0, Variable("?x"), 0};
TransitivePathSide right{std::nullopt, 1, Variable("?y"), 1};
TransitivePathSide left{std::nullopt, 1, Variable("?x"), 0};
TransitivePathSide right{std::nullopt, 0, Variable("?y"), 1};
h::expect(
"SELECT ?x ?y WHERE {"
"?x <p>* ?y."
Expand All @@ -766,9 +766,9 @@ TEST(QueryPlanner, TransitivePathBindRight) {
left, right, 0, std::numeric_limits<size_t>::max(),
scan("?y", "<p>", "<o>"),
scan("?_qlever_internal_variable_query_planner_0", "<p>",
"?_qlever_internal_variable_query_planner_1")),
ad_utility::testing::getQec("<x> <p> <o>. <x2> <p> <o2>")
);
"?_qlever_internal_variable_query_planner_1",
{Permutation::POS})),
ad_utility::testing::getQec("<x> <p> <o>. <x2> <p> <o2>"));
}

// __________________________________________________________________________
Expand Down

0 comments on commit 6a52ae5

Please sign in to comment.