If a Scan has a single equality filter on the primary key, convert to PointGet.
(plan: SqlPlan)
| 6 | |
| 7 | /// If a Scan has a single equality filter on the primary key, convert to PointGet. |
| 8 | pub fn optimize(plan: SqlPlan) -> SqlPlan { |
| 9 | match plan { |
| 10 | SqlPlan::Scan { |
| 11 | ref collection, |
| 12 | ref alias, |
| 13 | ref engine, |
| 14 | ref filters, |
| 15 | ref projection, |
| 16 | ref temporal, |
| 17 | .. |
| 18 | } if filters.len() == 1 |
| 19 | && !temporal.is_temporal() |
| 20 | && !projection |
| 21 | .iter() |
| 22 | .any(|p| matches!(p, Projection::Computed { .. })) => |
| 23 | { |
| 24 | if let Some((key_col, key_val)) = extract_pk_equality(&filters[0]) { |
| 25 | return SqlPlan::PointGet { |
| 26 | collection: collection.clone(), |
| 27 | alias: alias.clone(), |
| 28 | engine: *engine, |
| 29 | key_column: key_col, |
| 30 | key_value: key_val, |
| 31 | }; |
| 32 | } |
| 33 | plan |
| 34 | } |
| 35 | _ => plan, |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /// Extract a simple equality filter on a known PK column. |
| 40 | fn extract_pk_equality(filter: &Filter) -> Option<(String, SqlValue)> { |
nothing calls this directly
no test coverage detected