You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introducing Recursive CTEs to Musoq - Design Discussion
Overview
I'd like to discuss adding recursive Common Table Expression (CTE) support to Musoq. This would enable hierarchical queries and graph traversal scenarios while maintaining Musoq's SQL-like syntax and simplicity.
Proposed Syntax
Basic structure:
with recursive <name> [(<options>)] as (
-- Anchor member<initial_query>union all-- Recursive member<recursive_query>
)
With configurable options:
maxdepth <number>-- Maximum recursion depth
Example usage:
with recursive Hierarchy as (
-- Anchor: Get root nodesselect Id, ParentId, Name, 0as Level
from#system.source()where ParentId is nullunion all-- Recursive: Get child nodesselectchild.Id, child.ParentId, child.Name, parent.Level+1from#system.source() childinner join Hierarchy parent onchild.ParentId=parent.Id
)
select
Level,
Count(*) as NodesAtLevel,
string_agg(Name, ', ') as Names
from Hierarchy
group by Level
havingCount(*) >1order by Level
Key Design Decision: Data Source Awareness
The main architectural decision we need to make is whether data sources should be aware they're participating in a recursive query.
Option 1: Sources Unaware of Recursion
Data sources operate as they do today
All recursion handling happens in the query engine
Simpler plugin development
Consistent with current separation of concerns
Option 2: Recursion-Aware Sources
Sources could implement caching strategies
Better control over memory usage through chunking
Potential for source-specific optimizations
More complex plugin API
Discussion Points
Should data sources be aware of recursion? Why or why not?
What other options should be supported besides maxdepth?
How should we handle cycle detection?
Are there specific use cases we should consider in the design?
What performance characteristics are most important?
Initial Implementation Thoughts
I'm currently leaning towards keeping data sources unaware of recursion because:
Maintains simple plugin interface
Consistent with how other operations work
Engine can optimize recursion globally
Lower barrier to entry for plugin developers
However, I'm very interested in the community's thoughts on this approach.
Examples of Potential Use Cases
File System Traversal
Directory hierarchies
File dependency chains
Configuration inheritance
Git Analysis
Commit history traversal
Branch relationships
Merge history analysis
Code Analysis
Class inheritance chains
Dependency graphs
Call hierarchies
Organizational Data
Employee hierarchies
Department structures
Resource allocation trees
Next Steps
Gather community feedback on the design approach
Define detailed technical requirements
Create prototype implementation
Develop test cases
Questions for the Community
What scenarios would you use recursive CTEs for?
Do you see any issues with the proposed syntax?
What optimizations would be most valuable for your use cases?
How important is cycle detection for your scenarios?
Implementation Considerations
Key areas that will need attention:
graph TD
A[Recursive CTE Feature] --> B[Parser Changes]
A --> C[Query Engine Updates]
A --> D[Memory Management]
A --> E[Performance Optimization]
B --> B1[Syntax Recognition]
B --> B2[Validation Rules]
C --> C1[Recursion Control]
C --> C2[Result Streaming]
D --> D1[Chunking]
D --> D2[Caching]
E --> E1[Early Termination]
E --> E2[Parallel Processing]
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Introducing Recursive CTEs to Musoq - Design Discussion
Overview
I'd like to discuss adding recursive Common Table Expression (CTE) support to Musoq. This would enable hierarchical queries and graph traversal scenarios while maintaining Musoq's SQL-like syntax and simplicity.
Proposed Syntax
Basic structure:
With configurable options:
Example usage:
Key Design Decision: Data Source Awareness
The main architectural decision we need to make is whether data sources should be aware they're participating in a recursive query.
Option 1: Sources Unaware of Recursion
Option 2: Recursion-Aware Sources
Discussion Points
maxdepth
?Initial Implementation Thoughts
I'm currently leaning towards keeping data sources unaware of recursion because:
However, I'm very interested in the community's thoughts on this approach.
Examples of Potential Use Cases
File System Traversal
Git Analysis
Code Analysis
Organizational Data
Next Steps
Questions for the Community
Implementation Considerations
Key areas that will need attention:
Beta Was this translation helpful? Give feedback.
All reactions