diff --git a/pkg/executor/cte.go b/pkg/executor/cte.go index 48d143a4f87b7..4c30243268821 100644 --- a/pkg/executor/cte.go +++ b/pkg/executor/cte.go @@ -266,7 +266,10 @@ func (p *cteProducer) closeProducer() (firstErr error) { firstErr = setFirstErr(firstErr, err, "deref iterOutTbl err") } } - p.resetTracker() + // Reset to nil instead of calling Detach(), + // because ExplainExec still needs tracker to get mem usage info. + p.memTracker = nil + p.diskTracker = nil p.closed = true return }