提交 cb53595f 编写于 作者: D Daniel Gustafsson

Prevent EXPLAIN DXL to return output in case of error

Commit ca4c29d4 removed the error
deferring from EXPLAIN such that it attempted to return results
even in case of errors, but missed the DXL case. This removes the
TRY/CATCH wraps from DXL EXPLAIN to match the rest of the EXPLAIN
code.

Also remove the last (found) callsite that expects that a palloc
for a statsbuffer can have returned NULL into an Assertion.
上级 fec843c3
......@@ -298,42 +298,32 @@ ExplainDXL(Query *query, ExplainState *es, const char *queryString,
{
MemoryContext oldcxt = CurrentMemoryContext;
bool save_enumerate;
char *dxl = NULL;
save_enumerate = optimizer_enumerate_plans;
/* Do the EXPLAIN. */
PG_TRY();
{
// enable plan enumeration before calling optimizer
optimizer_enumerate_plans = true;
// optimize query using optimizer and get generated plan in DXL format
char *dxl = SzDXLPlan(query);
/* enable plan enumeration before calling optimizer */
optimizer_enumerate_plans = true;
// restore old value of enumerate plans GUC
optimizer_enumerate_plans = save_enumerate;
/* optimize query using optimizer and get generated plan in DXL format */
dxl = SzDXLPlan(query);
if (dxl == NULL)
elog(NOTICE, "Optimizer failed to produce plan");
else
{
appendStringInfoString(es->str, dxl);
appendStringInfoChar(es->str, '\n'); /* separator line */
pfree(dxl);
}
/* restore old value of enumerate plans GUC */
optimizer_enumerate_plans = save_enumerate;
/* Free the memory we used. */
MemoryContextSwitchTo(oldcxt);
}
PG_CATCH();
if (dxl == NULL)
elog(NOTICE, "Optimizer failed to produce plan");
else
{
// restore old value of enumerate plans GUC
optimizer_enumerate_plans = save_enumerate;
/* Exit to next error handler. */
PG_RE_THROW();
appendStringInfoString(es->str, dxl);
appendStringInfoChar(es->str, '\n'); /* separator line */
pfree(dxl);
}
PG_END_TRY();
/* Free the memory we used. */
MemoryContextSwitchTo(oldcxt);
}
#endif
......
......@@ -1258,13 +1258,7 @@ ExecHashTableExplainEnd(PlanState *planstate, struct StringInfoData *buf)
stats = hashtable->stats;
/* Check batchstats not null: If nodeHash failed to palloc batchstats, it will
* throw. Postgres will catch and handle it, but no matter what, postgres will
* try to get some explain results. We must check here in this case or we will
* segv.
*/
if(stats->batchstats == NULL)
return;
Assert(stats->batchstats);
if (!hashtable->eagerlyReleased)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册