MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / optimize

Function optimize

nodedb-sql/src/optimizer/point_get.rs:8–37  ·  view source on GitHub ↗

If a Scan has a single equality filter on the primary key, convert to PointGet.

(plan: SqlPlan)

Source from the content-addressed store, hash-verified

6
7/// If a Scan has a single equality filter on the primary key, convert to PointGet.
8pub 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.
40fn extract_pk_equality(filter: &Filter) -> Option<(String, SqlValue)> {

Callers

nothing calls this directly

Calls 5

extract_pk_equalityFunction · 0.85
is_temporalMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected