-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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/parser: Walk never traverses subqueries in a FROM clause #9952
Comments
We have a subquery visitor which finds all subqueries, executes them as separate statements, and replaces them with a VALUES node with the results. |
Radu: I don't think we want to do that for the purpose of preparing the query string to be stored in the view descriptor. Alex: we should distinguish the issues here:
Regarding point (2) above. The semantic analysis is currently done on sub-clauses as part of the So the problem you have for #9921 is really that all the normalization work, including table name normalization for views, is currently done as part of the planNode recursive construction. So you thought about invoking the Walk mechanism instead to do this normalization. This is fair, but perhaps you are under-estimating how much work is needed to do this properly. Namely the entire So then where to go from here? Just so you know we had a short discussion today at the office to try to tackle this issue, between others. There's actually a laundry list of issues similar to yours here that could really use a semantic analysis phase separate from the planNode construction. This analysis would resolve names between other things and annotate normalized names into the syntax tree, so that you can get the information you need directly for the view descriptor. This is basically the comprehensive extension of the idea you propose above. We can talk about it if you wish. However I fear it will take a few week before we get there. I am not sure we can do much better in a short term solution. Extending Walk to resolve names would introduce code duplication with that the planNode constructor currently does, and even if that was acceptable it would still be some effort. I'll let the other guys chime in and perhaps even @petermattis would have an opinion on this. |
To be clear, I wasn't suggesting anything, I was just clarifying how existing stuff works. |
I see, thanks for the explanation. It seems strange to me that the use of Walk and planNode construction are as intermingled as they are already, but I'm presumably missing a lot of background context and haven't read all the code. Introducing more duplication there doesn't sound particularly appealing to me. I take it that the Format() approach I mentioned in the other issue isn't feasible because it doesn't have enough info to properly resolve the table, right? I mean, we could pass a closure into Format that replicates the logic in getDataSource, but I don't know if that's going too far off the rails. I think I'll need to talk to you about this unless someone has a different proposal. |
The reason why things are the way they are now is organic growth from a much simpler starting point. It's fair to want something else and I think we've reached a tipping point this week with enough impetus gathered to make it happen. |
I'm going to close this, as the original issue was primarily a misunderstanding. I've sent out #10026 to try and prevent future misunderstandings of the sort. Feel free to reopen this if you want to adopt it for a related purpose. |
It looks like this is preventing things like normalization and type checking from taking effect on subqueries in a FROM clause, i.e.
select foo from (SUBQUERY GOES HERE);
. The parser.Walk code seems to assume that there's nothing of interest in FROM clauses other than AS OF expressions. I've verified with a dumb Visitor (that simply prints each Expr's type) that the Subquery is never reached when running Walk over such queries.I can fix this up while resolving #9921, but I'm curious what approach you guys like. The most tempting option to me is making the TableExpr interface satisfy the Expr interface and adding Walk methods for the structs that implement TableExpr, which will make adding the DB name normalization walker for #9921 easier, but thinking about that use may be biasing me.
@knz @RaduBerinde @nvanbenschoten
The text was updated successfully, but these errors were encountered: