| 1 | #include "duckdb/optimizer/join_order/join_node.hpp" | 
| 2 |  | 
| 3 | #include "duckdb/common/limits.hpp" | 
| 4 | #include "duckdb/planner/expression/list.hpp" | 
| 5 | #include "duckdb/planner/operator/list.hpp" | 
| 6 |  | 
| 7 | namespace duckdb { | 
| 8 |  | 
| 9 | JoinNode::JoinNode(JoinRelationSet &set, const double base_cardinality) | 
| 10 |     : set(set), info(nullptr), has_filter(false), left(nullptr), right(nullptr), base_cardinality(base_cardinality) { | 
| 11 | 	estimated_props = make_uniq<EstimatedProperties>(args: base_cardinality, args: 0); | 
| 12 | } | 
| 13 |  | 
| 14 | JoinNode::JoinNode(JoinRelationSet &set, optional_ptr<NeighborInfo> info, JoinNode &left, JoinNode &right, | 
| 15 |                    const double base_cardinality, double cost) | 
| 16 |     : set(set), info(info), has_filter(false), left(&left), right(&right), base_cardinality(base_cardinality) { | 
| 17 | 	estimated_props = make_uniq<EstimatedProperties>(args: base_cardinality, args&: cost); | 
| 18 | } | 
| 19 |  | 
| 20 | unique_ptr<EstimatedProperties> EstimatedProperties::Copy() { | 
| 21 | 	auto result = make_uniq<EstimatedProperties>(args&: cardinality, args&: cost); | 
| 22 | 	return result; | 
| 23 | } | 
| 24 |  | 
| 25 | double JoinNode::GetCost() { | 
| 26 | 	return estimated_props->GetCost(); | 
| 27 | } | 
| 28 |  | 
| 29 | void JoinNode::SetCost(double cost) { | 
| 30 | 	estimated_props->SetCost(cost); | 
| 31 | } | 
| 32 |  | 
| 33 | double JoinNode::GetBaseTableCardinality() { | 
| 34 | 	if (set.count > 1) { | 
| 35 | 		throw InvalidInputException("Cannot call get base table cardinality on intermediate join node" ); | 
| 36 | 	} | 
| 37 | 	return base_cardinality; | 
| 38 | } | 
| 39 |  | 
| 40 | void JoinNode::SetBaseTableCardinality(double base_card) { | 
| 41 | 	base_cardinality = base_card; | 
| 42 | } | 
| 43 |  | 
| 44 | void JoinNode::SetEstimatedCardinality(double estimated_card) { | 
| 45 | 	estimated_props->SetCardinality(estimated_card); | 
| 46 | } | 
| 47 |  | 
| 48 | string JoinNode::ToString() { | 
| 49 | 	string result = "-------------------------------\n" ; | 
| 50 | 	result += set.ToString() + "\n" ; | 
| 51 | 	result += "card = "  + to_string(val: GetCardinality<double>()) + "\n" ; | 
| 52 | 	bool is_cartesian = false; | 
| 53 | 	if (left && right) { | 
| 54 | 		is_cartesian = (GetCardinality<double>() == left->GetCardinality<double>() * right->GetCardinality<double>()); | 
| 55 | 	} | 
| 56 | 	result += "cartesian = "  + to_string(val: is_cartesian) + "\n" ; | 
| 57 | 	result += "cost = "  + to_string(val: estimated_props->GetCost()) + "\n" ; | 
| 58 | 	result += "left = \n" ; | 
| 59 | 	if (left) { | 
| 60 | 		result += left->ToString(); | 
| 61 | 	} | 
| 62 | 	result += "right = \n" ; | 
| 63 | 	if (right) { | 
| 64 | 		result += right->ToString(); | 
| 65 | 	} | 
| 66 | 	return result; | 
| 67 | } | 
| 68 | } // namespace duckdb | 
| 69 |  |