-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve cardinality estimation and cost model
- Loading branch information
1 parent
98a3349
commit 4792ec3
Showing
18 changed files
with
367 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "binder/query/reading_clause/query_graph.h" | ||
#include "planner/logical_plan/logical_plan.h" | ||
#include "storage/store/nodes_statistics_and_deleted_ids.h" | ||
#include "storage/store/rels_statistics.h" | ||
|
||
namespace kuzu { | ||
namespace planner { | ||
|
||
class CardinalityEstimator { | ||
public: | ||
CardinalityEstimator(const storage::NodesStatisticsAndDeletedIDs& nodesStatistics, | ||
const storage::RelsStatistics& relsStatistics) | ||
: nodesStatistics{nodesStatistics}, relsStatistics{relsStatistics} {} | ||
|
||
void initNodeIDDom(binder::QueryGraph* queryGraph); | ||
|
||
uint64_t estimateScanNode(LogicalOperator* op); | ||
uint64_t estimateHashJoin(const binder::expression_vector& joinNodeIDs, | ||
const LogicalPlan& probePlan, const LogicalPlan& buildPlan); | ||
uint64_t estimateCrossProduct(const LogicalPlan& probePlan, const LogicalPlan& buildPlan); | ||
uint64_t estimateIntersect(const binder::expression_vector& joinNodeIDs, | ||
const LogicalPlan& probePlan, const std::vector<std::unique_ptr<LogicalPlan>>& buildPlans); | ||
uint64_t estimateFlatten(const LogicalPlan& childPlan, f_group_pos groupPosToFlatten); | ||
uint64_t estimateFilter(const LogicalPlan& childPlan, const binder::Expression& predicate); | ||
|
||
double getExtensionRate( | ||
const binder::RelExpression& rel, const binder::NodeExpression& boundNode); | ||
|
||
private: | ||
inline uint64_t atLeastOne(uint64_t x) { return x == 0 ? 1 : x; } | ||
|
||
uint64_t getNodeIDDom(const std::string& nodeIDName) { | ||
assert(nodeIDName2dom.contains(nodeIDName)); | ||
return nodeIDName2dom.at(nodeIDName); | ||
} | ||
uint64_t getNumNodes(const binder::NodeExpression& node); | ||
|
||
uint64_t getNumRels(const binder::RelExpression& rel); | ||
|
||
private: | ||
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics; | ||
const storage::RelsStatistics& relsStatistics; | ||
// The domain of nodeID is defined as the number of unique value of nodeID, i.e. num nodes. | ||
std::unordered_map<std::string, uint64_t> nodeIDName2dom; | ||
}; | ||
|
||
} // namespace planner | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "planner/logical_plan/logical_plan.h" | ||
|
||
namespace kuzu { | ||
namespace planner { | ||
|
||
class CostModel { | ||
public: | ||
static uint64_t computeExtendCost(const LogicalPlan& childPlan); | ||
static uint64_t computeHashJoinCost(const binder::expression_vector& joinNodeIDs, | ||
const LogicalPlan& probe, const LogicalPlan& build); | ||
static uint64_t computeMarkJoinCost(const binder::expression_vector& joinNodeIDs, | ||
const LogicalPlan& probe, const LogicalPlan& build); | ||
static uint64_t computeIntersectCost( | ||
const LogicalPlan& probePlan, const std::vector<std::unique_ptr<LogicalPlan>>& buildPlans); | ||
}; | ||
|
||
} // namespace planner | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
add_subdirectory(join_order) | ||
add_subdirectory(operator) | ||
|
||
add_library(kuzu_planner | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
add_library(kuzu_planner_join_order | ||
OBJECT | ||
cardinality_estimator.cpp | ||
cost_model.cpp) | ||
|
||
set(ALL_OBJECT_FILES | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_planner_join_order> | ||
PARENT_SCOPE) |
Oops, something went wrong.