MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / join

Method join

src/transform/src/analysis.rs:1737–1803  ·  view source on GitHub ↗
(
            &self,
            equivalences: &Vec<Vec<MirScalarExpr>>,
            _implementation: &JoinImplementation,
            unique_columns: BTreeMap<usize, usize>,
            mut inputs: V

Source from the content-addressed store, hash-verified

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);

Callers 15

registerMethod · 0.45
forgetMethod · 0.45
forget_allMethod · 0.45
benchesFunction · 0.45
criterion_dirFunction · 0.45
read_criterion_median_nsFunction · 0.45
criterion_dirFunction · 0.45
read_criterion_median_nsFunction · 0.45
print_throughput_tableFunction · 0.45
release_crosses_threadsFunction · 0.45
run_dataflowFunction · 0.45
run_executeFunction · 0.45

Calls 7

unwrapMethod · 0.80
replaceFunction · 0.50
is_emptyMethod · 0.45
getMethod · 0.45
insertMethod · 0.45
iterMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected