Fix the crash that happens when using auto_explain extension with recursive queries (#6406)

This crash happens with recursively planned queries. For such queries,
subplans are explained via the ExplainOnePlan function of postgresql.
This function reconstructs the query description from the plan therefore
it expects the ActiveSnaphot for the query be available. This fix makes
sure that the snapshot is in the stack before calling ExplainOnePlan.

Fixes #2920.
fix-flaky-isolation_shard_move_vs_start_metadata_sync
Emel Şimşek 2022-10-19 18:04:45 +03:00 committed by GitHub
parent 737e2bb1bb
commit 02fd1e6c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -201,6 +201,13 @@ CitusExplainScan(CustomScanState *node, List *ancestors, struct ExplainState *es
ExplainOpenGroup("Distributed Query", "Distributed Query", true, es);
/*
* ExplainOnePlan function of postgres might be called in this codepath.
* It requires an ActiveSnapshot being set. Make sure to make ActiveSnapshot available before calling into
* Citus Explain functions.
*/
PushActiveSnapshot(executorState->es_snapshot);
if (distributedPlan->subPlanList != NIL)
{
ExplainSubPlans(distributedPlan, es);
@ -208,6 +215,8 @@ CitusExplainScan(CustomScanState *node, List *ancestors, struct ExplainState *es
ExplainJob(scanState, distributedPlan->workerJob, es, params);
PopActiveSnapshot();
ExplainCloseGroup("Distributed Query", "Distributed Query", true, es);
}