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

sql: WITH temp_data AS and recursion alternatives #14592

Closed
timchunght opened this issue Apr 4, 2017 · 5 comments
Closed

sql: WITH temp_data AS and recursion alternatives #14592

timchunght opened this issue Apr 4, 2017 · 5 comments
Labels
O-community Originated from the community
Milestone

Comments

@timchunght
Copy link

timchunght commented Apr 4, 2017

I believe as pointed out in an issue about table expressions that WITH data AS (select...) syntax is not supported yet and not to mention the postgres WITH recursive syntax. We are really trying to replace postgres with cockroach but would like to know what the timeline is for recursion. Or if it isn't in the future 1-3months, what will be an alternative to achieve essentially the following in the currently supported subset of SQL expressions implemented in cockroach. Please advise.

with recursive tree(id, name, parent_id) as (
    select n.id, n.name, n.parent_id
    from nodes n
    where n.id = 5
    union all
    select n.id, n.name, n.parent_id
    from nodes n
    join tree t on (n.id = t.parent_id)
)
select *
from tree;

So basically all nodes are connected to another node via parent_id, and given a child, we want to get all of its ancestors.

@petermattis
Copy link
Collaborator

Common Table Expressions are planned for the future, but we haven't given them a concrete placement on the roadmap. It is almost certain that they won't be supported in the next 1-3 months in a stable release as we're planning for a 6 month cadence for stable releases. The alternative to using a CTE (i.e. WITH or WITH RECURSIVE) is to perform the iteration/recursion on the client side in your application code.

@knz I believed you investigated how hard it would be to implement CTEs. Anything to add here?

@petermattis petermattis changed the title WITH temp_data AS and recursion alternatives sql: WITH temp_data AS and recursion alternatives Apr 4, 2017
@jordanlewis
Copy link
Member

#7029 tracks the general common table expression implementation.

@timchunght
Copy link
Author

@petermattis Certainly, recursion is not easy to implement. We are trying to avoid having to do recursion, but might have to now. Hopefully these CTEs can be added soon. Thanks for clarifying.

@knz
Copy link
Contributor

knz commented Apr 5, 2017

So to clarify from the engineering perspective:

  • adding support for non-recursive CTEs is a relatively (compared to the next item, but still non-trivial) small change to our execution engine, which was already on our roadmap for one of the upcoming releases this year
  • adding support for recursive CTEs would imply a large rewriting of our execution engine, which we are considering already (it's needed for other features we plan too) but for which we can't set a timeline just yet. I don't think we can commit to a particular timeline unless a strong business case arises that would justify shuffling around our roadmap.

@jordanlewis
Copy link
Member

Closing as we now have #21085 to track recursive CTEs specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community
Projects
None yet
Development

No branches or pull requests

5 participants