From cfc9cd68b79e8443b5fd128688943f575a96bc59 Mon Sep 17 00:00:00 2001
From: crazycs520 <crazycs520@gmail.com>
Date: Mon, 31 Oct 2022 13:13:48 +0800
Subject: [PATCH] executor: add memory track in handle cop request

Signed-off-by: crazycs520 <crazycs520@gmail.com>
---
 executor/coprocessor.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/executor/coprocessor.go b/executor/coprocessor.go
index 8970629c9f4b8..323abe865425e 100644
--- a/executor/coprocessor.go
+++ b/executor/coprocessor.go
@@ -63,6 +63,7 @@ func (h *CoprocessorDAGHandler) HandleRequest(ctx context.Context, req *coproces
 	chk := newFirstChunk(e)
 	tps := e.base().retFieldTypes
 	var totalChunks, partChunks []tipb.Chunk
+	memTracker := h.sctx.GetSessionVars().StmtCtx.MemTracker
 	for {
 		chk.Reset()
 		err = Next(ctx, e, chk)
@@ -76,6 +77,9 @@ func (h *CoprocessorDAGHandler) HandleRequest(ctx context.Context, req *coproces
 		if err != nil {
 			return h.buildErrorResponse(err)
 		}
+		for _, ch := range partChunks {
+			memTracker.Consume(int64(ch.Size()))
+		}
 		totalChunks = append(totalChunks, partChunks...)
 	}
 	if err := e.Close(); err != nil {