Avoid query deparse and planning of shard query in local execution. - #8035
Conversation
c8d3325 to
711873a
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8035 +/- ##
==========================================
+ Coverage 88.45% 89.04% +0.59%
==========================================
Files 284 284
Lines 61524 61689 +165
Branches 7698 7717 +19
==========================================
+ Hits 54423 54934 +511
+ Misses 4850 4509 -341
+ Partials 2251 2246 -5 🚀 New features to boost your workflow:
|
dc7f94d to
3cbcf40
Compare
Naisila Puka (naisila)
left a comment
There was a problem hiding this comment.
Thanks, LGTM.
Would be nice to provide the pgbench results in the PR description, that show the improvement when using this approach.
There was a problem hiding this comment.
Thanks for the PR, it looks good overall.
And just started reviewing this - probably just looked into a small portion of the files changed.
I'll continue reviewing this once I'm back on Wednesday but still sharing my quick and minor comments / questions.
|
|
||
|
|
||
| static bool | ||
| WarnIfLocalExecutionDisabled(bool *newval, void **extra, GucSource source) |
There was a problem hiding this comment.
Should we also add a similar warning check for citus.enable_local_execution?
Also, it can be better if we add a comment to the function as in:
/*
* WarnIfLocalExecutionDisabled is used to emit a warning message when
* enabling <new-GUC-name> if citus.enable_local_execution was disabled.
*/In general, we try to add comments (that start with the function name) on top of functions as much as possible.
There was a problem hiding this comment.
Should we also add a similar warning check for citus.enable_local_execution?
this was the only remaining part of above comment
There was a problem hiding this comment.
#8035 (comment)
Seems this is yet addressed, do you prefer to skip adding a similar check function for citus.enable_local_execution?
There was a problem hiding this comment.
#8035 (comment) Seems this is yet addressed, do you prefer to skip adding a similar check function for citus.enable_local_execution?
citus.enable_local_execution is explicitly used 50+ times in existing regress tests, and all associated goldfiles (.out) are impacted. Also, citus.enable_local_execution is also changed somewhere in EXPLAIN logic. So given this suggestion is having a broad impact on regress test output I'm omitting this.
Onur Tirtir (onurctirtir)
left a comment
There was a problem hiding this comment.
Done with code review, will need to test this a bit today.
6194621 to
377c7af
Compare
Onur Tirtir (onurctirtir)
left a comment
There was a problem hiding this comment.
LGTM, leaving just a few more suggestions if you see them helpful.
Also, not necessarily to be done in this PR but it might worth to add a few lines about this change in technical readme, maybe somewhere after the place where we mention fast path queries.
|
|
||
|
|
||
| static bool | ||
| WarnIfLocalExecutionDisabled(bool *newval, void **extra, GucSource source) |
There was a problem hiding this comment.
#8035 (comment)
Seems this is yet addressed, do you prefer to skip adding a similar check function for citus.enable_local_execution?
| !FindNodeMatchingCheckFunction( | ||
| (Node *) query, | ||
| CitusIsVolatileFunction); | ||
| } |
There was a problem hiding this comment.
maybe we can inform the user why we cannot use local fast path query optimizations when it's the case
| } | |
| } | |
| else if (!EnableLocalFastPathQueryOptimization) | |
| { | |
| // using debug2, log that we cannot use local fast path query optimizations because | |
| // citus.enable_local_fast_path_query_optimization was disabled | |
| } | |
| else if (!EnableLocalExecution) | |
| { | |
| // using debug2, log that we cannot use local fast path query optimizations because | |
| // citus.ebable_local_execution was disabled | |
| } | |
| else | |
| { | |
| // using debug2, log that we cannot use local fast path query optimizations because earlier in the | |
| // transaction a query / command accessed local shard placements via a remote connection | |
| // so local execution was implicitly disabled for the rest of the transaction | |
| } |
There was a problem hiding this comment.
I like this idea but deciding not to add because we don't have all the context here (InitializeFastPathContext()) and may give a misleading message, for example if its a reference table (which are unsupported) and either GUC is disabled, the user may think that enabling the GUC would make it work for reference tables and be puzzled why it does not. So I'm opting to pass on this rather than extend the function with all the needed context. Thanks for the suggestion though.
| WHERE a = 8 AND b IN (1,3,5,8,13,21) | ||
| GROUP BY b | ||
| ORDER BY b; | ||
|
|
There was a problem hiding this comment.
it might be nice if we can add a test for the case where we cannot apply the optimizations because earlier in the transaction local execution state was switched to "disabled" by Citus
| BEGIN; | |
| -- force accessing local placements via remote connections first | |
| SET citus.enable_local_execution TO false; | |
| SELECT * FROM test_tbl; | |
| -- Now, even if we enable local execution back before the query that | |
| -- could normally benefit from fast path local query optimizations, | |
| -- this time it won't be the case because local execution was implicitly | |
| -- disabled by Citus as we accessed local shard placements via remote | |
| -- connections. | |
| SET citus.enable_local_execution TO true; | |
| SELECT b, AVG(data_f), MIN(data_f), MAX(data_f), COUNT(1) | |
| FROM test_tbl | |
| WHERE a = 8 AND b IN (1,3,5,8,13,21) | |
| GROUP BY b | |
| ORDER BY b; | |
| COMMIT; |
There was a problem hiding this comment.
Thanks for the suggestion - have added it to local_execution_local_plan.sql
865d9d2 to
ef8cfdb
Compare
If a fast past query resolves to a shard that is local to the node planning the query, a shortcut can be taken so that the OID of the shard is plugged into the parse tree, which is then put through the Postgres planner. The task query uses that plan instead of deparsing and compiling a shard query.
ef8cfdb to
a37cc1a
Compare
DESCRIPTION: Adds citus.enable_local_fast_path_query_optimization (enabled by default) GUC to avoid unnecessary query deparsing to improve performance of fast-path queries targeting local shards
Avoid query deparse and planning of shard query in local execution.
If a fast path query resolves to a shard that is local to the node planning the query, a shortcut can be taken so that the OID of the shard is plugged into the parse tree, which is then planned by Postgres. In
local_executor.cthe task uses that plan instead of parsing and planning a shard query. How this is done: The fast path planner identifies if the shortcut is possible, and then the distributed planner checks, usingCheckAndBuildDelayedFastPathPlan(), if a local plan can be generated or if the shard query should be generated.This optimization is controlled by a GUC
citus.enable_local_execution_local_planwhich is on by default. A new regress testlocal_execution_local_plantests both row-sharding and schema sharding. Negative tests are added tolocal_shard_execution_dropped_columnto verify that the optimization is not taken when the shard is local but there is a difference between the shard and distributed table because of a dropped column.