-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Add Join Predicate Pushdown in CTE to improve the performance and reduce OOM in TiDB #28163
Comments
I'm doing some research to optimize CTE(both non-recursive and recursive). For now, I'm planning to implement predicate-pushdown, to make TPC-DS work with all CTE queries. |
Oh, can't wait to see it! I'm a big fan of CTE and just fed up with the OOM things. I have reported two OOM issues this week. |
According to your SQL, I think inlining is more efficient since the CTE is used only once. |
|
I mean that we can use inling to implement CTE instead of materialization. |
Oh, Oracle can decide to use inlining or materialization according to the cost. Maybe we can implement something like this. |
Enhancement
The VIEW PUSHED PREDICATE operation is a specific kind of predicate pushing, the join predicate pushdown transformation, which means "The view thus becomes correlated and must be evaluated for each row of the outer query block".
The idea behind that transformation is that the view may need to be executed more frequently, but adding the join predicate to the view can make it run much faster, since the tables in that view can now use an index access.
TiDB has implemented this kind of predicate pushing for SQL written with in-line view. For example:
We can see that the predicates n.id = 420015 and n.query_name = '10C' was pushed into the two in-line views.
However, if I rewrote the SQL statement with CTE, I got the following plan and what's worse, the execution failed with OOM:
And the expected plan should be like this:
Therefore, the Join Predicate Pushdown should be implemented for CTE to improve the performance and reduce OOM in TiDB.
The text was updated successfully, but these errors were encountered: