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

Function choose_index

src/transform/src/dataflow.rs:846–861  ·  view source on GitHub ↗

Pick an index from a given Vec of index keys. Currently, we pick as follows: - If there is an index on a unique key, then we pick that. (It might be better distributed, and is less likely to get dropped than other indexes.) - Otherwise, we pick an arbitrary index. TODO: There are various edge cases where a better choice would be possible: - Some indexes might be less skewed than others. (Althoug

(
    source_keys: &BTreeMap<GlobalId, BTreeSet<Vec<MirScalarExpr>>>,
    id: &GlobalId,
    indexes: &Vec<(GlobalId, Vec<MirScalarExpr>)>,
)

Source from the content-addressed store, hash-verified

844/// - Some indexes might have more extra data in their keys (because of being on more complicated
845/// expressions than just column references), which won't be used in a full scan.
846fn choose_index(
847 source_keys: &BTreeMap<GlobalId, BTreeSet<Vec<MirScalarExpr>>>,
848 id: &GlobalId,
849 indexes: &Vec<(GlobalId, Vec<MirScalarExpr>)>,
850) -> Option<(GlobalId, Vec<MirScalarExpr>)> {
851 match source_keys.get(id) {
852 None => indexes.iter().next().cloned(), // pick an arbitrary index
853 Some(coll_keys) => match indexes
854 .iter()
855 .find(|(_idx_id, key)| coll_keys.contains(&*key))
856 {
857 Some((idx_id, key)) => Some((*idx_id, key.clone())),
858 None => indexes.iter().next().cloned(), // pick an arbitrary index
859 },
860 }
861}
862
863#[derive(Debug)]
864struct CollectIndexRequests<'a> {

Calls 6

getMethod · 0.45
nextMethod · 0.45
iterMethod · 0.45
findMethod · 0.45
containsMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected