Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Mar 17, 2023
1 parent 9c3b368 commit 38abd23
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/include/planner/subplans_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace kuzu {
namespace planner {

const uint64_t MAX_LEVEL_TO_PLAN_EXACTLY = 7;
const uint64_t MAX_NUM_SUBGRAPHS_PER_LEVEL = 100;
const uint64_t MAX_NUM_SUBGRAPHS_PER_LEVEL = 50;
const uint64_t MAX_NUM_PLANS_PER_SUBGRAPH = 50;

class SubPlansTable {
Expand Down
1 change: 0 additions & 1 deletion src/planner/join_order_enumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ std::vector<std::unique_ptr<LogicalPlan>> JoinOrderEnumerator::enumerate(
while (context->currentLevel < context->maxLevel) {
planLevel(context->currentLevel++);
}
auto s = context->getPlans(context->getFullyMatchedSubqueryGraph()).size();
return std::move(context->getPlans(context->getFullyMatchedSubqueryGraph()));
}

Expand Down
3 changes: 2 additions & 1 deletion src/planner/subplans_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void SubPlansTable::clear() {
}

void SubPlansTable::PlanSet::addPlan(std::unique_ptr<LogicalPlan> plan) {
if (plans.size() > MAX_NUM_PLANS_PER_SUBGRAPH) {
if (plans.size() >= MAX_NUM_PLANS_PER_SUBGRAPH) {
return;
}
auto schema = plan->getSchema();
Expand All @@ -58,6 +58,7 @@ void SubPlansTable::PlanSet::addPlan(std::unique_ptr<LogicalPlan> plan) {
plans.push_back(std::move(plan));
} else { // swap plan for lower cost under the same factorization schema
auto idx = schemaToPlanIdx.at(schema);
assert(idx < MAX_NUM_PLANS_PER_SUBGRAPH);
auto currentPlan = plans[idx].get();
if (currentPlan->getCost() > plan->getCost()) {
plans[idx] = std::move(plan);
Expand Down
17 changes: 10 additions & 7 deletions src/processor/mapper/map_intersect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace processor {
std::unique_ptr<PhysicalOperator> PlanMapper::mapLogicalIntersectToPhysical(
LogicalOperator* logicalOperator) {
auto logicalIntersect = (LogicalIntersect*)logicalOperator;
auto intersectNodeID = logicalIntersect->getIntersectNodeID();
auto outSchema = logicalIntersect->getSchema();
std::vector<std::unique_ptr<PhysicalOperator>> children;
children.resize(logicalOperator->getNumChildren());
Expand All @@ -22,17 +23,19 @@ std::unique_ptr<PhysicalOperator> PlanMapper::mapLogicalIntersectToPhysical(
auto buildSchema = logicalIntersect->getChild(i)->getSchema();
auto buildSidePrevOperator = mapLogicalOperatorToPhysical(logicalIntersect->getChild(i));
std::vector<DataPos> payloadsDataPos;
auto buildDataInfo =
generateBuildDataInfo(*buildSchema, {keyNodeID}, buildSchema->getExpressionsInScope());
for (auto& [dataPos, _] : buildDataInfo.payloadsPosAndType) {
auto expression = buildSchema->getGroup(dataPos.dataChunkPos)
->getExpressions()[dataPos.valueVectorPos];
if (expression->getUniqueName() ==
logicalIntersect->getIntersectNodeID()->getUniqueName()) {
binder::expression_vector expressionsToMaterialize;
expressionsToMaterialize.push_back(keyNodeID);
expressionsToMaterialize.push_back(intersectNodeID);
for (auto& expression : buildSchema->getExpressionsInScope()) {
if (expression->getUniqueName() == keyNodeID->getUniqueName() ||
expression->getUniqueName() == intersectNodeID->getUniqueName()) {
continue;
}
expressionsToMaterialize.push_back(expression);
payloadsDataPos.emplace_back(outSchema->getExpressionPos(*expression));
}
auto buildDataInfo =
generateBuildDataInfo(*buildSchema, {keyNodeID}, expressionsToMaterialize);
auto sharedState = std::make_shared<IntersectSharedState>();
sharedStates.push_back(sharedState);
children[i] = make_unique<IntersectBuild>(
Expand Down
9 changes: 6 additions & 3 deletions src/processor/operator/hash_join/join_hash_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ void JoinHashTable::append(const std::vector<ValueVector*>& vectorsToAppend) {
// TODO(Guodong): use compiling information to remove the for loop.
auto numTuplesToAppend = 1;
for (auto i = 0u; i < numKeyColumns; i++) {
numTuplesToAppend *= (vectorsToAppend[i]->state->isFlat() ?
1 :
vectorsToAppend[i]->state->selVector->selectedSize);
// At most one unFlat key data chunk. If there are multiple unFlat key vectors, they must
// share the same state.
if (!vectorsToAppend[i]->state->isFlat()) {
numTuplesToAppend = vectorsToAppend[i]->state->selVector->selectedSize;
break;
}
}
auto appendInfos = factorizedTable->allocateFlatTupleBlocks(numTuplesToAppend);
for (auto i = 0u; i < vectorsToAppend.size(); i++) {
Expand Down
6 changes: 2 additions & 4 deletions src/processor/operator/intersect/intersect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ void Intersect::initLocalStateInternal(ResultSet* resultSet, ExecutionContext* c
for (auto i = 0u; i < dataInfo.payloadsDataPos.size(); i++) {
auto vector = resultSet->getValueVector(dataInfo.payloadsDataPos[i]);
// Always skip the first two columns in the fTable: build key and intersect key.
// TODO(Guodong): this is a potential bug because you cannot guarantee intersect key is
// the second column. Once this is solved, go back and refactor projection push down for
// intersect.
// TODO(Guodong): this is a bad practice. This assumption requires
columnIdxesToScanFrom.push_back(i + 2);
vectorsToReadInto.push_back(vector.get());
}
Expand Down Expand Up @@ -147,7 +145,7 @@ void Intersect::populatePayloads(
const std::vector<uint8_t*>& tuples, const std::vector<uint32_t>& listIdxes) {
for (auto i = 0u; i < listIdxes.size(); i++) {
auto listIdx = listIdxes[i];
sharedHTs[i]->getHashTable()->getFactorizedTable()->lookup(
sharedHTs[listIdx]->getHashTable()->getFactorizedTable()->lookup(
payloadVectorsToScanInto[listIdx], intersectSelVectors[i].get(),
payloadColumnIdxesToScanFrom[listIdx], tuples[listIdx]);
}
Expand Down
12 changes: 5 additions & 7 deletions test/test_files/tinysnb/cyclic/multi_label.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
---- 1
3

# TODO(Guodong): generic extend sames to give correct output but not getting correct final result
# Also remember to add one with edge filter
#-NAME MultiLabelTriangleTest
#-QUERY MATCH (a:person)-[:knows]->(b:person)-[:studyAt|:mixed]->(c:organisation), (a)-[:studyAt]->(c) RETURN COUNT(*)
#-ENUMERATE
#---- 1
#2
-NAME MultiLabelTriangleTest
-QUERY MATCH (a:person)-[:knows]->(b:person)-[:studyAt|:meets]->(c:organisation:person), (a)-[:studyAt|:meets]->(c) RETURN COUNT(*)
-ENUMERATE
---- 1
4
7 changes: 7 additions & 0 deletions test/test_files/tinysnb/cyclic/single_label.test
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ Dan|1950-05-14|Bob|1950-05-14|Carol|2000-01-01
-ENUMERATE
---- 0

-NAME TriangleTest6
-QUERY MATCH (a:person)-[e1:knows]->(b:person)-[e2:knows]->(c:person), (a)-[e3:knows]->(c) WHERE a.fName='Alice' AND e1.meetTime=timestamp('1986-10-21 21:08:31.521') RETURN b.fName, c.fName
-ENUMERATE
---- 2
Bob|Carol
Bob|Dan

-NAME TriangleWithProjectionTest
-QUERY MATCH (a:person)-[e1:knows]->(b:person)-[e2:studyAt]->(c:organisation), (a)-[e3:studyAt]->(c) RETURN a.fName, e1.date, b.fName, e2.year, c.name, e3.year
-ENUMERATE
Expand Down

0 comments on commit 38abd23

Please sign in to comment.