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

Function plan_join_from_select

nodedb-sql/src/planner/join/plan.rs:18–151  ·  view source on GitHub ↗
(
    select: &Select,
    scope: &TableScope,
    catalog: &dyn SqlCatalog,
    functions: &FunctionRegistry,
    temporal: crate::TemporalScope,
)

Source from the content-addressed store, hash-verified

16use crate::types::*;
17
18pub fn plan_join_from_select(
19 select: &Select,
20 scope: &TableScope,
21 catalog: &dyn SqlCatalog,
22 functions: &FunctionRegistry,
23 temporal: crate::TemporalScope,
24) -> Result<Option<SqlPlan>> {
25 let from = &select.from[0];
26
27 // Left side: either an ARRAY_* TVF or a named table.
28 let left_plan =
29 if let Some(plan) = array_arm::try_plan_relation(&from.relation, catalog, temporal)? {
30 plan
31 } else {
32 scan_for_relation(&from.relation, scope)?
33 };
34
35 let outer_alias = scan_alias_from_relation(&from.relation);
36
37 let mut current_plan = left_plan;
38
39 for join_item in &from.joins {
40 // Detect LATERAL derived subquery on the right side.
41 if is_lateral_derived(&join_item.relation) {
42 let lateral_alias =
43 lateral_alias_from_factor(&join_item.relation).ok_or_else(|| {
44 SqlError::Unsupported {
45 detail: "LATERAL subquery requires an alias (e.g. LATERAL (...) AS x)"
46 .into(),
47 }
48 })?;
49 let subquery = subquery_from_factor(&join_item.relation)
50 .expect("is_lateral_derived guarantees Derived variant");
51 let left_join = is_left_join_operator(&join_item.join_operator);
52 let projection = super::super::select::convert_projection(&select.projection)?;
53 return Ok(Some(plan_lateral_join(
54 current_plan,
55 outer_alias,
56 subquery,
57 &lateral_alias,
58 left_join,
59 projection,
60 catalog,
61 functions,
62 temporal,
63 )?));
64 }
65
66 // Right side: array TVF or named table.
67 let right_plan = if let Some(plan) =
68 array_arm::try_plan_relation(&join_item.relation, catalog, temporal)?
69 {
70 plan
71 } else {
72 scan_for_relation(&join_item.relation, scope)?
73 };
74
75 let (join_type, on_keys, condition) = extract_join_spec(&join_item.join_operator)?;

Callers 1

try_plan_joinFunction · 0.85

Calls 15

try_plan_relationFunction · 0.85
scan_for_relationFunction · 0.85
scan_alias_from_relationFunction · 0.85
is_lateral_derivedFunction · 0.85
subquery_from_factorFunction · 0.85
is_left_join_operatorFunction · 0.85
convert_projectionFunction · 0.85
plan_lateral_joinFunction · 0.85
extract_join_specFunction · 0.85
extract_subqueriesFunction · 0.85
convert_where_to_filtersFunction · 0.85

Tested by

no test coverage detected