(
&self,
equivalences: &Vec<Vec<MirScalarExpr>>,
_implementation: &JoinImplementation,
unique_columns: BTreeMap<usize, usize>,
mut inputs: V
| 1735 | } |
| 1736 | |
| 1737 | fn join( |
| 1738 | &self, |
| 1739 | equivalences: &Vec<Vec<MirScalarExpr>>, |
| 1740 | _implementation: &JoinImplementation, |
| 1741 | unique_columns: BTreeMap<usize, usize>, |
| 1742 | mut inputs: Vec<CardinalityEstimate>, |
| 1743 | ) -> CardinalityEstimate { |
| 1744 | if inputs.is_empty() { |
| 1745 | return CardinalityEstimate::from(0.0); |
| 1746 | } |
| 1747 | |
| 1748 | for equiv in equivalences { |
| 1749 | // those sources which have a unique key |
| 1750 | let mut unique_sources = BTreeSet::new(); |
| 1751 | let mut all_unique = true; |
| 1752 | |
| 1753 | for expr in equiv { |
| 1754 | if let MirScalarExpr::Column(col, _) = expr { |
| 1755 | if let Some(idx) = unique_columns.get(col) { |
| 1756 | unique_sources.insert(*idx); |
| 1757 | } else { |
| 1758 | all_unique = false; |
| 1759 | } |
| 1760 | } else { |
| 1761 | all_unique = false; |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | // no unique columns in this equivalence |
| 1766 | if unique_sources.is_empty() { |
| 1767 | continue; |
| 1768 | } |
| 1769 | |
| 1770 | // ALL unique columns in this equivalence |
| 1771 | if all_unique { |
| 1772 | // these inputs have unique keys for _all_ of the equivalence, so they're a bound on how many rows we'll get from those sources |
| 1773 | // we'll find the leftmost such input and use it to hold the minimum; the other sources we set to 1.0 (so they have no effect) |
| 1774 | let mut sources = unique_sources.iter(); |
| 1775 | |
| 1776 | let lhs_idx = *sources.next().unwrap(); |
| 1777 | let mut lhs = |
| 1778 | std::mem::replace(&mut inputs[lhs_idx], CardinalityEstimate::from(1.0)); |
| 1779 | for &rhs_idx in sources { |
| 1780 | let rhs = |
| 1781 | std::mem::replace(&mut inputs[rhs_idx], CardinalityEstimate::from(1.0)); |
| 1782 | lhs = CardinalityEstimate::min(lhs, rhs); |
| 1783 | } |
| 1784 | |
| 1785 | inputs[lhs_idx] = lhs; |
| 1786 | |
| 1787 | // best option! go look at the next equivalence |
| 1788 | continue; |
| 1789 | } |
| 1790 | |
| 1791 | // some unique columns in this equivalence |
| 1792 | for idx in unique_sources { |
| 1793 | // when joining R and S on R.x = S.x, if R.x is unique and S.x is not, we're bounded above by the cardinality of S |
| 1794 | inputs[idx] = CardinalityEstimate::from(1.0); |
no test coverage detected