Function mz_transform::dataflow::choose_index
source · fn choose_index(
source_keys: &BTreeMap<GlobalId, BTreeSet<Vec<MirScalarExpr>>>,
id: &GlobalId,
indexes: &Vec<(GlobalId, Vec<MirScalarExpr>)>,
) -> Option<(GlobalId, Vec<MirScalarExpr>)>
Expand description
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. (Although, picking a unique key tries to capture this already.)
- Some indexes might have an error, while others don’t. https://github.com/MaterializeInc/database-issues/issues/4455
- Some indexes might have more extra data in their keys (because of being on more complicated expressions than just column references), which won’t be used in a full scan.