Originally created by: romancitodev
📝 What changed?
Adds a relational algebra graph for a query, next to Explain and Analyze. The new Algebra button in the editor toolbar turns the selected statement (or the one at the caret) into a tab that draws it as a tree of operators: σ selection, π projection, ⋈ join, γ grouping, τ sort, δ distinct, ρ rename, × product and ∪ ∩ − for set operations. CTEs are inlined where they are used.
- Drawn in the ER diagram's style: flat boxes with a header, pan by dragging, zoom with Ctrl/⌘ + wheel, pinch or the buttons, and fit.
- Projections, groupings and sorts list their items as pills. A selection lists each of its
AND conditions on its own row, and a join's kind sits in its header.
- Hovering an operator previews the table at that point: its columns (with their table and type) and a few made-up example rows. It never reads the database; the columns come from the already loaded schema.
- Clicking an operator lights it in its own colour and marks the part of the query it comes from in the editor tab it was opened from. If that query changed or was closed since, it says so instead of marking the wrong text.
- The tab is kept in the session (the statement and where it began), so it comes back after a restart.
- Parsing uses
sqlparser (without its default recursive-protection feature), with the connection's dialect.
Closes [#27]
🧩 Type
- [ ] 🐛 Bug fix
- [x] ✨ Feature
- [ ] ♻️ Refactor
- [ ] 📝 Docs or landing page
- [ ] 🛠️ Build, CI or packaging
🧪 Tested
- [x] By hand in the app
- [ ] On macOS / Windows (Actions → Tests → Run workflow), for platform-specific changes
Unit tests cover the parser (shapes, spans, items, conditions and the columns each operator outputs), the graph's layout and pill wrapping, the example values, and the session round trip. cargo clippy is clean on the crates touched.
📌 Notes
- Only a single
SELECT can be drawn. Anything else shows a message.
- A join's span starts at its table, not at the
JOIN keyword, and a sort's span leaves out ASC/DESC. That is what sqlparser reports.
- Product (×) and set operations have no part of the query to mark.
- Translations for German and Bulgarian were written without a native review.
- [#29] (the visual query builder) is not part of this.
Originally posted by: romancitodev
This is an example based on this query: