1 | #include "duckdb/common/field_writer.hpp" |
2 | #include "duckdb/planner/operator/logical_limit.hpp" |
3 | |
4 | namespace duckdb { |
5 | |
6 | LogicalLimit::LogicalLimit(int64_t limit_val, int64_t offset_val, unique_ptr<Expression> limit, |
7 | unique_ptr<Expression> offset) |
8 | : LogicalOperator(LogicalOperatorType::LOGICAL_LIMIT), limit_val(limit_val), offset_val(offset_val), |
9 | limit(std::move(limit)), offset(std::move(offset)) { |
10 | } |
11 | |
12 | vector<ColumnBinding> LogicalLimit::GetColumnBindings() { |
13 | return children[0]->GetColumnBindings(); |
14 | } |
15 | |
16 | idx_t LogicalLimit::EstimateCardinality(ClientContext &context) { |
17 | auto child_cardinality = children[0]->EstimateCardinality(context); |
18 | if (limit_val >= 0 && idx_t(limit_val) < child_cardinality) { |
19 | child_cardinality = limit_val; |
20 | } |
21 | return child_cardinality; |
22 | } |
23 | |
24 | void LogicalLimit::ResolveTypes() { |
25 | types = children[0]->types; |
26 | } |
27 | |
28 | void LogicalLimit::Serialize(FieldWriter &writer) const { |
29 | writer.WriteField(element: limit_val); |
30 | writer.WriteField(element: offset_val); |
31 | writer.WriteOptional(element: limit); |
32 | writer.WriteOptional(element: offset); |
33 | } |
34 | |
35 | unique_ptr<LogicalOperator> LogicalLimit::Deserialize(LogicalDeserializationState &state, FieldReader &reader) { |
36 | auto limit_val = reader.ReadRequired<int64_t>(); |
37 | auto offset_val = reader.ReadRequired<int64_t>(); |
38 | auto limit = reader.ReadOptional<Expression>(default_value: nullptr, args&: state.gstate); |
39 | auto offset = reader.ReadOptional<Expression>(default_value: nullptr, args&: state.gstate); |
40 | return make_uniq<LogicalLimit>(args&: limit_val, args&: offset_val, args: std::move(limit), args: std::move(offset)); |
41 | } |
42 | |
43 | } // namespace duckdb |
44 | |