You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/12/27 12:54:00 UTC

[GitHub] [arrow-datafusion] xudong963 opened a new pull request #1492: subquery rfc

xudong963 opened a new pull request #1492:
URL: https://github.com/apache/arrow-datafusion/pull/1492


   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] xudong963 removed a comment on pull request #1492: subquery rfc

Posted by GitBox <gi...@apache.org>.
xudong963 removed a comment on pull request #1492:
URL: https://github.com/apache/arrow-datafusion/pull/1492#issuecomment-1001601467


   Thanks, @Dandandan , I am speeding up the completion of this design document


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] xudong963 commented on pull request #1492: subquery rfc

Posted by GitBox <gi...@apache.org>.
xudong963 commented on pull request #1492:
URL: https://github.com/apache/arrow-datafusion/pull/1492#issuecomment-1001601467


   Thanks, @Dandandan , I am speeding up the completion of this design document


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] alamb commented on pull request #1492: subquery rfc

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #1492:
URL: https://github.com/apache/arrow-datafusion/pull/1492#issuecomment-1040676450


   Closing stale PRs. Please reopen (or open a new one) if you plan to keep working on this feature. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] xudong963 commented on a change in pull request #1492: subquery rfc

Posted by GitBox <gi...@apache.org>.
xudong963 commented on a change in pull request #1492:
URL: https://github.com/apache/arrow-datafusion/pull/1492#discussion_r776359498



##########
File path: docs/rfcs/subquery_design.md
##########
@@ -0,0 +1,108 @@
+<!---
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+    http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+Feature Name: subquery
+
+Status: in-progress
+
+Start Date: 2021-12-27
+
+Authors: xudong.w
+
+RFC PR: #1373
+
+Datafusion Issue: #1209
+
+---
+
+### Background
+Datafusion currently only supports subquery in `from`.
+Almost all of the tpch queries that datafusion currently fails are due to unsupported subqueries, such as `exist subquery`, `scalar subquery`.
+To improve the integrity of Datafusion SQL support, and through all TPCH cases, more complete subquery support is needed.
+
+---
+
+### Goals
+1. Support the `Scalar subquery`.
+2. Support the `Exist/Not Exist subquery`.
+3. Support the `In/Not In subquery`.
+4. Support the `Any/Some/All subquery`, currently sqlparser doesn't support Any/AllSubquery expr, I opened an issue to trace. [support Any/AllSubquery exprs](https://github.com/sqlparser-rs/sqlparser-rs/issues/394)
+5. Support the non-correlation subquery and correlation subquery
+
+---
+
+### Non-Goals
+1. Correlation subquery doesn't use a more complex solution to do decorrelation, for this design, I'll use nest-loop to do decorrelation.
+I'll provide some materials about more advanced decorrelation, and we can research them and optimize in subsequent iterations.
+2. Some unusual subqueries won't be supported, such as list subqueries.
+---
+
+### Survey
+
+#### PostgreSQL
+In postgresql, subqueries are classified into sublink and subquery based on where they appear. Sublink occurs in constraints such as WHERE/ON.
+Postgres will try to pull up sublink if possible, the relevant code is in `pull_up_sublinks_jointree_recurse` function. If pull up succeeds, sublink will be converted to join.
+- [NOT IN] -> [Anti] Semi Join
+- [ANY/SOME] -> Semi Join
+- [NOT EXISTS] -> [Anti] Semi Join
+
+**Note that not all sublinks can be pulled up**. Only some simple sublink queries can be pulled up. If contains aggregate functions, sublink won't be pulled up, then there will be a `SubPlan` in `Query Plan` and the upper execution plan and the subquery plan do nested loops to get the final result.
+
+Subqueries and sublinks have similar processing logic, except they are in different locations of queries
+
+
+#### CockroachDB
+The cockroach's subquery design draws on the ideas in this [paper](https://dl.acm.org/doi/10.1145/1247480.1247598), you can see it to learn more details.
+That's the [decorrelation rules](https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/opt/norm/rules/decorrelate.opt) of the cockroach.
+
+#### Materialize
+Materialize is a streaming system with incremental backend. This backend does not support nested loops, so it has to be able to handle all decorrelation cases. 
+Materialize's subquery implementation should be the most complete. This [paper](https://cs.emis.de/LNI/Proceedings/Proceedings241/383.pdf) is relevant to their implementation. The paper is a little indigestible, so I didn't deep into it.
+
+---
+
+### Design
+Let's turn our attention to Datafusion.
+
+There are two overall steps:
+1. transfer sqlparser subquery exprs to datafusion exprs.

Review comment:
       `sql_expr_to_logical_expr` function in datafusion/src/sql/planner.rs




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] Dandandan commented on a change in pull request #1492: subquery rfc

Posted by GitBox <gi...@apache.org>.
Dandandan commented on a change in pull request #1492:
URL: https://github.com/apache/arrow-datafusion/pull/1492#discussion_r775513155



##########
File path: docs/rfcs/subquery_design.md
##########
@@ -0,0 +1,106 @@
+<!---
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+    http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+Feature Name: subquery
+
+Status: in-progress
+
+Start Date: 2021-12-27
+
+Authors: xudong.w
+
+RFC PR: #1373
+
+Datafusion Issue: #1209
+
+---
+
+### BackGround
+Datafusion currently only supports subquery in `from`.
+Almost all of the tpch queries that datafusion currently fails are due to unsupported subqueries, such as `exist subquery`, `scalar subquery`.
+To improve the integrity of Datafusion SQL support, and through all TPCH cases, more complete subquery support is needed.
+
+---
+
+### Goals
+1. Support the `Scalar subquery`.
+2. Support the `Exist/Not Exist subquery`.
+3. Support the `In/Not In subquery`.
+4. Support the `Any/Some/All subquery`, currently sqlparser doesn't support Any/AllSubquery expr, I opened an issue to trace. [support Any/AllSubquery exprs](https://github.com/sqlparser-rs/sqlparser-rs/issues/394)
+5. Support the non-correlation subquery and correlation subquery
+
+---
+
+### Non-Goals
+1. Correlation subquery doesn't use a more complex solution to do decorrelation, for this design, I'll use nest-loop to do decorrelation.
+I'll provide some materials about more advanced decorrelation, and we can research them and optimize in subsequent iterations.
+2. Some unusual subqueries won't be supported, such as list subqueries.
+---
+
+### Survey
+
+#### postgresql
+In postgresql, subqueries are classified into sublink and subquery based on where they appear. Sublink occurs in constraints such as WHERE/ON.
+Postgres will try to pull up sublink if possible, the relevant code is in `pull_up_sublinks_jointree_recurse` function. If pull up succeeds, sublink will be converted to join.
+- [NOT IN] -> [Anti] Semi Join
+- [ANY/SOME] -> Semi Join
+- [NOT EXISTS] -> [Anti] Semi Join
+
+**Note that not all sublinks can be pulled up**. Only some simple sublink queries can be pulled up. If contains aggregate functions, sublink won't be pulled up, then there will be a `SubPlan` in `Query Plan` and the upper execution plan and the subquery plan do nested loops to get the final result.
+
+Subqueries and sublinks have similar processing logic, except they are in different locations of queries
+
+
+#### cockroach
+The cockroach's subquery design draws on the ideas in this [paper](https://dl.acm.org/doi/10.1145/1247480.1247598), you can see it to learn more details.
+That's the [decorrelation rules](https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/opt/norm/rules/decorrelate.opt) of the cockroach.
+
+#### materialize

Review comment:
       ```suggestion
   #### Materialize
   ```
   

##########
File path: docs/rfcs/subquery_design.md
##########
@@ -0,0 +1,106 @@
+<!---
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+    http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+Feature Name: subquery
+
+Status: in-progress
+
+Start Date: 2021-12-27
+
+Authors: xudong.w
+
+RFC PR: #1373
+
+Datafusion Issue: #1209
+
+---
+
+### BackGround
+Datafusion currently only supports subquery in `from`.
+Almost all of the tpch queries that datafusion currently fails are due to unsupported subqueries, such as `exist subquery`, `scalar subquery`.
+To improve the integrity of Datafusion SQL support, and through all TPCH cases, more complete subquery support is needed.
+
+---
+
+### Goals
+1. Support the `Scalar subquery`.
+2. Support the `Exist/Not Exist subquery`.
+3. Support the `In/Not In subquery`.
+4. Support the `Any/Some/All subquery`, currently sqlparser doesn't support Any/AllSubquery expr, I opened an issue to trace. [support Any/AllSubquery exprs](https://github.com/sqlparser-rs/sqlparser-rs/issues/394)
+5. Support the non-correlation subquery and correlation subquery
+
+---
+
+### Non-Goals
+1. Correlation subquery doesn't use a more complex solution to do decorrelation, for this design, I'll use nest-loop to do decorrelation.
+I'll provide some materials about more advanced decorrelation, and we can research them and optimize in subsequent iterations.
+2. Some unusual subqueries won't be supported, such as list subqueries.
+---
+
+### Survey
+
+#### postgresql
+In postgresql, subqueries are classified into sublink and subquery based on where they appear. Sublink occurs in constraints such as WHERE/ON.
+Postgres will try to pull up sublink if possible, the relevant code is in `pull_up_sublinks_jointree_recurse` function. If pull up succeeds, sublink will be converted to join.
+- [NOT IN] -> [Anti] Semi Join
+- [ANY/SOME] -> Semi Join
+- [NOT EXISTS] -> [Anti] Semi Join
+
+**Note that not all sublinks can be pulled up**. Only some simple sublink queries can be pulled up. If contains aggregate functions, sublink won't be pulled up, then there will be a `SubPlan` in `Query Plan` and the upper execution plan and the subquery plan do nested loops to get the final result.
+
+Subqueries and sublinks have similar processing logic, except they are in different locations of queries
+
+
+#### cockroach

Review comment:
       ```suggestion
   #### CockroachDB
   ```
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] alamb closed pull request #1492: subquery rfc

Posted by GitBox <gi...@apache.org>.
alamb closed pull request #1492:
URL: https://github.com/apache/arrow-datafusion/pull/1492


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] hntd187 commented on a change in pull request #1492: subquery rfc

Posted by GitBox <gi...@apache.org>.
hntd187 commented on a change in pull request #1492:
URL: https://github.com/apache/arrow-datafusion/pull/1492#discussion_r775582714



##########
File path: docs/rfcs/subquery_design.md
##########
@@ -0,0 +1,108 @@
+<!---
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+    http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+Feature Name: subquery
+
+Status: in-progress
+
+Start Date: 2021-12-27
+
+Authors: xudong.w
+
+RFC PR: #1373
+
+Datafusion Issue: #1209
+
+---
+
+### Background
+Datafusion currently only supports subquery in `from`.
+Almost all of the tpch queries that datafusion currently fails are due to unsupported subqueries, such as `exist subquery`, `scalar subquery`.
+To improve the integrity of Datafusion SQL support, and through all TPCH cases, more complete subquery support is needed.
+
+---
+
+### Goals
+1. Support the `Scalar subquery`.
+2. Support the `Exist/Not Exist subquery`.
+3. Support the `In/Not In subquery`.
+4. Support the `Any/Some/All subquery`, currently sqlparser doesn't support Any/AllSubquery expr, I opened an issue to trace. [support Any/AllSubquery exprs](https://github.com/sqlparser-rs/sqlparser-rs/issues/394)
+5. Support the non-correlation subquery and correlation subquery
+
+---
+
+### Non-Goals
+1. Correlation subquery doesn't use a more complex solution to do decorrelation, for this design, I'll use nest-loop to do decorrelation.
+I'll provide some materials about more advanced decorrelation, and we can research them and optimize in subsequent iterations.
+2. Some unusual subqueries won't be supported, such as list subqueries.
+---
+
+### Survey
+
+#### PostgreSQL
+In postgresql, subqueries are classified into sublink and subquery based on where they appear. Sublink occurs in constraints such as WHERE/ON.
+Postgres will try to pull up sublink if possible, the relevant code is in `pull_up_sublinks_jointree_recurse` function. If pull up succeeds, sublink will be converted to join.
+- [NOT IN] -> [Anti] Semi Join
+- [ANY/SOME] -> Semi Join
+- [NOT EXISTS] -> [Anti] Semi Join
+
+**Note that not all sublinks can be pulled up**. Only some simple sublink queries can be pulled up. If contains aggregate functions, sublink won't be pulled up, then there will be a `SubPlan` in `Query Plan` and the upper execution plan and the subquery plan do nested loops to get the final result.
+
+Subqueries and sublinks have similar processing logic, except they are in different locations of queries
+
+
+#### CockroachDB
+The cockroach's subquery design draws on the ideas in this [paper](https://dl.acm.org/doi/10.1145/1247480.1247598), you can see it to learn more details.
+That's the [decorrelation rules](https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/opt/norm/rules/decorrelate.opt) of the cockroach.
+
+#### Materialize
+Materialize is a streaming system with incremental backend. This backend does not support nested loops, so it has to be able to handle all decorrelation cases. 
+Materialize's subquery implementation should be the most complete. This [paper](https://cs.emis.de/LNI/Proceedings/Proceedings241/383.pdf) is relevant to their implementation. The paper is a little indigestible, so I didn't deep into it.
+
+---
+
+### Design
+Let's turn our attention to Datafusion.
+
+There are two overall steps:
+1. transfer sqlparser subquery exprs to datafusion exprs.

Review comment:
       Do you mean something like an `Into<Expr>` impl or something of the sort on the datafusion side?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] alamb commented on pull request #1492: subquery rfc

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #1492:
URL: https://github.com/apache/arrow-datafusion/pull/1492#issuecomment-1026192210


   Marking PRs without activity in the last month as stale. I'll plan to close it in another month or so without activity, though feel free to reopen it when you have time to work on it)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org