Advanced Nodes¶
Advanced nodes represent sophisticated SQL features that go beyond basic statements, clauses, and expressions. These include window functions, common table expressions, recursive queries, and database-specific extensions.
Overview¶
Advanced nodes handle complex SQL constructs that often involve multiple components working together. They typically appear in modern SQL dialects and provide powerful analytical and data processing capabilities.
Advanced Node Categories¶
Window and Analytical Functions¶
- Window Functions -
TFunctionCall
withOVER
clause - Analytical functions (ROW_NUMBER, RANK, DENSE_RANK)
- Aggregate functions with windows
-
Frame specifications and partitioning
-
Window Specifications -
TWindowDef
- PARTITION BY clauses
- ORDER BY specifications
- Frame boundaries (ROWS, RANGE)
Common Table Expressions¶
- CTE Nodes -
TWithClause
,TCTE
- Non-recursive CTEs
- Recursive common table expressions
-
Multiple CTE definitions
- Hierarchical data traversal
- Graph processing patterns
- Cycle detection mechanisms
Pivoting and Data Transformation¶
- PIVOT Operations -
TPivotClause
- Column-to-row transformations
- Dynamic pivot operations
-
Aggregate specifications
-
UNPIVOT Operations -
TUnpivotClause
- Row-to-column transformations
- Column name specifications
- Value handling
Set Operations and Combinations¶
- UNION Operations -
TUnionSqlStatement
- UNION, UNION ALL
- INTERSECT, EXCEPT operations
-
Multiple set combinations
-
VALUES Clauses -
TValuesSqlStatement
- Table value constructors
- Inline data specifications
- Row value expressions
Database-Specific Features¶
- Database-Specific Nodes
- Vendor-specific syntax extensions
- Proprietary function calls
- Platform-specific optimizations
Advanced SQL Patterns¶
Window Function Structure¶
1 2 3 4 5 6 7 |
|
CTE Structure¶
1 2 3 4 5 6 |
|
Common Usage Patterns¶
Analyzing Window Functions¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
Processing CTEs¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Handling Set Operations¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Advanced Query Patterns¶
Recursive Query Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Window Function Example¶
1 2 3 4 5 6 7 8 9 10 |
|
PIVOT Example¶
1 2 3 4 5 6 7 8 9 |
|
Database-Specific Advanced Features¶
SQL Server¶
MERGE
statements with complex WHEN clausesOUTPUT
clauses with table variables- Hierarchical data with
hierarchyid
- Temporal tables with system versioning
PostgreSQL¶
- Advanced CTE features (
RECURSIVE
,MATERIALIZED
) - Array functions and operators
- JSON/JSONB advanced operations
- Custom aggregate functions
Oracle¶
- Advanced analytical functions
MODEL
clause for spreadsheet calculations- Flashback query capabilities
- Object-relational features
MySQL¶
- Window functions (8.0+)
- JSON table functions
- Generated columns
- Common table expressions (8.0+)
Performance Considerations¶
Window Function Optimization¶
- Partition elimination strategies
- Index usage for window ordering
- Memory usage for large partitions
CTE Performance¶
- Materialization vs inline expansion
- Recursive CTE termination conditions
- Index usage in CTE definitions
See Also¶
- Window Functions - Detailed analytical function documentation
- CTE Nodes - Common table expression specifics
- Expressions - Expression elements in advanced constructs
- SQL Statements - Statement containers for advanced features