|
| 1 | +//! Logical Plan representation for Cypher queries. |
| 2 | +//! |
| 3 | +//! This module defines the core data structures representing a Cypher query |
| 4 | +//! as an intermediate representation (IR) between parsed AST and generated SQL. |
| 5 | +//! |
| 6 | +//! # Architecture Overview |
| 7 | +//! |
| 8 | +//! ```text |
| 9 | +//! Cypher Query → AST → LogicalPlan → SQL Query |
| 10 | +//! ^^^^^^^^^^^ |
| 11 | +//! This module |
| 12 | +//! ``` |
| 13 | +//! |
| 14 | +//! # Key Components |
| 15 | +//! |
| 16 | +//! ## Core Types |
| 17 | +//! - [`LogicalPlan`] - Main enum representing all query plan nodes |
| 18 | +//! - [`ViewScan`] - Table scan with optional predicate pushdown |
| 19 | +//! - [`GraphNode`] / [`GraphRel`] - Graph pattern nodes and relationships |
| 20 | +//! - [`Projection`] - SELECT clause items |
| 21 | +//! - [`Filter`] - WHERE clause conditions |
| 22 | +//! - [`GroupBy`] - Aggregation and grouping |
| 23 | +//! - [`Cte`] - Common Table Expression (WITH clause in SQL sense) |
| 24 | +//! - [`CartesianProduct`] - CROSS JOIN for disconnected patterns |
| 25 | +//! - [`Union`] - UNION/UNION ALL for combined result sets |
| 26 | +//! |
| 27 | +//! ## Clause Processing Submodules |
| 28 | +//! - `match_clause` - MATCH pattern to scan/join translation |
| 29 | +//! - `optional_match_clause` - OPTIONAL MATCH (LEFT JOIN) handling |
| 30 | +//! - `with_clause` - WITH clause scope/projection boundaries |
| 31 | +//! - `return_clause` - RETURN projection handling |
| 32 | +//! - `where_clause` - WHERE condition processing |
| 33 | +//! - `order_by_clause` - ORDER BY generation |
| 34 | +//! - `skip_n_limit_clause` - SKIP/LIMIT pagination |
| 35 | +//! - `unwind_clause` - UNWIND array expansion |
| 36 | +//! |
| 37 | +//! # Plan Building |
| 38 | +//! |
| 39 | +//! Plans are built via [`plan_builder::build_logical_plan`] which: |
| 40 | +//! 1. Processes Cypher clauses in order |
| 41 | +//! 2. Builds nodes from inner to outer (scans → joins → filters → projections) |
| 42 | +//! 3. Tracks planning context via [`PlanCtx`] |
| 43 | +//! |
| 44 | +//! # Example Plan Structure |
| 45 | +//! |
| 46 | +//! ```text |
| 47 | +//! MATCH (u:User)-[f:FOLLOWS]->(friend) |
| 48 | +//! WHERE u.active = true |
| 49 | +//! RETURN friend.name |
| 50 | +//! |
| 51 | +//! → Projection(friend.name) |
| 52 | +//! └─ Filter(u.active = true) |
| 53 | +//! └─ GraphRel(f:FOLLOWS) |
| 54 | +//! ├─ left: ViewScan(users AS u) |
| 55 | +//! ├─ center: ViewScan(follows AS f) |
| 56 | +//! └─ right: ViewScan(users AS friend) |
| 57 | +//! ``` |
| 58 | +//! |
| 59 | +//! # ID Generation |
| 60 | +//! |
| 61 | +//! For anonymous patterns, unique IDs are generated via: |
| 62 | +//! - [`generate_id`] - Simple incrementing aliases (t1, t2, t3...) |
| 63 | +//! - [`generate_cte_id`] - CTE names (cte1, cte2, cte3...) |
| 64 | +
|
1 | 65 | use serde::{Deserialize, Serialize}; |
2 | 66 | use std::sync::atomic::{AtomicU32, Ordering}; |
3 | 67 | use std::{collections::HashMap, fmt, sync::Arc}; |
|
0 commit comments