Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common Table Expressions (CTE) inside WITH should have their own identifier scope #910

Closed
stumc opened this issue Feb 27, 2018 · 5 comments · Fixed by #3986
Closed

Common Table Expressions (CTE) inside WITH should have their own identifier scope #910

stumc opened this issue Feb 27, 2018 · 5 comments · Fixed by #3986
Labels
WITH clause Related to the WITH clause implementation.

Comments

@stumc
Copy link
Contributor

stumc commented Feb 27, 2018

Common Table Expressions inside WITH should have their own identifier scope. Currently they share the same scope as all other identifiers.

@stumc stumc changed the title Common Table Expressions inside WITH should have their own identifier scope Common Table Expressions (CTE) inside WITH should have their own identifier scope Feb 27, 2018
@grandinj
Copy link
Contributor

Are you planning on submitting a fix for this? :-)

@katzyn
Copy link
Contributor

katzyn commented Oct 13, 2018

I wrote a some basic implementation of separate identifier scopes for CTE views and it fixes problem from #1374, but our current implementation of CTE has a lot of tricks. Some queries don't work because such tricks cannot work with my changes. When I'm trying to resolve failure in one place something else becomes broken.

@katzyn
Copy link
Contributor

katzyn commented Jan 23, 2024

I recently resumed my work on this issue, but I had to remove support of non-standard constructions like WITH something INSERT / UPDATE / DELETE / CREATE TABLE / etc., they are too problematic.

@manticore-projects
Copy link
Contributor

manticore-projects commented Jan 23, 2024

Thank you @katzyn,

I may be overly biased here since we use WITH ... a lot as part of our financial reporting queries but I would say: a simple robust WITH ... SELECT ... (no recursion) was much better than an unreliable cover-all approach.

Please feel very welcome to push any kind of testing and support towards me, I will want to help you as good as I can.

Allow me one question please: Why is the WITH ... clause not just executed (first) into a temporary table, which is then used for the query itself? This is how I would have tried to implement it eventually. It even would allow for indexing? (sorry when this is too naive here)

@katzyn
Copy link
Contributor

katzyn commented Jan 24, 2024

We have multiple problems with CTEs:

  1. Wrong scope (this one).
  2. Problem with parameters (possibly a parser bug).
  3. Common problem with deeply nested references in derived tables, they are simply not supported at all and were never supported.
  4. Implementation of recursive CTEs is tricky and unreliable.

Materialization of derived tables, CTEs, etc. is another question. And it can't be performed unconditionally, we don't want to materialize something with 1,000,000,000 rows to use only 100 of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WITH clause Related to the WITH clause implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants