Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yangzq50 committed Dec 13, 2024
1 parent c58561b commit 29cdf89
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/executor/operator/physical_merge_limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ namespace infinity {

PhysicalMergeLimit::PhysicalMergeLimit(u64 id,
UniquePtr<PhysicalOperator> left,
SharedPtr<BaseTableRef> base_table_ref,
SharedPtr<BaseExpression> limit_expr,
SharedPtr<BaseExpression> offset_expr,
SharedPtr<Vector<LoadMeta>> load_metas)
: PhysicalOperator(PhysicalOperatorType::kMergeLimit, std::move(left), nullptr, id, load_metas), limit_expr_(std::move(limit_expr)),
offset_expr_(std::move(offset_expr)) {
: PhysicalOperator(PhysicalOperatorType::kMergeLimit, std::move(left), nullptr, id, std::move(load_metas)),
base_table_ref_(std::move(base_table_ref)), limit_expr_(std::move(limit_expr)), offset_expr_(std::move(offset_expr)) {
i64 offset = 0;
i64 limit = (static_pointer_cast<ValueExpression>(limit_expr_))->GetValue().value_.big_int;

Expand Down
7 changes: 7 additions & 0 deletions src/executor/operator/physical_merge_limit.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ import infinity_exception;
import internal_types;
import data_type;
import logger;
import base_table_ref;

namespace infinity {

export class PhysicalMergeLimit final : public PhysicalOperator {
public:
explicit PhysicalMergeLimit(u64 id,
UniquePtr<PhysicalOperator> left,
SharedPtr<BaseTableRef> base_table_ref,
SharedPtr<BaseExpression> limit_expr,
SharedPtr<BaseExpression> offset_expr,
SharedPtr<Vector<LoadMeta>> load_metas);
Expand All @@ -56,7 +58,12 @@ public:
return 0;
}

void FillingTableRefs(HashMap<SizeT, SharedPtr<BaseTableRef>> &table_refs) override {
table_refs.insert({base_table_ref_->table_index_, base_table_ref_});
}

private:
SharedPtr<BaseTableRef> base_table_ref_;
SharedPtr<BaseExpression> limit_expr_{};
SharedPtr<BaseExpression> offset_expr_{};

Expand Down
5 changes: 3 additions & 2 deletions src/executor/physical_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ void PhysicalOperator::InputLoad(QueryContext *query_context, OperatorState *ope

auto load_metas = *load_metas_.get();
// FIXME: After columnar reading is supported, use a different table_ref for each LoadMetas
auto table_ref = table_refs[load_metas[0].binding_.table_idx];
if (table_ref.get() == nullptr) {
const auto table_refs_it = table_refs.find(load_metas[0].binding_.table_idx);
if (table_refs_it == table_refs.end()) {
UnrecoverableError("TableRef not found");
}
const auto *table_ref = table_refs_it->second.get();

OutputToDataBlockHelper output_to_data_block_helper;
for (SizeT i = 0; i < operator_state->prev_op_state_->data_block_array_.size(); ++i) {
Expand Down
1 change: 1 addition & 0 deletions src/executor/physical_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ UniquePtr<PhysicalOperator> PhysicalPlanner::BuildLimit(const SharedPtr<LogicalN
logical_limit->total_hits_count_flag_);
return MakeUnique<PhysicalMergeLimit>(query_context_ptr_->GetNextNodeID(),
std::move(child_limit_op),
logical_limit->base_table_ref_,
logical_limit->limit_expression_,
logical_limit->offset_expression_,
MakeShared<Vector<LoadMeta>>());
Expand Down
4 changes: 2 additions & 2 deletions src/planner/bound_select_statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ SharedPtr<LogicalNode> BoundSelectStatement::BuildPlan(QueryContext *query_conte
root = top;
}
} else if (limit_expression_.get() != nullptr) {
auto limit = MakeShared<LogicalLimit>(bind_context->GetNewLogicalNodeId(), limit_expression_, offset_expression_, total_hits_count_flag_);
auto limit = MakeShared<LogicalLimit>(bind_context->GetNewLogicalNodeId(), std::static_pointer_cast<BaseTableRef>(table_ref_ptr_), limit_expression_, offset_expression_, total_hits_count_flag_);
limit->set_left_node(root);
root = limit;
}
Expand Down Expand Up @@ -389,7 +389,7 @@ SharedPtr<LogicalNode> BoundSelectStatement::BuildPlan(QueryContext *query_conte
}

if (limit_expression_.get() != nullptr) {
auto limit = MakeShared<LogicalLimit>(bind_context->GetNewLogicalNodeId(), limit_expression_, offset_expression_, total_hits_count_flag_);
auto limit = MakeShared<LogicalLimit>(bind_context->GetNewLogicalNodeId(), base_table_ref, limit_expression_, offset_expression_, total_hits_count_flag_);
limit->set_left_node(root);
root = limit;
}
Expand Down
8 changes: 6 additions & 2 deletions src/planner/node/logical_limit.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ import logical_node;
import data_type;
import base_expression;
import internal_types;
import base_table_ref;

namespace infinity {

export class LogicalLimit : public LogicalNode {
public:
inline explicit LogicalLimit(u64 node_id,
SharedPtr<BaseTableRef> base_table_ref,
SharedPtr<BaseExpression> limit_expression,
SharedPtr<BaseExpression> offset_expression,
bool total_hits_count_flag)
: LogicalNode(node_id, LogicalNodeType::kLimit), limit_expression_(std::move(limit_expression)),
offset_expression_(std::move(offset_expression)), total_hits_count_flag_(total_hits_count_flag) {}
: LogicalNode(node_id, LogicalNodeType::kLimit), base_table_ref_(std::move(base_table_ref)),
limit_expression_(std::move(limit_expression)), offset_expression_(std::move(offset_expression)),
total_hits_count_flag_(total_hits_count_flag) {}

[[nodiscard]] Vector<ColumnBinding> GetColumnBindings() const final;

Expand All @@ -45,6 +48,7 @@ public:

inline String name() final { return "LogicalLimit"; }

SharedPtr<BaseTableRef> base_table_ref_{};
SharedPtr<BaseExpression> limit_expression_{};
SharedPtr<BaseExpression> offset_expression_{};

Expand Down

0 comments on commit 29cdf89

Please sign in to comment.