From a400cb47f2af99162dbcd7c6b33aa4ca730d8840 Mon Sep 17 00:00:00 2001
From: nnsgmsone <nnsmgsone@outlook.com>
Date: Thu, 18 Aug 2022 17:42:25 +0800
Subject: [PATCH] Fix the bug of avg (#4576)

Approved by: @yingfeng
---
 pkg/sql/colexec/agg/avg/avg.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pkg/sql/colexec/agg/avg/avg.go b/pkg/sql/colexec/agg/avg/avg.go
index ddc68cd21..2d81328fa 100644
--- a/pkg/sql/colexec/agg/avg/avg.go
+++ b/pkg/sql/colexec/agg/avg/avg.go
@@ -126,7 +126,7 @@ func (a *Decimal64Avg) BatchFill(rs, vs any, start, count int64, vps []uint64, z
 			continue
 		}
 		j := vps[i] - 1
-		a.cnts[j] += zs[j]
+		a.cnts[j] += zs[i+start]
 	}
 	return nil
 }
@@ -180,7 +180,7 @@ func (a *Decimal128Avg) BatchFill(rs, vs any, start, count int64, vps []uint64,
 			continue
 		}
 		j := vps[i] - 1
-		a.cnts[j] += zs[j]
+		a.cnts[j] += zs[i+start]
 	}
 	return nil
 }
-- 
GitLab