-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce physical plan and add switch #4820
Merged
ti-chi-bot
merged 24 commits into
pingcap:planner_refactory
from
SeaRise:introduce_physical_plan_add_switch
Jun 13, 2022
Merged
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d987c89
introd physical plan
SeaRise e24489a
add source
SeaRise 99c6a74
fix
SeaRise c6363c8
fix
SeaRise bb44d1f
fix
SeaRise c51c152
add optimize
SeaRise a5647fd
format
SeaRise 39cc3ec
license
SeaRise 3960244
plan type
SeaRise 9b86c41
u
SeaRise 4bde83b
license check
SeaRise 4137c52
Merge branch 'planner_refactory' into introduce_physical_plan_add_switch
SeaRise 328e18f
Merge branch 'introduce_physical_plan_add_switch' of https://github.c…
SeaRise e6d0a43
Merge branch 'planner_refactory' into introduce_physical_plan_add_switch
SeaRise 2fc02b7
add tests
SeaRise 6a91f86
f
SeaRise dcaa84a
Errors::Planner
SeaRise 8ac8ce4
Merge branch 'planner_refactory' into introduce_physical_plan_add_switch
SeaRise 64b6d2c
add tests and test
SeaRise ca45abf
add parallel tests
SeaRise 5a95ca0
fix
SeaRise 6f9dc61
format
SeaRise edf26bc
address comment
SeaRise d31b310
address comments
SeaRise 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 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2022 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <Common/FmtUtils.h> | ||
#include <Flash/Coprocessor/DAGContext.h> | ||
#include <Flash/Coprocessor/DAGPipeline.h> | ||
#include <Flash/Planner/PhysicalPlan.h> | ||
#include <Flash/Planner/PhysicalPlanHelper.h> | ||
#include <Interpreters/Context.h> | ||
|
||
namespace DB | ||
{ | ||
PhysicalPlan::PhysicalPlan( | ||
const String & executor_id_, | ||
const PlanType & type_, | ||
const NamesAndTypes & schema_, | ||
const String & req_id) | ||
: executor_id(executor_id_) | ||
, type(type_) | ||
, schema(schema_) | ||
, log(Logger::get(type_.toString(), req_id)) | ||
{} | ||
|
||
String PhysicalPlan::toString() | ||
{ | ||
auto schema_to_string = [&]() { | ||
FmtBuffer buffer; | ||
buffer.joinStr( | ||
schema.cbegin(), | ||
schema.cend(), | ||
[](const auto & item, FmtBuffer & buf) { buf.fmtAppend("<{}, {}>", item.name, item.type->getName()); }, | ||
", "); | ||
return buffer.toString(); | ||
}; | ||
return fmt::format( | ||
"type: {}, executor_id: {}, is_record_profile_streams: {}, schema: {}", | ||
type.toString(), | ||
executor_id, | ||
is_record_profile_streams, | ||
schema_to_string()); | ||
} | ||
|
||
void PhysicalPlan::finalize() | ||
{ | ||
finalize(PhysicalPlanHelper::schemaToNames(schema)); | ||
} | ||
|
||
void PhysicalPlan::recordProfileStreams(DAGPipeline & pipeline, const Context & context) | ||
{ | ||
if (is_record_profile_streams) | ||
{ | ||
auto & profile_streams = context.getDAGContext()->getProfileStreamsMap()[executor_id]; | ||
pipeline.transform([&profile_streams](auto & stream) { profile_streams.push_back(stream); }); | ||
} | ||
} | ||
|
||
void PhysicalPlan::transform(DAGPipeline & pipeline, Context & context, size_t max_streams) | ||
{ | ||
transformImpl(pipeline, context, max_streams); | ||
recordProfileStreams(pipeline, context); | ||
} | ||
} // namespace DB |
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,83 @@ | ||
// Copyright 2022 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Common/Logger.h> | ||
#include <Core/Block.h> | ||
#include <Core/Names.h> | ||
#include <Core/NamesAndTypes.h> | ||
#include <Flash/Planner/PlanType.h> | ||
|
||
#include <memory> | ||
|
||
namespace DB | ||
{ | ||
struct DAGPipeline; | ||
class Context; | ||
class DAGContext; | ||
|
||
class PhysicalPlan; | ||
using PhysicalPlanPtr = std::shared_ptr<PhysicalPlan>; | ||
|
||
class PhysicalPlan | ||
{ | ||
public: | ||
PhysicalPlan( | ||
const String & executor_id_, | ||
const PlanType & type_, | ||
const NamesAndTypes & schema_, | ||
const String & req_id); | ||
|
||
virtual ~PhysicalPlan() = default; | ||
|
||
virtual PhysicalPlanPtr children(size_t /*i*/) const = 0; | ||
|
||
virtual void setChild(size_t /*i*/, const PhysicalPlanPtr & /*new_child*/) = 0; | ||
|
||
const PlanType & tp() const { return type; } | ||
|
||
const String & execId() const { return executor_id; } | ||
|
||
const NamesAndTypes & getSchema() const { return schema; } | ||
|
||
virtual void appendChild(const PhysicalPlanPtr & /*new_child*/) = 0; | ||
|
||
virtual size_t childrenSize() const = 0; | ||
|
||
virtual void transform(DAGPipeline & pipeline, Context & context, size_t max_streams); | ||
|
||
virtual void finalize(const Names & parent_require) = 0; | ||
void finalize(); | ||
|
||
/// Obtain a sample block that contains the names and types of result columns. | ||
virtual const Block & getSampleBlock() const = 0; | ||
|
||
void disableRecordProfileStreams() { is_record_profile_streams = false; } | ||
|
||
String toString(); | ||
|
||
protected: | ||
virtual void transformImpl(DAGPipeline & /*pipeline*/, Context & /*context*/, size_t /*max_streams*/){}; | ||
|
||
void recordProfileStreams(DAGPipeline & pipeline, const Context & context); | ||
|
||
String executor_id; | ||
PlanType type; | ||
NamesAndTypes schema; | ||
bool is_record_profile_streams = true; | ||
|
||
LoggerPtr log; | ||
}; | ||
} // namespace DB |
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,24 @@ | ||
// Copyright 2022 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <Flash/Planner/PhysicalPlanBuilder.h> | ||
ywqzzy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include <Flash/Planner/plans/PhysicalSource.h> | ||
|
||
namespace DB | ||
{ | ||
void PhysicalPlanBuilder::buildSource(const Block & sample_block) | ||
{ | ||
cur_plans.push_back(PhysicalSource::build(sample_block, log->identifier())); | ||
} | ||
} // namespace DB |
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,47 @@ | ||
// Copyright 2022 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Common/Exception.h> | ||
#include <Common/Logger.h> | ||
#include <Flash/Planner/PhysicalPlan.h> | ||
#include <common/logger_useful.h> | ||
|
||
namespace DB | ||
{ | ||
class PhysicalPlanBuilder | ||
{ | ||
public: | ||
explicit PhysicalPlanBuilder(Context & context_, const String & req_id) | ||
: context(context_) | ||
, log(Logger::get("PhysicalPlanBuilder", req_id)) | ||
{} | ||
|
||
void buildSource(const Block & sample_block); | ||
|
||
PhysicalPlanPtr getResult() const | ||
{ | ||
RUNTIME_ASSERT(cur_plans.size() == 1, log, "There can only be one plan output, but here are {}", cur_plans.size()); | ||
return cur_plans.back(); | ||
} | ||
|
||
private: | ||
std::vector<PhysicalPlanPtr> cur_plans; | ||
|
||
[[maybe_unused]] Context & context; | ||
|
||
LoggerPtr log; | ||
}; | ||
} // namespace DB |
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,27 @@ | ||
// Copyright 2022 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <Flash/Planner/PhysicalPlanHelper.h> | ||
|
||
namespace DB::PhysicalPlanHelper | ||
{ | ||
Names schemaToNames(const NamesAndTypes & schema) | ||
{ | ||
Names names; | ||
names.reserve(schema.size()); | ||
for (const auto & column : schema) | ||
names.push_back(column.name); | ||
return names; | ||
} | ||
} // namespace DB::PhysicalPlanHelper |
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,22 @@ | ||
// Copyright 2022 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Core/NamesAndTypes.h> | ||
|
||
namespace DB::PhysicalPlanHelper | ||
{ | ||
Names schemaToNames(const NamesAndTypes & schema); | ||
} // namespace DB::PhysicalPlanHelper |
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,30 @@ | ||
// Copyright 2022 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <Common/TiFlashException.h> | ||
#include <Flash/Planner/PlanType.h> | ||
|
||
namespace DB | ||
{ | ||
String PlanType::toString() const | ||
{ | ||
switch (enum_value) | ||
{ | ||
case Source: | ||
return "Source"; | ||
default: | ||
throw TiFlashException("Unknown PlanType", Errors::Planner::Internal); | ||
} | ||
} | ||
} // namespace DB |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified for license checker.
I'll revert it to
master
at the last pr