diff --git a/benchmark/tpch/lineitem_aggregate.cpp b/benchmark/tpch/lineitem_aggregate.cpp index bb59a0029a2..769d408e588 100644 --- a/benchmark/tpch/lineitem_aggregate.cpp +++ b/benchmark/tpch/lineitem_aggregate.cpp @@ -71,7 +71,11 @@ void Load(DuckDBBenchmarkState *state) override { tpch::dbgen(SF, state->db); } string GetQuery() override { - return "SELECT l_returnflag, l_linestatus, sum(l_quantity) AS sum_qty, sum(l_extendedprice) AS sum_base_price, sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge, avg(l_quantity) AS avg_qty, avg(l_extendedprice) AS avg_price, avg(l_discount) AS avg_disc, count(*) AS count_order FROM lineitem, orders WHERE l_orderkey=o_orderkey GROUP BY l_returnflag, l_linestatus ORDER BY l_returnflag, l_linestatus"; + return "SELECT l_returnflag, l_linestatus, sum(l_quantity) AS sum_qty, sum(l_extendedprice) AS sum_base_price, " + "sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + " + "l_tax)) AS sum_charge, avg(l_quantity) AS avg_qty, avg(l_extendedprice) AS avg_price, avg(l_discount) AS " + "avg_disc, count(*) AS count_order FROM lineitem, orders WHERE l_orderkey=o_orderkey GROUP BY l_returnflag, " + "l_linestatus ORDER BY l_returnflag, l_linestatus"; } string VerifyResult(QueryResult *result) override { if (!result->success) { @@ -90,7 +94,11 @@ void Load(DuckDBBenchmarkState *state) override { tpch::dbgen(SF, state->db); } string GetQuery() override { - return "SELECT l_returnflag, l_linestatus, sum(l_quantity) AS sum_qty, sum(l_extendedprice) AS sum_base_price, sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge, avg(l_quantity) AS avg_qty, avg(l_extendedprice) AS avg_price, avg(l_discount) AS avg_disc, count(*) AS count_order FROM lineitem, orders WHERE l_orderkey=o_orderkey AND l_shipdate <= cast('1998-09-02' AS date) GROUP BY l_returnflag, l_linestatus ORDER BY l_returnflag, l_linestatus"; + return "SELECT l_returnflag, l_linestatus, sum(l_quantity) AS sum_qty, sum(l_extendedprice) AS sum_base_price, " + "sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + " + "l_tax)) AS sum_charge, avg(l_quantity) AS avg_qty, avg(l_extendedprice) AS avg_price, avg(l_discount) AS " + "avg_disc, count(*) AS count_order FROM lineitem, orders WHERE l_orderkey=o_orderkey AND l_shipdate <= " + "cast('1998-09-02' AS date) GROUP BY l_returnflag, l_linestatus ORDER BY l_returnflag, l_linestatus"; } string VerifyResult(QueryResult *result) override { if (!result->success) { diff --git a/src/execution/column_binding_resolver.cpp b/src/execution/column_binding_resolver.cpp index 7de1e6b6402..b8be91744fc 100644 --- a/src/execution/column_binding_resolver.cpp +++ b/src/execution/column_binding_resolver.cpp @@ -18,7 +18,7 @@ ColumnBindingResolver::ColumnBindingResolver() { void ColumnBindingResolver::VisitOperator(LogicalOperator &op) { if (op.type == LogicalOperatorType::COMPARISON_JOIN || op.type == LogicalOperatorType::DELIM_JOIN) { // special case: comparison join - auto &comp_join = (LogicalComparisonJoin&) op; + auto &comp_join = (LogicalComparisonJoin &)op; // first get the bindings of the LHS and resolve the LHS expressions VisitOperator(*comp_join.children[0]); for (auto &cond : comp_join.conditions) { @@ -40,8 +40,9 @@ void ColumnBindingResolver::VisitOperator(LogicalOperator &op) { bindings = op.GetColumnBindings(); return; } else if (op.type == LogicalOperatorType::ANY_JOIN) { - // ANY join, this join is different because we evaluate the expression on the bindings of BOTH join sides at once - // i.e. we set the bindings first to the bindings of the entire join, and then resolve the expressions of this operator + // ANY join, this join is different because we evaluate the expression on the bindings of BOTH join sides at + // once i.e. we set the bindings first to the bindings of the entire join, and then resolve the expressions of + // this operator VisitOperatorChildren(op); bindings = op.GetColumnBindings(); VisitOperatorExpressions(op); @@ -49,7 +50,7 @@ void ColumnBindingResolver::VisitOperator(LogicalOperator &op) { } else if (op.type == LogicalOperatorType::CREATE_INDEX) { // CREATE INDEX statement, add the columns of the table with table index 0 to the binding set // afterwards bind the expressions of the CREATE INDEX statement - auto &create_index = (LogicalCreateIndex&) op; + auto &create_index = (LogicalCreateIndex &)op; bindings = LogicalOperator::GenerateColumnBindings(0, create_index.table.columns.size()); VisitOperatorExpressions(op); return; @@ -67,15 +68,15 @@ unique_ptr ColumnBindingResolver::VisitReplace(BoundColumnRefExpress unique_ptr *expr_ptr) { assert(expr.depth == 0); // check the current set of column bindings to see which index corresponds to the column reference - for(index_t i = 0; i < bindings.size(); i++) { + for (index_t i = 0; i < bindings.size(); i++) { if (expr.binding == bindings[i]) { return make_unique(expr.alias, expr.return_type, i); } } // could not bind the column reference, this should never happen and indicates a bug in the code // generate an error message - string bound_columns = "["; - for(index_t i = 0; i < bindings.size(); i++) { + string bound_columns = "["; + for (index_t i = 0; i < bindings.size(); i++) { if (i != 0) { bound_columns += " "; } @@ -83,5 +84,6 @@ unique_ptr ColumnBindingResolver::VisitReplace(BoundColumnRefExpress } bound_columns += "]"; - throw InternalException("Failed to bind column reference \"%s\" [%d.%d] (bindings: %s)", expr.alias.c_str(), (int) expr.binding.table_index, (int) expr.binding.column_index, bound_columns.c_str()); + throw InternalException("Failed to bind column reference \"%s\" [%d.%d] (bindings: %s)", expr.alias.c_str(), + (int)expr.binding.table_index, (int)expr.binding.column_index, bound_columns.c_str()); } diff --git a/src/execution/operator/filter/physical_filter.cpp b/src/execution/operator/filter/physical_filter.cpp index 86f36d0f6a8..109e251904d 100644 --- a/src/execution/operator/filter/physical_filter.cpp +++ b/src/execution/operator/filter/physical_filter.cpp @@ -26,7 +26,6 @@ PhysicalFilter::PhysicalFilter(vector types, vectorexecutor.SelectExpression(chunk, chunk.owned_sel_vector); - } while(result_count == 0); + } while (result_count == 0); if (result_count == initial_count) { // nothing was filtered: skip adding any selection vectors diff --git a/src/execution/operator/join/physical_hash_join.cpp b/src/execution/operator/join/physical_hash_join.cpp index df8979f5f8c..a8422c344dd 100644 --- a/src/execution/operator/join/physical_hash_join.cpp +++ b/src/execution/operator/join/physical_hash_join.cpp @@ -23,20 +23,22 @@ class PhysicalHashJoinState : public PhysicalComparisonJoinState { PhysicalHashJoin::PhysicalHashJoin(ClientContext &context, LogicalOperator &op, unique_ptr left, unique_ptr right, vector cond, JoinType join_type, - vector left_projection_map, vector right_projection_map) - : PhysicalComparisonJoin(op, PhysicalOperatorType::HASH_JOIN, move(cond), join_type), right_projection_map(right_projection_map) { + vector left_projection_map, vector right_projection_map) + : PhysicalComparisonJoin(op, PhysicalOperatorType::HASH_JOIN, move(cond), join_type), + right_projection_map(right_projection_map) { children.push_back(move(left)); children.push_back(move(right)); assert(left_projection_map.size() == 0); hash_table = - make_unique(*context.db.storage->buffer_manager, conditions, LogicalOperator::MapTypes(children[1]->GetTypes(), right_projection_map), type); + make_unique(*context.db.storage->buffer_manager, conditions, + LogicalOperator::MapTypes(children[1]->GetTypes(), right_projection_map), type); } PhysicalHashJoin::PhysicalHashJoin(ClientContext &context, LogicalOperator &op, unique_ptr left, - unique_ptr right, vector cond, JoinType join_type) : - PhysicalHashJoin(context, op, move(left), move(right), move(cond), join_type, {}, {}) { + unique_ptr right, vector cond, JoinType join_type) + : PhysicalHashJoin(context, op, move(left), move(right), move(cond), join_type, {}, {}) { } void PhysicalHashJoin::BuildHashTable(ClientContext &context, PhysicalOperatorState *state_) { @@ -66,7 +68,7 @@ void PhysicalHashJoin::BuildHashTable(ClientContext &context, PhysicalOperatorSt if (right_projection_map.size() > 0) { // there is a projection map: fill the build chunk with the projected columns build_chunk.Reset(); - for(index_t i = 0; i < right_projection_map.size(); i++) { + for (index_t i = 0; i < right_projection_map.size(); i++) { build_chunk.data[i].Reference(right_chunk.data[right_projection_map[i]]); } build_chunk.sel_vector = right_chunk.sel_vector; diff --git a/src/execution/physical_plan/plan_comparison_join.cpp b/src/execution/physical_plan/plan_comparison_join.cpp index f6210194e40..86df9277688 100644 --- a/src/execution/physical_plan/plan_comparison_join.cpp +++ b/src/execution/physical_plan/plan_comparison_join.cpp @@ -39,12 +39,15 @@ unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalComparison unique_ptr plan; if (has_equality) { // equality join: use hash join - plan = make_unique(context, op, move(left), move(right), move(op.conditions), op.join_type, op.left_projection_map, op.right_projection_map); + plan = make_unique(context, op, move(left), move(right), move(op.conditions), op.join_type, + op.left_projection_map, op.right_projection_map); } else { assert(!has_null_equal_conditions); // don't support this for anything but hash joins for now - if (op.conditions.size() == 1 && (op.join_type == JoinType::MARK || op.join_type == JoinType::INNER) && !has_inequality) { + if (op.conditions.size() == 1 && (op.join_type == JoinType::MARK || op.join_type == JoinType::INNER) && + !has_inequality) { // range join: use piecewise merge join - plan = make_unique(op, move(left), move(right), move(op.conditions), op.join_type); + plan = + make_unique(op, move(left), move(right), move(op.conditions), op.join_type); } else { // inequality join: use nested loop plan = make_unique(op, move(left), move(right), move(op.conditions), op.join_type); diff --git a/src/execution/physical_plan/plan_filter.cpp b/src/execution/physical_plan/plan_filter.cpp index 6b5c073c2f9..66b39ab4f37 100644 --- a/src/execution/physical_plan/plan_filter.cpp +++ b/src/execution/physical_plan/plan_filter.cpp @@ -21,7 +21,7 @@ unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalFilter &op if (op.projection_map.size() > 0) { // there is a projection map, generate a physical projection vector> select_list; - for(index_t i = 0; i < op.projection_map.size(); i++) { + for (index_t i = 0; i < op.projection_map.size(); i++) { select_list.push_back(make_unique(op.types[i], op.projection_map[i])); } auto proj = make_unique(op.types, move(select_list)); diff --git a/src/include/duckdb/common/exception.hpp b/src/include/duckdb/common/exception.hpp index 628b851a1c2..7e1db687f29 100644 --- a/src/include/duckdb/common/exception.hpp +++ b/src/include/duckdb/common/exception.hpp @@ -55,8 +55,9 @@ enum class ExceptionType { NULL_POINTER = 27, // nullptr exception IO = 28, // IO exception INTERRUPT = 29, // interrupt - FATAL = 30, // Fatal exception: fatal exceptions are non-recoverable, and render the entire DB in an unusable state - INTERNAL = 31 // Internal exception: exception that indicates something went wrong internally (i.e. bug in the code base) + FATAL = 30, // Fatal exception: fatal exceptions are non-recoverable, and render the entire DB in an unusable state + INTERNAL = + 31 // Internal exception: exception that indicates something went wrong internally (i.e. bug in the code base) }; class Exception : public std::exception { diff --git a/src/include/duckdb/execution/column_binding_resolver.hpp b/src/include/duckdb/execution/column_binding_resolver.hpp index c63546918c1..139ab55abc0 100644 --- a/src/include/duckdb/execution/column_binding_resolver.hpp +++ b/src/include/duckdb/execution/column_binding_resolver.hpp @@ -21,6 +21,7 @@ class ColumnBindingResolver : public LogicalOperatorVisitor { ColumnBindingResolver(); void VisitOperator(LogicalOperator &op) override; + protected: vector bindings; diff --git a/src/include/duckdb/execution/operator/filter/physical_filter.hpp b/src/include/duckdb/execution/operator/filter/physical_filter.hpp index 342f27f393c..a7636334cb4 100644 --- a/src/include/duckdb/execution/operator/filter/physical_filter.hpp +++ b/src/include/duckdb/execution/operator/filter/physical_filter.hpp @@ -21,6 +21,7 @@ class PhysicalFilter : public PhysicalOperator { //! The filter expression unique_ptr expression; + public: void GetChunkInternal(ClientContext &context, DataChunk &chunk, PhysicalOperatorState *state) override; diff --git a/src/include/duckdb/execution/operator/join/physical_hash_join.hpp b/src/include/duckdb/execution/operator/join/physical_hash_join.hpp index 8684f49298f..a4921fca612 100644 --- a/src/include/duckdb/execution/operator/join/physical_hash_join.hpp +++ b/src/include/duckdb/execution/operator/join/physical_hash_join.hpp @@ -21,7 +21,7 @@ class PhysicalHashJoin : public PhysicalComparisonJoin { public: PhysicalHashJoin(ClientContext &context, LogicalOperator &op, unique_ptr left, unique_ptr right, vector cond, JoinType join_type, - vector left_projection_map, vector right_projection_map); + vector left_projection_map, vector right_projection_map); PhysicalHashJoin(ClientContext &context, LogicalOperator &op, unique_ptr left, unique_ptr right, vector cond, JoinType join_type); diff --git a/src/include/duckdb/execution/physical_operator.hpp b/src/include/duckdb/execution/physical_operator.hpp index c91b5cce2d1..e2ae36270a6 100644 --- a/src/include/duckdb/execution/physical_operator.hpp +++ b/src/include/duckdb/execution/physical_operator.hpp @@ -61,6 +61,7 @@ class PhysicalOperator { vector> children; //! The types returned by this physical operator vector types; + public: string ToString(index_t depth = 0) const; void Print(); diff --git a/src/include/duckdb/optimizer/column_lifetime_optimizer.hpp b/src/include/duckdb/optimizer/column_lifetime_optimizer.hpp index eaed77fc64d..b7a7f0d1247 100644 --- a/src/include/duckdb/optimizer/column_lifetime_optimizer.hpp +++ b/src/include/duckdb/optimizer/column_lifetime_optimizer.hpp @@ -14,24 +14,31 @@ namespace duckdb { class BoundColumnRefExpression; -//! The ColumnLifetimeAnalyzer optimizer traverses the logical operator tree and ensures that columns are removed from the plan when no longer required +//! The ColumnLifetimeAnalyzer optimizer traverses the logical operator tree and ensures that columns are removed from +//! the plan when no longer required class ColumnLifetimeAnalyzer : public LogicalOperatorVisitor { public: - ColumnLifetimeAnalyzer(bool is_root = false) : everything_referenced(is_root) {} + ColumnLifetimeAnalyzer(bool is_root = false) : everything_referenced(is_root) { + } void VisitOperator(LogicalOperator &op) override; + protected: unique_ptr VisitReplace(BoundColumnRefExpression &expr, unique_ptr *expr_ptr) override; unique_ptr VisitReplace(BoundReferenceExpression &expr, unique_ptr *expr_ptr) override; + private: - //! Whether or not all the columns are referenced. This happens in the case of the root expression (because the output implicitly refers all the columns below it) + //! Whether or not all the columns are referenced. This happens in the case of the root expression (because the + //! output implicitly refers all the columns below it) bool everything_referenced; //! The set of column references column_binding_set_t column_references; + private: void StandardVisitOperator(LogicalOperator &op); void ExtractUnusedColumnBindings(vector bindings, column_binding_set_t &unused_bindings); - void GenerateProjectionMap(vector bindings, column_binding_set_t &unused_bindings, vector &map); + void GenerateProjectionMap(vector bindings, column_binding_set_t &unused_bindings, + vector &map); }; } // namespace duckdb diff --git a/src/include/duckdb/optimizer/remove_unused_columns.hpp b/src/include/duckdb/optimizer/remove_unused_columns.hpp index 34fc1a7742b..69bc1de8be0 100644 --- a/src/include/duckdb/optimizer/remove_unused_columns.hpp +++ b/src/include/duckdb/optimizer/remove_unused_columns.hpp @@ -17,22 +17,27 @@ class BoundColumnRefExpression; //! The RemoveUnusedColumns optimizer traverses the logical operator tree and removes any columns that are not required class RemoveUnusedColumns : public LogicalOperatorVisitor { public: - RemoveUnusedColumns(bool is_root = false) : everything_referenced(is_root) {} + RemoveUnusedColumns(bool is_root = false) : everything_referenced(is_root) { + } void VisitOperator(LogicalOperator &op) override; + protected: unique_ptr VisitReplace(BoundColumnRefExpression &expr, unique_ptr *expr_ptr) override; unique_ptr VisitReplace(BoundReferenceExpression &expr, unique_ptr *expr_ptr) override; + private: - //! Whether or not all the columns are referenced. This happens in the case of the root expression (because the output implicitly refers all the columns below it) + //! Whether or not all the columns are referenced. This happens in the case of the root expression (because the + //! output implicitly refers all the columns below it) bool everything_referenced; //! The map of column references - column_binding_map_t> column_references; + column_binding_map_t> column_references; + private: - template - void ClearUnusedExpressions(vector &list, index_t table_idx); + template void ClearUnusedExpressions(vector &list, index_t table_idx); - //! Perform a replacement of the ColumnBinding, iterating over all the currently found column references and replacing the bindings + //! Perform a replacement of the ColumnBinding, iterating over all the currently found column references and + //! replacing the bindings void ReplaceBinding(ColumnBinding current_binding, ColumnBinding new_binding); }; } // namespace duckdb diff --git a/src/include/duckdb/planner/bound_query_node.hpp b/src/include/duckdb/planner/bound_query_node.hpp index 5e01b3c4485..1e230c77d35 100644 --- a/src/include/duckdb/planner/bound_query_node.hpp +++ b/src/include/duckdb/planner/bound_query_node.hpp @@ -49,6 +49,7 @@ class BoundQueryNode { vector names; //! The types returned by this QueryNode. vector types; + public: virtual index_t GetRootIndex() = 0; }; diff --git a/src/include/duckdb/planner/operator/logical_aggregate.hpp b/src/include/duckdb/planner/operator/logical_aggregate.hpp index 27da22133e4..7ed8325a27e 100644 --- a/src/include/duckdb/planner/operator/logical_aggregate.hpp +++ b/src/include/duckdb/planner/operator/logical_aggregate.hpp @@ -30,6 +30,7 @@ class LogicalAggregate : public LogicalOperator { string ParamsToString() const override; vector GetColumnBindings() override; + protected: void ResolveTypes() override; }; diff --git a/src/include/duckdb/planner/operator/logical_chunk_get.hpp b/src/include/duckdb/planner/operator/logical_chunk_get.hpp index 4777775b08f..442e022083c 100644 --- a/src/include/duckdb/planner/operator/logical_chunk_get.hpp +++ b/src/include/duckdb/planner/operator/logical_chunk_get.hpp @@ -33,6 +33,7 @@ class LogicalChunkGet : public LogicalOperator { vector GetColumnBindings() override { return GenerateColumnBindings(table_index, chunk_types.size()); } + protected: void ResolveTypes() override { // types are resolved in the constructor diff --git a/src/include/duckdb/planner/operator/logical_comparison_join.hpp b/src/include/duckdb/planner/operator/logical_comparison_join.hpp index f256c51b2c4..5b12e4d0c7e 100644 --- a/src/include/duckdb/planner/operator/logical_comparison_join.hpp +++ b/src/include/duckdb/planner/operator/logical_comparison_join.hpp @@ -22,8 +22,10 @@ class LogicalComparisonJoin : public LogicalJoin { //! The conditions of the join vector conditions; + public: string ParamsToString() const override; + public: static unique_ptr CreateJoin(JoinType type, unique_ptr left_child, unique_ptr right_child, diff --git a/src/include/duckdb/planner/operator/logical_copy_from_file.hpp b/src/include/duckdb/planner/operator/logical_copy_from_file.hpp index c2917c0ee8d..0b708afe68b 100644 --- a/src/include/duckdb/planner/operator/logical_copy_from_file.hpp +++ b/src/include/duckdb/planner/operator/logical_copy_from_file.hpp @@ -16,7 +16,8 @@ namespace duckdb { class LogicalCopyFromFile : public LogicalOperator { public: LogicalCopyFromFile(index_t table_index, unique_ptr info, vector sql_types) - : LogicalOperator(LogicalOperatorType::COPY_FROM_FILE), table_index(table_index), info(move(info)), sql_types(sql_types) { + : LogicalOperator(LogicalOperatorType::COPY_FROM_FILE), table_index(table_index), info(move(info)), + sql_types(sql_types) { } index_t table_index; @@ -27,6 +28,7 @@ class LogicalCopyFromFile : public LogicalOperator { vector GetColumnBindings() override { return GenerateColumnBindings(table_index, sql_types.size()); } + protected: void ResolveTypes() override { for (auto &type : sql_types) { diff --git a/src/include/duckdb/planner/operator/logical_cross_product.hpp b/src/include/duckdb/planner/operator/logical_cross_product.hpp index 099da2ee9e0..668f6c05bd7 100644 --- a/src/include/duckdb/planner/operator/logical_cross_product.hpp +++ b/src/include/duckdb/planner/operator/logical_cross_product.hpp @@ -19,6 +19,7 @@ class LogicalCrossProduct : public LogicalOperator { public: vector GetColumnBindings() override; + protected: void ResolveTypes() override; }; diff --git a/src/include/duckdb/planner/operator/logical_delim_get.hpp b/src/include/duckdb/planner/operator/logical_delim_get.hpp index 1666d105316..94be322354e 100644 --- a/src/include/duckdb/planner/operator/logical_delim_get.hpp +++ b/src/include/duckdb/planner/operator/logical_delim_get.hpp @@ -25,10 +25,12 @@ class LogicalDelimGet : public LogicalOperator { index_t table_index; //! The types of the chunk vector chunk_types; + public: vector GetColumnBindings() override { return GenerateColumnBindings(table_index, chunk_types.size()); } + protected: void ResolveTypes() override { // types are resolved in the constructor diff --git a/src/include/duckdb/planner/operator/logical_distinct.hpp b/src/include/duckdb/planner/operator/logical_distinct.hpp index 0d9fd131588..7683e3fef12 100644 --- a/src/include/duckdb/planner/operator/logical_distinct.hpp +++ b/src/include/duckdb/planner/operator/logical_distinct.hpp @@ -27,6 +27,7 @@ class LogicalDistinct : public LogicalOperator { vector GetColumnBindings() override { return children[0]->GetColumnBindings(); } + protected: void ResolveTypes() override { types = children[0]->types; diff --git a/src/include/duckdb/planner/operator/logical_empty_result.hpp b/src/include/duckdb/planner/operator/logical_empty_result.hpp index 7cfb32cce26..109e39e6e5b 100644 --- a/src/include/duckdb/planner/operator/logical_empty_result.hpp +++ b/src/include/duckdb/planner/operator/logical_empty_result.hpp @@ -22,10 +22,12 @@ class LogicalEmptyResult : public LogicalOperator { vector return_types; //! The columns that would be bound at this location (if the subtree was not optimized away) vector bindings; + public: vector GetColumnBindings() override { return bindings; } + protected: void ResolveTypes() override { this->types = return_types; diff --git a/src/include/duckdb/planner/operator/logical_expression_get.hpp b/src/include/duckdb/planner/operator/logical_expression_get.hpp index 6f8dd0aee7b..ee6f42eb36a 100644 --- a/src/include/duckdb/planner/operator/logical_expression_get.hpp +++ b/src/include/duckdb/planner/operator/logical_expression_get.hpp @@ -26,10 +26,12 @@ class LogicalExpressionGet : public LogicalOperator { vector expr_types; //! The set of expressions vector>> expressions; + public: vector GetColumnBindings() override { return GenerateColumnBindings(table_index, expr_types.size()); } + protected: void ResolveTypes() override { // types are resolved in the constructor diff --git a/src/include/duckdb/planner/operator/logical_filter.hpp b/src/include/duckdb/planner/operator/logical_filter.hpp index 4b454308df6..d33f4b366e1 100644 --- a/src/include/duckdb/planner/operator/logical_filter.hpp +++ b/src/include/duckdb/planner/operator/logical_filter.hpp @@ -19,6 +19,7 @@ class LogicalFilter : public LogicalOperator { LogicalFilter(); vector projection_map; + public: vector GetColumnBindings() override; @@ -28,6 +29,7 @@ class LogicalFilter : public LogicalOperator { //! Splits up the predicates of the LogicalFilter into a set of predicates //! separated by AND Returns whether or not any splits were made static bool SplitPredicates(vector> &expressions); + protected: void ResolveTypes() override; }; diff --git a/src/include/duckdb/planner/operator/logical_get.hpp b/src/include/duckdb/planner/operator/logical_get.hpp index 26577835d6f..414afa00736 100644 --- a/src/include/duckdb/planner/operator/logical_get.hpp +++ b/src/include/duckdb/planner/operator/logical_get.hpp @@ -32,6 +32,7 @@ class LogicalGet : public LogicalOperator { public: vector GetColumnBindings() override; + protected: void ResolveTypes() override; }; diff --git a/src/include/duckdb/planner/operator/logical_index_scan.hpp b/src/include/duckdb/planner/operator/logical_index_scan.hpp index adfa484d448..6cec8281d7d 100644 --- a/src/include/duckdb/planner/operator/logical_index_scan.hpp +++ b/src/include/duckdb/planner/operator/logical_index_scan.hpp @@ -53,6 +53,7 @@ class LogicalIndexScan : public LogicalOperator { vector GetColumnBindings() override { return GenerateColumnBindings(table_index, column_ids.size()); } + protected: void ResolveTypes() override { if (column_ids.size() == 0) { diff --git a/src/include/duckdb/planner/operator/logical_join.hpp b/src/include/duckdb/planner/operator/logical_join.hpp index 8fd90d8a0be..10ffa66600e 100644 --- a/src/include/duckdb/planner/operator/logical_join.hpp +++ b/src/include/duckdb/planner/operator/logical_join.hpp @@ -31,8 +31,10 @@ class LogicalJoin : public LogicalOperator { vector left_projection_map; //! The columns of the RHS that are output by the join vector right_projection_map; + public: vector GetColumnBindings() override; + protected: void ResolveTypes() override; }; diff --git a/src/include/duckdb/planner/operator/logical_limit.hpp b/src/include/duckdb/planner/operator/logical_limit.hpp index 9d5944e4850..ba56efef8d9 100644 --- a/src/include/duckdb/planner/operator/logical_limit.hpp +++ b/src/include/duckdb/planner/operator/logical_limit.hpp @@ -28,6 +28,7 @@ class LogicalLimit : public LogicalOperator { vector GetColumnBindings() override { return children[0]->GetColumnBindings(); } + protected: void ResolveTypes() override { types = children[0]->types; diff --git a/src/include/duckdb/planner/operator/logical_order.hpp b/src/include/duckdb/planner/operator/logical_order.hpp index 1e5bc41b79c..370b9c14698 100644 --- a/src/include/duckdb/planner/operator/logical_order.hpp +++ b/src/include/duckdb/planner/operator/logical_order.hpp @@ -26,6 +26,7 @@ class LogicalOrder : public LogicalOperator { vector GetColumnBindings() override { return children[0]->GetColumnBindings(); } + protected: void ResolveTypes() override { types = children[0]->types; diff --git a/src/include/duckdb/planner/operator/logical_projection.hpp b/src/include/duckdb/planner/operator/logical_projection.hpp index d0a57d74694..9116f63e5bd 100644 --- a/src/include/duckdb/planner/operator/logical_projection.hpp +++ b/src/include/duckdb/planner/operator/logical_projection.hpp @@ -18,8 +18,10 @@ class LogicalProjection : public LogicalOperator { LogicalProjection(index_t table_index, vector> select_list); index_t table_index; + public: vector GetColumnBindings() override; + protected: void ResolveTypes() override; }; diff --git a/src/include/duckdb/planner/operator/logical_prune_columns.hpp b/src/include/duckdb/planner/operator/logical_prune_columns.hpp index 125794b4f99..984b77c6bc4 100644 --- a/src/include/duckdb/planner/operator/logical_prune_columns.hpp +++ b/src/include/duckdb/planner/operator/logical_prune_columns.hpp @@ -21,8 +21,10 @@ class LogicalPruneColumns : public LogicalOperator { } index_t column_limit; + public: vector GetColumnBindings() override; + protected: void ResolveTypes() override; }; diff --git a/src/include/duckdb/planner/operator/logical_set_operation.hpp b/src/include/duckdb/planner/operator/logical_set_operation.hpp index 78fbb8c46b3..8ef0e4bcf25 100644 --- a/src/include/duckdb/planner/operator/logical_set_operation.hpp +++ b/src/include/duckdb/planner/operator/logical_set_operation.hpp @@ -30,6 +30,7 @@ class LogicalSetOperation : public LogicalOperator { vector GetColumnBindings() override { return GenerateColumnBindings(table_index, column_count); } + protected: void ResolveTypes() override { types = children[0]->types; diff --git a/src/include/duckdb/planner/operator/logical_table_function.hpp b/src/include/duckdb/planner/operator/logical_table_function.hpp index 8fc991f159b..fbcbe760230 100644 --- a/src/include/duckdb/planner/operator/logical_table_function.hpp +++ b/src/include/duckdb/planner/operator/logical_table_function.hpp @@ -28,6 +28,7 @@ class LogicalTableFunction : public LogicalOperator { public: vector GetColumnBindings() override; + protected: void ResolveTypes() override; }; diff --git a/src/include/duckdb/planner/operator/logical_top_n.hpp b/src/include/duckdb/planner/operator/logical_top_n.hpp index b40368d5de3..a65fdb42623 100644 --- a/src/include/duckdb/planner/operator/logical_top_n.hpp +++ b/src/include/duckdb/planner/operator/logical_top_n.hpp @@ -30,6 +30,7 @@ class LogicalTopN : public LogicalOperator { vector GetColumnBindings() override { return children[0]->GetColumnBindings(); } + protected: void ResolveTypes() override { types = children[0]->types; diff --git a/src/include/duckdb/planner/operator/logical_window.hpp b/src/include/duckdb/planner/operator/logical_window.hpp index 7e2b9cb765d..7c71fcd348e 100644 --- a/src/include/duckdb/planner/operator/logical_window.hpp +++ b/src/include/duckdb/planner/operator/logical_window.hpp @@ -20,8 +20,10 @@ class LogicalWindow : public LogicalOperator { } index_t window_index; + public: vector GetColumnBindings() override; + protected: void ResolveTypes() override; }; diff --git a/src/include/duckdb/planner/query_node/bound_select_node.hpp b/src/include/duckdb/planner/query_node/bound_select_node.hpp index 83741fe006a..6e075aa3103 100644 --- a/src/include/duckdb/planner/query_node/bound_select_node.hpp +++ b/src/include/duckdb/planner/query_node/bound_select_node.hpp @@ -50,8 +50,9 @@ class BoundSelectNode : public BoundQueryNode { index_t window_index; //! Window functions to compute (only used if HasWindow is true) vector> windows; + public: - index_t GetRootIndex() override{ + index_t GetRootIndex() override { return projection_index; } }; diff --git a/src/include/duckdb/planner/query_node/bound_set_operation_node.hpp b/src/include/duckdb/planner/query_node/bound_set_operation_node.hpp index 8a04b307f39..5e8df9f3013 100644 --- a/src/include/duckdb/planner/query_node/bound_set_operation_node.hpp +++ b/src/include/duckdb/planner/query_node/bound_set_operation_node.hpp @@ -33,6 +33,7 @@ class BoundSetOperationNode : public BoundQueryNode { unique_ptr left_binder; //! The binder used by the right side of the set operation unique_ptr right_binder; + public: index_t GetRootIndex() override { return setop_index; diff --git a/src/optimizer/column_lifetime_analyzer.cpp b/src/optimizer/column_lifetime_analyzer.cpp index 414aadb2505..aacbcdaa976 100644 --- a/src/optimizer/column_lifetime_analyzer.cpp +++ b/src/optimizer/column_lifetime_analyzer.cpp @@ -9,20 +9,23 @@ using namespace duckdb; using namespace std; -void ColumnLifetimeAnalyzer::ExtractUnusedColumnBindings(vector bindings, column_binding_set_t &unused_bindings) { - for(index_t i = 0; i < bindings.size(); i++) { +void ColumnLifetimeAnalyzer::ExtractUnusedColumnBindings(vector bindings, + column_binding_set_t &unused_bindings) { + for (index_t i = 0; i < bindings.size(); i++) { if (column_references.find(bindings[i]) == column_references.end()) { unused_bindings.insert(bindings[i]); } } } -void ColumnLifetimeAnalyzer::GenerateProjectionMap(vector bindings, column_binding_set_t &unused_bindings, vector &projection_map) { +void ColumnLifetimeAnalyzer::GenerateProjectionMap(vector bindings, + column_binding_set_t &unused_bindings, + vector &projection_map) { if (unused_bindings.size() == 0) { return; } // now iterate over the result bindings of the child - for(index_t i = 0; i < bindings.size(); i++) { + for (index_t i = 0; i < bindings.size(); i++) { // if this binding does not belong to the unused bindings, add it to the projection map if (unused_bindings.find(bindings[i]) == unused_bindings.end()) { projection_map.push_back(i); @@ -60,10 +63,9 @@ void ColumnLifetimeAnalyzer::VisitOperator(LogicalOperator &op) { if (everything_referenced) { break; } - auto &comp_join = (LogicalComparisonJoin&) op; - if (comp_join.join_type == JoinType::MARK || - comp_join.join_type == JoinType::SEMI || - comp_join.join_type == JoinType::ANTI) { + auto &comp_join = (LogicalComparisonJoin &)op; + if (comp_join.join_type == JoinType::MARK || comp_join.join_type == JoinType::SEMI || + comp_join.join_type == JoinType::ANTI) { break; } // FIXME for now, we only push into the projection map for equality (hash) joins @@ -92,8 +94,9 @@ void ColumnLifetimeAnalyzer::VisitOperator(LogicalOperator &op) { case LogicalOperatorType::EXCEPT: case LogicalOperatorType::INTERSECT: // for set operations we don't remove anything, just recursively visit the children - // FIXME: for UNION we can remove unreferenced columns as long as everything_referenced is false (i.e. we encounter a UNION node that is not preceded by a DISTINCT) - for(auto &child : op.children) { + // FIXME: for UNION we can remove unreferenced columns as long as everything_referenced is false (i.e. we + // encounter a UNION node that is not preceded by a DISTINCT) + for (auto &child : op.children) { ColumnLifetimeAnalyzer analyzer(true); analyzer.VisitOperator(*child); } @@ -113,7 +116,7 @@ void ColumnLifetimeAnalyzer::VisitOperator(LogicalOperator &op) { break; } case LogicalOperatorType::FILTER: { - auto &filter = (LogicalFilter&) op; + auto &filter = (LogicalFilter &)op; if (everything_referenced) { break; } @@ -134,13 +137,14 @@ void ColumnLifetimeAnalyzer::VisitOperator(LogicalOperator &op) { StandardVisitOperator(op); } - -unique_ptr ColumnLifetimeAnalyzer::VisitReplace(BoundColumnRefExpression &expr, unique_ptr *expr_ptr) { +unique_ptr ColumnLifetimeAnalyzer::VisitReplace(BoundColumnRefExpression &expr, + unique_ptr *expr_ptr) { column_references.insert(expr.binding); return nullptr; } -unique_ptr ColumnLifetimeAnalyzer::VisitReplace(BoundReferenceExpression &expr, unique_ptr *expr_ptr) { +unique_ptr ColumnLifetimeAnalyzer::VisitReplace(BoundReferenceExpression &expr, + unique_ptr *expr_ptr) { // BoundReferenceExpression should not be used here yet, they only belong in the physical plan throw InternalException("BoundReferenceExpression should not be used here yet!"); } diff --git a/src/optimizer/join_order_optimizer.cpp b/src/optimizer/join_order_optimizer.cpp index 391e6655779..24a74681510 100644 --- a/src/optimizer/join_order_optimizer.cpp +++ b/src/optimizer/join_order_optimizer.cpp @@ -64,8 +64,7 @@ static unique_ptr PushFilter(unique_ptr node, bool JoinOrderOptimizer::ExtractJoinRelations(LogicalOperator &input_op, vector &filter_operators, LogicalOperator *parent) { LogicalOperator *op = &input_op; - while (op->children.size() == 1 && - op->type != LogicalOperatorType::PROJECTION) { + while (op->children.size() == 1 && op->type != LogicalOperatorType::PROJECTION) { if (op->type == LogicalOperatorType::FILTER) { // extract join conditions from filter filter_operators.push_back(op); diff --git a/src/optimizer/pushdown/pushdown_set_operation.cpp b/src/optimizer/pushdown/pushdown_set_operation.cpp index 13bb3ea34b0..a4f389743a7 100644 --- a/src/optimizer/pushdown/pushdown_set_operation.cpp +++ b/src/optimizer/pushdown/pushdown_set_operation.cpp @@ -10,7 +10,8 @@ using namespace std; using Filter = FilterPushdown::Filter; -static void ReplaceSetOpBindings(vector &bindings, Filter &filter, Expression &expr, LogicalSetOperation &setop) { +static void ReplaceSetOpBindings(vector &bindings, Filter &filter, Expression &expr, + LogicalSetOperation &setop) { if (expr.type == ExpressionType::BOUND_COLUMN_REF) { auto &colref = (BoundColumnRefExpression &)expr; assert(colref.binding.table_index == setop.table_index); diff --git a/src/optimizer/remove_unused_columns.cpp b/src/optimizer/remove_unused_columns.cpp index d1fe614f43c..ca1e5eab0f6 100644 --- a/src/optimizer/remove_unused_columns.cpp +++ b/src/optimizer/remove_unused_columns.cpp @@ -21,17 +21,16 @@ using namespace std; void RemoveUnusedColumns::ReplaceBinding(ColumnBinding current_binding, ColumnBinding new_binding) { auto colrefs = column_references.find(current_binding); if (colrefs != column_references.end()) { - for(auto &colref : colrefs->second) { + for (auto &colref : colrefs->second) { assert(colref->binding == current_binding); colref->binding = new_binding; } } } -template -void RemoveUnusedColumns::ClearUnusedExpressions(vector &list, index_t table_idx) { +template void RemoveUnusedColumns::ClearUnusedExpressions(vector &list, index_t table_idx) { index_t offset = 0; - for(index_t col_idx = 0; col_idx < list.size(); col_idx++) { + for (index_t col_idx = 0; col_idx < list.size(); col_idx++) { auto current_binding = ColumnBinding(table_idx, col_idx + offset); auto entry = column_references.find(current_binding); if (entry == column_references.end()) { @@ -52,12 +51,13 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { // aggregate if (!everything_referenced) { // FIXME: groups that are not referenced need to stay -> but they don't need to be scanned and output! - auto &aggr = (LogicalAggregate&) op; + auto &aggr = (LogicalAggregate &)op; ClearUnusedExpressions(aggr.expressions, aggr.aggregate_index); if (aggr.expressions.size() == 0 && aggr.groups.size() == 0) { // removed all expressions from the aggregate: push a COUNT(*) - aggr.expressions.push_back(make_unique(TypeId::BIGINT, CountStarFun::GetFunction(), false)); + aggr.expressions.push_back( + make_unique(TypeId::BIGINT, CountStarFun::GetFunction(), false)); } } @@ -70,7 +70,7 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { case LogicalOperatorType::DELIM_JOIN: case LogicalOperatorType::COMPARISON_JOIN: { if (!everything_referenced) { - auto &comp_join = (LogicalComparisonJoin&) op; + auto &comp_join = (LogicalComparisonJoin &)op; if (comp_join.join_type != JoinType::INNER) { break; @@ -78,18 +78,18 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { // for inner joins with equality predicates in the form of (X=Y) // we can replace any references to the RHS (Y) to references to the LHS (X) // this reduces the amount of columns we need to extract from the join hash table - for(auto &cond : comp_join.conditions) { + for (auto &cond : comp_join.conditions) { if (cond.comparison == ExpressionType::COMPARE_EQUAL) { if (cond.left->expression_class == ExpressionClass::BOUND_COLUMN_REF && - cond.right->expression_class == ExpressionClass::BOUND_COLUMN_REF) { + cond.right->expression_class == ExpressionClass::BOUND_COLUMN_REF) { // comparison join between two bound column refs // we can replace any reference to the RHS (build-side) with a reference to the LHS (probe-side) - auto &lhs_col = (BoundColumnRefExpression &) *cond.left; - auto &rhs_col = (BoundColumnRefExpression &) *cond.right; + auto &lhs_col = (BoundColumnRefExpression &)*cond.left; + auto &rhs_col = (BoundColumnRefExpression &)*cond.right; // if there are any columns that refer to the RHS, auto colrefs = column_references.find(rhs_col.binding); if (colrefs != column_references.end()) { - for(auto &entry : colrefs->second) { + for (auto &entry : colrefs->second) { entry->binding = lhs_col.binding; column_references[lhs_col.binding].push_back(entry); } @@ -107,15 +107,16 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { case LogicalOperatorType::EXCEPT: case LogicalOperatorType::INTERSECT: // for set operations we don't remove anything, just recursively visit the children - // FIXME: for UNION we can remove unreferenced columns as long as everything_referenced is false (i.e. we encounter a UNION node that is not preceded by a DISTINCT) - for(auto &child : op.children) { + // FIXME: for UNION we can remove unreferenced columns as long as everything_referenced is false (i.e. we + // encounter a UNION node that is not preceded by a DISTINCT) + for (auto &child : op.children) { RemoveUnusedColumns remove(true); remove.VisitOperator(*child); } return; case LogicalOperatorType::PROJECTION: { if (!everything_referenced) { - auto &proj = (LogicalProjection&) op; + auto &proj = (LogicalProjection &)op; ClearUnusedExpressions(proj.expressions, proj.table_index); if (proj.expressions.size() == 0) { @@ -133,13 +134,14 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { } case LogicalOperatorType::GET: if (!everything_referenced) { - auto &get = (LogicalGet&) op; + auto &get = (LogicalGet &)op; // table scan: figure out which columns are referenced ClearUnusedExpressions(get.column_ids, get.table_index); if (get.column_ids.size() == 0) { - // this generally means we are only interested in whether or not anything exists in the table (e.g. EXISTS(SELECT * FROM tbl)) - // in this case, we just scan the row identifier column as it means we do not need to read any of the columns + // this generally means we are only interested in whether or not anything exists in the table (e.g. + // EXISTS(SELECT * FROM tbl)) in this case, we just scan the row identifier column as it means we do not + // need to read any of the columns get.column_ids.push_back(COLUMN_IDENTIFIER_ROW_ID); } } @@ -158,14 +160,15 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { LogicalOperatorVisitor::VisitOperatorChildren(op); } - -unique_ptr RemoveUnusedColumns::VisitReplace(BoundColumnRefExpression &expr, unique_ptr *expr_ptr) { +unique_ptr RemoveUnusedColumns::VisitReplace(BoundColumnRefExpression &expr, + unique_ptr *expr_ptr) { // add a column reference column_references[expr.binding].push_back(&expr); return nullptr; } -unique_ptr RemoveUnusedColumns::VisitReplace(BoundReferenceExpression &expr, unique_ptr *expr_ptr) { +unique_ptr RemoveUnusedColumns::VisitReplace(BoundReferenceExpression &expr, + unique_ptr *expr_ptr) { // BoundReferenceExpression should not be used here yet, they only belong in the physical plan throw InternalException("BoundReferenceExpression should not be used here yet!"); } diff --git a/src/planner/logical_operator.cpp b/src/planner/logical_operator.cpp index 5dfcb055303..4df3ffa6a71 100644 --- a/src/planner/logical_operator.cpp +++ b/src/planner/logical_operator.cpp @@ -34,7 +34,7 @@ void LogicalOperator::ResolveOperatorTypes() { vector LogicalOperator::GenerateColumnBindings(index_t table_idx, index_t column_count) { vector result; - for(index_t i = 0; i < column_count; i++) { + for (index_t i = 0; i < column_count; i++) { result.push_back(ColumnBinding(table_idx, i)); } return result; @@ -45,7 +45,7 @@ vector LogicalOperator::MapTypes(vector types, vector p return types; } else { vector result_types; - for(auto index : projection_map) { + for (auto index : projection_map) { result_types.push_back(types[index]); } return result_types; @@ -57,7 +57,7 @@ vector LogicalOperator::MapBindings(vector binding return bindings; } else { vector result_bindings; - for(auto index : projection_map) { + for (auto index : projection_map) { result_bindings.push_back(bindings[index]); } return result_bindings; diff --git a/src/planner/logical_plan/plan_subquery.cpp b/src/planner/logical_plan/plan_subquery.cpp index 8e2d4894192..618b078081d 100644 --- a/src/planner/logical_plan/plan_subquery.cpp +++ b/src/planner/logical_plan/plan_subquery.cpp @@ -120,8 +120,8 @@ static unique_ptr PlanUncorrelatedSubquery(Binder &binder, BoundSubq JoinCondition cond; cond.left = move(expr.child); cond.right = BoundCastExpression::AddCastToType( - make_unique(GetInternalType(expr.child_type), plan_columns[0]), - expr.child_type, expr.child_target); + make_unique(GetInternalType(expr.child_type), plan_columns[0]), expr.child_type, + expr.child_target); cond.comparison = expr.comparison_type; join->conditions.push_back(move(cond)); root = move(join); @@ -255,8 +255,8 @@ static unique_ptr PlanCorrelatedSubquery(Binder &binder, BoundSubque JoinCondition compare_cond; compare_cond.left = move(expr.child); compare_cond.right = BoundCastExpression::AddCastToType( - make_unique(GetInternalType(expr.child_type), plan_columns[0]), - expr.child_type, expr.child_target); + make_unique(GetInternalType(expr.child_type), plan_columns[0]), expr.child_type, + expr.child_target); compare_cond.comparison = expr.comparison_type; delim_join->conditions.push_back(move(compare_cond)); diff --git a/src/planner/logical_plan/query_node/plan_setop.cpp b/src/planner/logical_plan/query_node/plan_setop.cpp index 5ae82f9ca31..c7f3f6bb0e0 100644 --- a/src/planner/logical_plan/query_node/plan_setop.cpp +++ b/src/planner/logical_plan/query_node/plan_setop.cpp @@ -45,8 +45,8 @@ unique_ptr LogicalPlanGenerator::CastLogicalOperatorToTypes(vec // now generate the expression list vector> select_list; for (index_t i = 0; i < target_types.size(); i++) { - unique_ptr result = make_unique(GetInternalType(source_types[i]), - setop_columns[i]); + unique_ptr result = + make_unique(GetInternalType(source_types[i]), setop_columns[i]); if (source_types[i] != target_types[i]) { // add a cast only if the source and target types are not equivalent result = make_unique(GetInternalType(target_types[i]), move(result), diff --git a/src/planner/operator/logical_aggregate.cpp b/src/planner/operator/logical_aggregate.cpp index 4d640d5db32..05ef32943ca 100644 --- a/src/planner/operator/logical_aggregate.cpp +++ b/src/planner/operator/logical_aggregate.cpp @@ -4,9 +4,10 @@ using namespace duckdb; using namespace std; -LogicalAggregate::LogicalAggregate(index_t group_index, index_t aggregate_index, vector> select_list) - : LogicalOperator(LogicalOperatorType::AGGREGATE_AND_GROUP_BY, move(select_list)), group_index(group_index), - aggregate_index(aggregate_index) { +LogicalAggregate::LogicalAggregate(index_t group_index, index_t aggregate_index, + vector> select_list) + : LogicalOperator(LogicalOperatorType::AGGREGATE_AND_GROUP_BY, move(select_list)), group_index(group_index), + aggregate_index(aggregate_index) { } void LogicalAggregate::ResolveTypes() { @@ -21,10 +22,10 @@ void LogicalAggregate::ResolveTypes() { vector LogicalAggregate::GetColumnBindings() { vector result; - for(index_t i = 0; i < groups.size(); i++) { + for (index_t i = 0; i < groups.size(); i++) { result.push_back(ColumnBinding(group_index, i)); } - for(index_t i = 0; i < expressions.size(); i++) { + for (index_t i = 0; i < expressions.size(); i++) { result.push_back(ColumnBinding(aggregate_index, i)); } return result; diff --git a/src/planner/operator/logical_get.cpp b/src/planner/operator/logical_get.cpp index 9717fae6d44..f9d97e11646 100644 --- a/src/planner/operator/logical_get.cpp +++ b/src/planner/operator/logical_get.cpp @@ -7,10 +7,10 @@ using namespace duckdb; using namespace std; LogicalGet::LogicalGet(index_t table_index) - : LogicalOperator(LogicalOperatorType::GET), table(nullptr), table_index(table_index) { + : LogicalOperator(LogicalOperatorType::GET), table(nullptr), table_index(table_index) { } LogicalGet::LogicalGet(TableCatalogEntry *table, index_t table_index, vector column_ids) - : LogicalOperator(LogicalOperatorType::GET), table(table), table_index(table_index), column_ids(column_ids) { + : LogicalOperator(LogicalOperatorType::GET), table(table), table_index(table_index), column_ids(column_ids) { } string LogicalGet::ParamsToString() const { @@ -22,10 +22,10 @@ string LogicalGet::ParamsToString() const { vector LogicalGet::GetColumnBindings() { if (!table) { - return { ColumnBinding(INVALID_INDEX, 0) }; + return {ColumnBinding(INVALID_INDEX, 0)}; } vector result; - for(index_t i = 0; i < column_ids.size(); i++) { + for (index_t i = 0; i < column_ids.size(); i++) { result.push_back(ColumnBinding(table_index, i)); } return result; diff --git a/src/planner/operator/logical_join.cpp b/src/planner/operator/logical_join.cpp index 5e612d8bd12..49afe176318 100644 --- a/src/planner/operator/logical_join.cpp +++ b/src/planner/operator/logical_join.cpp @@ -6,7 +6,8 @@ using namespace duckdb; using namespace std; -LogicalJoin::LogicalJoin(JoinType join_type, LogicalOperatorType logical_type) : LogicalOperator(logical_type), join_type(join_type) { +LogicalJoin::LogicalJoin(JoinType join_type, LogicalOperatorType logical_type) + : LogicalOperator(logical_type), join_type(join_type) { } vector LogicalJoin::GetColumnBindings() { @@ -44,7 +45,7 @@ void LogicalJoin::ResolveTypes() { void LogicalJoin::GetTableReferences(LogicalOperator &op, unordered_set &bindings) { auto column_bindings = op.GetColumnBindings(); - for(auto binding : column_bindings) { + for (auto binding : column_bindings) { bindings.insert(binding.table_index); } } diff --git a/src/planner/operator/logical_projection.cpp b/src/planner/operator/logical_projection.cpp index 81781723152..bc8058a3089 100644 --- a/src/planner/operator/logical_projection.cpp +++ b/src/planner/operator/logical_projection.cpp @@ -3,9 +3,8 @@ using namespace duckdb; using namespace std; - LogicalProjection::LogicalProjection(index_t table_index, vector> select_list) - : LogicalOperator(LogicalOperatorType::PROJECTION, move(select_list)), table_index(table_index) { + : LogicalOperator(LogicalOperatorType::PROJECTION, move(select_list)), table_index(table_index) { } vector LogicalProjection::GetColumnBindings() { diff --git a/src/planner/operator/logical_window.cpp b/src/planner/operator/logical_window.cpp index 5bf72426526..73920ee9280 100644 --- a/src/planner/operator/logical_window.cpp +++ b/src/planner/operator/logical_window.cpp @@ -5,7 +5,7 @@ using namespace std; vector LogicalWindow::GetColumnBindings() { auto child_bindings = children[0]->GetColumnBindings(); - for(index_t i = 0; i < expressions.size(); i++) { + for (index_t i = 0; i < expressions.size(); i++) { child_bindings.push_back(ColumnBinding(window_index, i)); } return child_bindings; diff --git a/test/sql/simple/test_join.cpp b/test/sql/simple/test_join.cpp index 32f17ddd500..84242698279 100644 --- a/test/sql/simple/test_join.cpp +++ b/test/sql/simple/test_join.cpp @@ -88,7 +88,8 @@ TEST_CASE("Test basic joins of tables", "[joins]") { REQUIRE(CHECK_COLUMN(result, 1, {1})); } SECTION("equality join where both lhs and rhs keys are projected with filter") { - result = con.Query("SELECT * FROM (VALUES (1), (2)) tbl(i) JOIN (VALUES (1), (2)) tbl2(j) ON (i=j) WHERE i+j=2;"); + result = + con.Query("SELECT * FROM (VALUES (1), (2)) tbl(i) JOIN (VALUES (1), (2)) tbl2(j) ON (i=j) WHERE i+j=2;"); REQUIRE(CHECK_COLUMN(result, 0, {1})); REQUIRE(CHECK_COLUMN(result, 1, {1})); } @@ -430,11 +431,11 @@ TEST_CASE("Test joins with various columns that are only used in the join", "[jo REQUIRE(CHECK_COLUMN(result, 0, {36})); // count of multi-way join with filters - result = con.Query("SELECT COUNT(*) FROM test a1, test a2, test a3 WHERE a1.b=a2.b AND a2.b=a3.b AND a1.a=11 AND a2.a=11 AND a3.a=11"); + result = con.Query("SELECT COUNT(*) FROM test a1, test a2, test a3 WHERE a1.b=a2.b AND a2.b=a3.b AND a1.a=11 AND " + "a2.a=11 AND a3.a=11"); REQUIRE(CHECK_COLUMN(result, 0, {1})); // unused columns that become unused because of optimizer result = con.Query("SELECT (TRUE OR a1.a=a2.b) FROM test a1, test a2 WHERE a1.a=11 AND a2.a>=10"); REQUIRE(CHECK_COLUMN(result, 0, {true, true, true})); - }