-
Notifications
You must be signed in to change notification settings - Fork 200
Set join_collapse_limit default value to 13 #1525
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
Conversation
|
I suggest join_collapse_limit=8 to reduce the difference from PostgreSQL 14, but you can consider slightly larger values. In the table below there are time and memory consumption to process the query from the test.
Query processing time was got using |
Thank you such interesting research! I would suggest setting join_collapse_limit to 13 or 14 for your choice. I agree, 20 is too much, but 8 is also too small. The reason is to exchange execution time for planning time and free memory (on the master). However, the master has its own limitations. Join_collapse_limit should be set to a value that prevents exhaustion of resources by a single user. Typically, even test/development installations have 8 GB of free memory space. I'm not sure about 22 GB; it seems quite large. I have seen many dev/test instances with 10 GB to 16 GB of free memory space. |
I have replaced 8 with 13. 14 is too high, because in this case I get |
Smyatkin-Maxim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for anything between 12 and 13
I’m surprised that the planner consumes so much memory — typically it uses very little. Your test results are surprising to me. Could you share the complete test setup so others can reproduce it? Another point is that this parameter is intended to generate better query plans. Reducing it could lead to worse plans. Memory usage during the planning phase is usually negligible compared to execution memory. We need to verify in standard benchmarks whether lowering this parameter causes any performance regression. Typically, we should test it with TPCDS at 1TB scale. |
I ran queries on standard demo cluster. OS: Ubuntu 22.04.5 |
Thank you for sharing the test case—I was able to reproduce the issue. Indeed, the planner does become very slow in this scenario. The reason is that with 20 tables joined purely via inner joins and no restrictions (such as LEFT JOIN), the join order can be rearranged arbitrarily. In GPDB and our Cloudberry, join ordering relies on dynamic programming for search. Consider the number of possible join permutations with 20 tables—this becomes extremely costly. This highlights a fundamental limitation: unlike upstream PostgreSQL, which can fall back to genetic algorithm-based join search when the number of joins exceeds a threshold, we currently do not inherit that mechanism. I recall this topic was previously discussed with @reshke I appreciate you raising this. Overall, I’m supportive of exploring adjustments here. The current default of Therefore, before moving forward, I recommend we validate this change with a TPCDS 1T benchmark (using AOCO tables). If no plan changes are observed, I have no objection. If we can identify a better-performing setting through such testing, that would be even more valuable. |
Based on my manual review of all 99 TPC-DS queries, I have confirmed that Query 72 contains the highest number of explicit JOINs: 11 tables with 10 JOIN operations, which is below the value modified in your PR. Therefore, this change should theoretically have no impact on query planning for explicit joins. Regarding queries with a higher number of table references, such as Query 64, which lists over 18 tables in its FROM clause, these are presented as a This change looks good to me, thanks, |
cf638b4 to
6f095e0
Compare
…QL 14 The default value of join_collapse_limit was 20. When this value is set and the query contains about 20 joins (see added test), Postgres query optimizer cannot build a plan during hours and consumes a lot of memory, because the planner checks a lot of possible ways to join the tables. When join_collapse_limit is 8, the query plan is built in reasonable time.
7215bbb to
32061ee
Compare
The default value of join_collapse_limit was 20. When this value is set and
the query contains about 20 joins (see added test), Postgres query optimizer
cannot build a plan during hours and consumes a lot of memory, because the
planner checks a lot of possible ways to join the tables.
When join_collapse_limit is 13, the query plan is built in reasonable time.