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>)>,
)
| 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. |
| 846 | fn 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)] |
| 864 | struct CollectIndexRequests<'a> { |
no test coverage detected