This repository was archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 619
Optimizer refactor and cost model additions #1484
Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0acee07
Separate cost model from optimizer and add postgres cost model
fcbf161
Fix bug overflow in Analyze
7f5da31
Changes to cost model construction
e7f6d10
Fix bug in stats hashing
b039b12
Fix to commutativity of equality comparison expressions
7f0cdc1
Revert group equality, this works
5f82942
Move Postgres cost model to header file and add some starting plan te…
5a5b62f
Remove printf
052f5c4
Remove old optimizer constructor
4ee5dad
Fix unused variable
885b37c
Testing if changing llvm path fixes travis
bb0593c
Did not work : (
49ba11a
Ok trying changing to 3.9.1_2
8863bc9
Revert "Fix bug overflow in Analyze"
54b25b0
Update LLVM dir in travis config
4de36ce
Merge remote-tracking branch 'upstream/master'
24814c4
Merge remote-tracking branch 'origin/master' into postgres_cost_model
e67a0f8
Add trivial cost model
363c993
Move files into stats folder
1c4e4b3
Add test cases for trivial cost model
fd51f95
Delete cost.h and cost.cpp that were commented out
dfc9ce2
Cost model name and directory refactoring
fa1aaef
Fix three join test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Peloton | ||
// | ||
// abstract_cost_calculator.h | ||
// | ||
// Identification: src/include/optimizer/abstract_cost_calculator.h | ||
// | ||
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "optimizer/operator_visitor.h" | ||
|
||
namespace peloton { | ||
namespace optimizer { | ||
|
||
class Memo; | ||
|
||
class AbstractCostCalculator : public OperatorVisitor { | ||
public: | ||
virtual double CalculateCost(GroupExpression *gexpr, Memo *memo, | ||
concurrency::TransactionContext *txn) = 0; | ||
}; | ||
|
||
} // namespace optimizer | ||
} // namespace peloton | ||
|
This file contains hidden or 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 hidden or 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,31 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Peloton | ||
// | ||
// cost_calculator_factory.h | ||
// | ||
// Identification: src/include/optimizer/cost_calculator_factory.h | ||
// | ||
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
#include "optimizer/cost_calculator.h" | ||
|
||
#include "common/exception.h" | ||
|
||
namespace peloton { | ||
namespace optimizer { | ||
|
||
class CostCalculatorFactory { | ||
public: | ||
/* | ||
* Creates the respective cost calculator given a cost calculator name | ||
*/ | ||
static std::unique_ptr<AbstractCostCalculator> CreateCostCalculator( | ||
const std::string &cost_model_name); | ||
}; | ||
|
||
} // namespace peloton | ||
} // namespace optimizer |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
// | ||
// Peloton | ||
// | ||
// optimizer.h | ||
// optimizer_metadata.h | ||
// | ||
// Identification: src/include/optimizer/optimizer.h | ||
// Identification: src/include/optimizer/optimizer_metadata.h | ||
// | ||
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group | ||
// | ||
|
@@ -13,6 +13,8 @@ | |
#pragma once | ||
|
||
#include "common/timer.h" | ||
#include "optimizer/cost_calculator.h" | ||
#include "optimizer/cost_calculator_factory.h" | ||
#include "optimizer/memo.h" | ||
#include "optimizer/group_expression.h" | ||
#include "optimizer/rule.h" | ||
|
@@ -35,9 +37,16 @@ class OptimizerMetadata { | |
settings::SettingId::task_execution_timeout)), | ||
timer(Timer<std::milli>()) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarity, do we still need this method here? |
||
|
||
OptimizerMetadata(std::unique_ptr<AbstractCostCalculator> cost_model) | ||
: cost_model(std::move(cost_model)), timeout_limit(settings::SettingsManager::GetInt( | ||
settings::SettingId::task_execution_timeout)), | ||
timer(Timer<std::milli>()) {} | ||
|
||
|
||
Memo memo; | ||
RuleSet rule_set; | ||
OptimizerTaskPool *task_pool; | ||
std::unique_ptr<AbstractCostCalculator> cost_model; | ||
catalog::CatalogCache *catalog_cache; | ||
unsigned int timeout_limit; | ||
Timer<std::milli> timer; | ||
|
This file contains hidden or 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,71 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Peloton | ||
// | ||
// postgres_cost_calculator.h | ||
// | ||
// Identification: src/include/optimizer/postgres_cost_calculator.h | ||
// | ||
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
|
||
#pragma once | ||
|
||
#include "optimizer/abstract_cost_calculator.h" | ||
|
||
// TODO: This is not fully reflective of the postgres cost model. Currently we | ||
// are attempting | ||
// to emulate their hash join cost model | ||
|
||
namespace peloton { | ||
namespace optimizer { | ||
|
||
class Memo; | ||
// Derive cost for a physical group expression | ||
class PostgresCostCalculator : public AbstractCostCalculator { | ||
public: | ||
double CalculateCost(GroupExpression *gexpr, Memo *memo, | ||
concurrency::TransactionContext *txn) override; | ||
|
||
void Visit(const DummyScan *) override; | ||
void Visit(const PhysicalSeqScan *) override; | ||
void Visit(const PhysicalIndexScan *) override; | ||
void Visit(const QueryDerivedScan *) override; | ||
void Visit(const PhysicalOrderBy *) override; | ||
void Visit(const PhysicalLimit *) override; | ||
void Visit(const PhysicalInnerNLJoin *) override; | ||
void Visit(const PhysicalLeftNLJoin *) override; | ||
void Visit(const PhysicalRightNLJoin *) override; | ||
void Visit(const PhysicalOuterNLJoin *) override; | ||
void Visit(const PhysicalInnerHashJoin *) override; | ||
void Visit(const PhysicalLeftHashJoin *) override; | ||
void Visit(const PhysicalRightHashJoin *) override; | ||
void Visit(const PhysicalOuterHashJoin *) override; | ||
void Visit(const PhysicalInsert *) override; | ||
void Visit(const PhysicalInsertSelect *) override; | ||
void Visit(const PhysicalDelete *) override; | ||
void Visit(const PhysicalUpdate *) override; | ||
void Visit(const PhysicalHashGroupBy *) override; | ||
void Visit(const PhysicalSortGroupBy *) override; | ||
void Visit(const PhysicalDistinct *) override; | ||
void Visit(const PhysicalAggregate *) override; | ||
|
||
private: | ||
double HashCost(); | ||
double SortCost(); | ||
double GroupByCost(); | ||
|
||
/* Checks if keys for a join child only reference one table */ | ||
bool IsBaseTable( | ||
const std::vector<std::unique_ptr<expression::AbstractExpression>> &keys); | ||
|
||
GroupExpression *gexpr_; | ||
Memo *memo_; | ||
concurrency::TransactionContext *txn_; | ||
double output_cost_ = 0; | ||
}; | ||
|
||
} // namespace optimizer | ||
} // namespace peloton |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.