Skip to content

feat(sql): allow self-UNION queries in materialized views#5730

Merged
bluestreak01 merged 3 commits intomasterfrom
puzpuzpuz_relax_mat_view_query_validation
Jun 16, 2025
Merged

feat(sql): allow self-UNION queries in materialized views#5730
bluestreak01 merged 3 commits intomasterfrom
puzpuzpuz_relax_mat_view_query_validation

Conversation

@puzpuzpuz
Copy link
Copy Markdown
Contributor

Relaxes UNION restriction for materialized view queries. Namely, self-UNION on base table is now allowed.

@puzpuzpuz puzpuzpuz self-assigned this Jun 9, 2025
@puzpuzpuz puzpuzpuz added Enhancement Enhance existing functionality SQL Issues or changes relating to SQL execution Materialized View labels Jun 9, 2025
@bluestreak01 bluestreak01 requested a review from Copilot June 11, 2025 13:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR relaxes the materialized view validator to allow self-UNION on the base table while still prohibiting unions involving other tables.

  • Update validateMatViewQuery to track all referenced tables and permit self-UNION only when no other tables are involved
  • Remove the old isTableQueried helper and replace it with collectAllTableNames
  • Add tests for successful self-UNION and failure when unioning with a non-base table; remove the obsolete union test

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
CreateMatViewTest.java Added tests for self-UNION support and failing non-base-table unions; removed outdated union test
SqlParser.java Replaced isTableQueried logic with collectAllTableNames, updated validation to allow self-UNION
Comments suppressed due to low confidence (1)

core/src/test/java/io/questdb/test/cairo/mv/CreateMatViewTest.java:197

  • Test only covers UNION (distinct). Add a variant with UNION ALL in testCreateMatViewBaseTableSelfUnion to ensure both forms are allowed.
union

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 11 / 11 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/SqlParser.java 11 11 100.00%

@bluestreak01 bluestreak01 merged commit 09ff882 into master Jun 16, 2025
37 checks passed
@bluestreak01 bluestreak01 deleted the puzpuzpuz_relax_mat_view_query_validation branch June 16, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Enhance existing functionality Materialized View SQL Issues or changes relating to SQL execution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants