Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Aug 11, 2023
1 parent 509710b commit 83ef47a
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 148 deletions.
3 changes: 3 additions & 0 deletions src/include/binder/expression/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ struct ExpressionUtil {

static uint32_t find(Expression* target, expression_vector expressions);

// Print as a1,a2,a3,...
static std::string toString(const expression_vector& expressions);
// Print as a1=a2, a3=a4,...
static std::string toString(const std::vector<expression_pair>& expressionPairs);
// Print as a1=a2
static std::string toString(const expression_pair& expressionPair);

static expression_vector excludeExpressions(
Expand Down
9 changes: 5 additions & 4 deletions src/include/planner/logical_plan/logical_hash_join.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class LogicalHashJoin : public LogicalOperator {
std::move(buildSideChild)} {}

// Mark join.
LogicalHashJoin( std::vector<join_condition_t> joinConditions, std::shared_ptr<binder::Expression> mark,
std::shared_ptr<LogicalOperator> probeSideChild,
LogicalHashJoin(std::vector<join_condition_t> joinConditions,
std::shared_ptr<binder::Expression> mark, std::shared_ptr<LogicalOperator> probeSideChild,
std::shared_ptr<LogicalOperator> buildSideChild)
: LogicalHashJoin{std::move(joinConditions), common::JoinType::MARK, std::move(mark),
std::move(probeSideChild), std::move(buildSideChild)} {}

LogicalHashJoin( std::vector<join_condition_t> joinConditions, common::JoinType joinType,
LogicalHashJoin(std::vector<join_condition_t> joinConditions, common::JoinType joinType,
std::shared_ptr<binder::Expression> mark, std::shared_ptr<LogicalOperator> probeSideChild,
std::shared_ptr<LogicalOperator> buildSideChild)
: LogicalOperator{LogicalOperatorType::HASH_JOIN, std::move(probeSideChild),
Expand All @@ -43,7 +43,8 @@ class LogicalHashJoin : public LogicalOperator {
void computeFlatSchema() override;

inline std::string getExpressionsForPrinting() const override {
return isIDBasedJoin() ? binder::ExpressionUtil::toString(getJoinNodeIDs()) : binder::ExpressionUtil::toString(joinConditions);
return isIDBasedJoin() ? binder::ExpressionUtil::toString(getJoinNodeIDs()) :
binder::ExpressionUtil::toString(joinConditions);
}

binder::expression_vector getExpressionsToMaterialize() const;
Expand Down
2 changes: 0 additions & 2 deletions src/include/planner/logical_plan/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ class Schema {

class SchemaUtils {
public:
// static std::vector<binder::expression_vector> getExpressionsPerGroup(
// const binder::expression_vector& expressions, const Schema& schema);
// Given a set of factorization group, a leading group is selected as the unFlat group (caller
// should ensure at most one unFlat group which is our general assumption of factorization). If
// all groups are flat, we select any (the first) group as leading group.
Expand Down
4 changes: 0 additions & 4 deletions src/include/processor/operator/hash_join/hash_join_probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
namespace kuzu {
namespace processor {

enum class ProbeType : uint8_t {

};

struct ProbeState {
explicit ProbeState() : nextMatchedTupleIdx{0} {
matchedTuples = std::make_unique<uint8_t*[]>(common::DEFAULT_VECTOR_CAPACITY);
Expand Down
2 changes: 1 addition & 1 deletion src/include/processor/operator/hash_join/join_hash_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class JoinHashTable : public BaseHashTable {
// given key tuple.
common::sel_t matchFlatKeys(const std::vector<common::ValueVector*>& keyVectors,
uint8_t** probedTuples, uint8_t** matchedTuples);
// Input is multiple tuples, at most one match c
// Input is multiple tuples, at most one match exist for each key.
common::sel_t matchUnFlatKey(common::ValueVector* keyVector, uint8_t** probedTuples,
uint8_t** matchedTuples, common::SelectionVector* matchedTuplesSelVector);

Expand Down
1 change: 0 additions & 1 deletion src/include/processor/operator/intersect/intersect_build.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "intersect_hash_table.h"
#include "processor/operator/hash_join/hash_join_build.h"

namespace kuzu {
Expand Down
18 changes: 0 additions & 18 deletions src/include/processor/operator/intersect/intersect_hash_table.h

This file was deleted.

61 changes: 7 additions & 54 deletions src/optimizer/filter_push_down_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "binder/expression/property_expression.h"
#include "binder/expression_visitor.h"
#include "planner/logical_plan/logical_filter.h"
#include "planner/logical_plan/logical_hash_join.h"
#include "planner/logical_plan/scan/logical_dummy_scan.h"
#include "planner/logical_plan/scan/logical_scan_node.h"
#include "planner/logical_plan/scan/logical_scan_node_property.h"
#include "planner/logical_plan/logical_hash_join.h"

using namespace kuzu::binder;
using namespace kuzu::common;
Expand Down Expand Up @@ -51,36 +51,6 @@ std::shared_ptr<LogicalOperator> FilterPushDownOptimizer::visitFilterReplace(
return visitOperator(filter->getChild(0));
}

// A trivial sub-plan is defined as a plan containing only simple table scan (i.e. SCAN_NODE,
// SCAN_NODE_PROPERTY), FILTER and PROJECTION.
//static bool isTrivialSubPlan(LogicalOperator* root) {
// switch (root->getOperatorType()) {
// case LogicalOperatorType::FILTER:
// case LogicalOperatorType::SCAN_NODE_PROPERTY:
// case LogicalOperatorType::PROJECTION: { // operators we directly search through
// return isTrivialSubPlan(root->getChild(0).get());
// }
// case LogicalOperatorType::SCAN_NODE: {
// return true;
// }
// default:
// return false;
// }
//}
//
//static std::vector<std::shared_ptr<LogicalOperator>> fetchOpsInTrivialSubPlan(
// std::shared_ptr<LogicalOperator> root) {
// std::vector<std::shared_ptr<LogicalOperator>> result;
// auto op = std::move(root);
// while (op->getOperatorType() != LogicalOperatorType::SCAN_NODE) {
// result.push_back(op);
// assert(op->getNumChildren() == 1);
// op = op->getChild(0);
// }
// result.push_back(op);
// return result;
//}

std::shared_ptr<LogicalOperator> FilterPushDownOptimizer::visitCrossProductReplace(
std::shared_ptr<LogicalOperator> op) {
for (auto i = 0u; i < op->getNumChildren(); ++i) {
Expand All @@ -93,40 +63,23 @@ std::shared_ptr<LogicalOperator> FilterPushDownOptimizer::visitCrossProductRepla
for (auto& predicate : predicateSet->equalityPredicates) {
auto left = predicate->getChild(0);
auto right = predicate->getChild(1);
// TODO(Xiyang): this can only rewrite left = right, we should also be able to do expr(left), expr(right)
// TODO(Xiyang): this can only rewrite left = right, we should also be able to do
// expr(left), expr(right)
if (probeSchema->isExpressionInScope(*left) && buildSchema->isExpressionInScope(*right)) {
joinConditions.emplace_back(left, right);
} else if (probeSchema->isExpressionInScope(*right) && buildSchema->isExpressionInScope(*left)) {
} else if (probeSchema->isExpressionInScope(*right) &&
buildSchema->isExpressionInScope(*left)) {
joinConditions.emplace_back(right, left);
}
}
if (joinConditions.empty()) {
return finishPushDown(op);
}
auto hashJoin = std::make_shared<LogicalHashJoin>(joinConditions, JoinType::INNER, op->getChild(0), op->getChild(1));
auto hashJoin = std::make_shared<LogicalHashJoin>(
joinConditions, JoinType::INNER, op->getChild(0), op->getChild(1));
hashJoin->setSIP(planner::SidewaysInfoPassing::PROHIBIT);
hashJoin->computeFlatSchema();
return hashJoin;

// if (!isTrivialSubPlan(op->getChild(1).get())) {
// return finishPushDown(op);
// }
// auto buildOps = fetchOpsInTrivialSubPlan(op->getChild(1));
// auto node = ((LogicalScanNode&)*buildOps[buildOps.size() - 1]).getNode();
// auto primaryKeyEqualityComparison = predicateSet->popNodePKEqualityComparison(*node);
// if (primaryKeyEqualityComparison == nullptr) {
// return finishPushDown(op);
// }
// // Append index scan to left branch
// auto indexScan = make_shared<LogicalIndexScanNode>(
// node, primaryKeyEqualityComparison->getChild(1), op->getChild(0));
// indexScan->computeFlatSchema();
// // Append right branch (except for node table scan) to left branch
// buildOps[buildOps.size() - 2]->setChild(0, std::move(indexScan));
// for (auto i = 0; i < buildOps.size() - 1; ++i) {
// buildOps[i]->computeFlatSchema();
// }
// return buildOps[0];
}

std::shared_ptr<planner::LogicalOperator> FilterPushDownOptimizer::visitScanNodePropertyReplace(
Expand Down
7 changes: 5 additions & 2 deletions src/planner/operator/logical_hash_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void LogicalHashJoin::computeFactorizedSchema() {
if (isKeyGroup) { // merge key group
auto probeKeyGroupPos = buildToProbeKeyGroupPositionMap.at(i);
for (auto& expression : expressions) {
// Join key may repeat for internal ID based joins
schema->insertToGroupAndScopeMayRepeat(expression, probeKeyGroupPos);
}
} else {
Expand Down Expand Up @@ -89,6 +90,7 @@ void LogicalHashJoin::computeFlatSchema() {
case JoinType::INNER:
case JoinType::LEFT: {
for (auto& expression : buildSchema->getExpressionsInScope()) {
// Join key may repeat for internal ID based joins.
schema->insertToGroupAndScopeMayRepeat(expression, 0);
}
} break;
Expand Down Expand Up @@ -116,7 +118,8 @@ binder::expression_vector LogicalHashJoin::getExpressionsToMaterialize() const {

bool LogicalHashJoin::isIDBasedJoin() const {
for (auto& [probeKey, buildKey] : joinConditions) {
if (probeKey->getUniqueName() != buildKey->getUniqueName() || probeKey->getDataType().getLogicalTypeID() != common::LogicalTypeID::INTERNAL_ID) {
if (probeKey->getUniqueName() != buildKey->getUniqueName() ||
probeKey->getDataType().getLogicalTypeID() != common::LogicalTypeID::INTERNAL_ID) {
return false;
}
}
Expand All @@ -139,7 +142,7 @@ bool LogicalHashJoin::requireFlatProbeKeys() {
}
// Flatten for left join.
if (joinType == JoinType::LEFT) {
return true; // TODO(Guodong): fix this. We shouldn't require flatten.
return true; // TODO(Guodong): fix this. We shouldn't require flatten.
}
auto& [probeKey, buildKey] = joinConditions[0];
// Flatten for non-ID-based join.
Expand Down
11 changes: 0 additions & 11 deletions src/planner/operator/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,6 @@ size_t Schema::getNumGroups(bool isFlat) const {
return result;
}

//std::vector<binder::expression_vector> SchemaUtils::getExpressionsPerGroup(
// const binder::expression_vector& expressions, const Schema& schema) {
// std::vector<binder::expression_vector> result;
// result.resize(schema.getNumGroups());
// for (auto& expression : expressions) {
// auto groupPos = schema.getGroupPos(*expression);
// result[groupPos].push_back(expression);
// }
// return result;
//}

f_group_pos SchemaUtils::getLeadingGroupPos(
const std::unordered_set<f_group_pos>& groupPositions, const Schema& schema) {
auto leadingGroupPos = INVALID_F_GROUP_POS;
Expand Down
3 changes: 2 additions & 1 deletion src/processor/map/map_hash_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ std::unique_ptr<PhysicalOperator> PlanMapper::mapHashJoin(LogicalOperator* logic
probeSidePrevOperator = mapOperator(hashJoin->getChild(0).get());
}
auto paramsString = hashJoin->getExpressionsForPrinting();
binder:;expression_vector probeKeys;
binder:;
expression_vector probeKeys;
binder::expression_vector buildKeys;
for (auto& [probeKey, buildKey] : hashJoin->getJoinConditions()) {
probeKeys.push_back(probeKey);
Expand Down
3 changes: 1 addition & 2 deletions src/processor/operator/intersect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
add_library(kuzu_processor_operator_intersect
OBJECT
intersect.cpp
intersect_hash_table.cpp)
intersect.cpp)

set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_processor_operator_intersect>
Expand Down
47 changes: 0 additions & 47 deletions src/processor/operator/intersect/intersect_hash_table.cpp

This file was deleted.

1 change: 0 additions & 1 deletion src/storage/wal/wal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ void WAL::logAddPropertyRecord(table_id_t tableID, property_id_t propertyID) {
}

void WAL::clearWAL() {
bufferManager.clearEvictionQueue();
bufferManager.removeFilePagesFromFrames(*fileHandle);
fileHandle->resetToZeroPagesAndPageCapacity();
initCurrentPage();
Expand Down

0 comments on commit 83ef47a

Please sign in to comment.