From 5cfe959c42c0a1c0c231697e8acda30478e08bc9 Mon Sep 17 00:00:00 2001 From: yisaer Date: Mon, 30 Jan 2023 14:05:34 +0800 Subject: [PATCH 1/6] fix 40843 --- bindinfo/bind_record.go | 14 ++++++++++++++ bindinfo/handle.go | 7 ++++++- executor/show.go | 6 ++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/bindinfo/bind_record.go b/bindinfo/bind_record.go index 6395bbaa278ba..0b5ec71fdfd21 100644 --- a/bindinfo/bind_record.go +++ b/bindinfo/bind_record.go @@ -115,6 +115,20 @@ type BindRecord struct { Bindings []Binding } +// Copy get the copy of bindRecord +func (br *BindRecord) Copy() *BindRecord { + nbr := &BindRecord{ + OriginalSQL: br.OriginalSQL, + Db: br.Db, + } + nbr.Bindings = make([]Binding, 0, len(br.Bindings)) + for i, binding := range br.Bindings { + // TODO: support binding copy + nbr.Bindings[i] = binding + } + return nbr +} + // HasEnabledBinding checks if there are any enabled bindings in bind record. func (br *BindRecord) HasEnabledBinding() bool { for _, binding := range br.Bindings { diff --git a/bindinfo/handle.go b/bindinfo/handle.go index 59919e2b5ad85..f023cc263d812 100644 --- a/bindinfo/handle.go +++ b/bindinfo/handle.go @@ -1129,7 +1129,12 @@ const ( func (h *BindHandle) getOnePendingVerifyJob() (string, string, Binding) { cache := h.bindInfo.Value.Load().(*bindCache) - for _, bindRecord := range cache.GetAllBindRecords() { + tmp := cache.GetAllBindRecords() + bindRecords := make([]*BindRecord, 0, len(tmp)) + for i, bindRecord := range tmp { + bindRecords[i] = bindRecord.Copy() + } + for _, bindRecord := range bindRecords { for _, bind := range bindRecord.Bindings { if bind.Status == PendingVerify { return bindRecord.OriginalSQL, bindRecord.Db, bind diff --git a/executor/show.go b/executor/show.go index 36a9b8485822b..5da5f78493479 100644 --- a/executor/show.go +++ b/executor/show.go @@ -69,7 +69,6 @@ import ( "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/sem" "github.com/pingcap/tidb/util/set" - "github.com/pingcap/tidb/util/slice" "github.com/pingcap/tidb/util/sqlexec" "github.com/pingcap/tidb/util/stringutil" "golang.org/x/exp/slices" @@ -317,7 +316,10 @@ func (e *ShowExec) fetchShowBind() error { } else { tmp = domain.GetDomain(e.ctx).BindHandle().GetAllBindRecord() } - bindRecords := slice.Copy(tmp) + bindRecords := make([]*bindinfo.BindRecord, 0, len(tmp)) + for i, bindRecord := range tmp { + bindRecords[i] = bindRecord.Copy() + } // Remove the invalid bindRecord. ind := 0 for _, bindData := range bindRecords { From 304b6e03e94bc0e415f1f75a901bd54b3ace48c6 Mon Sep 17 00:00:00 2001 From: yisaer Date: Mon, 30 Jan 2023 14:15:49 +0800 Subject: [PATCH 2/6] fix 40843 --- bindinfo/bind_record.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bindinfo/bind_record.go b/bindinfo/bind_record.go index 0b5ec71fdfd21..536016a51783b 100644 --- a/bindinfo/bind_record.go +++ b/bindinfo/bind_record.go @@ -121,11 +121,7 @@ func (br *BindRecord) Copy() *BindRecord { OriginalSQL: br.OriginalSQL, Db: br.Db, } - nbr.Bindings = make([]Binding, 0, len(br.Bindings)) - for i, binding := range br.Bindings { - // TODO: support binding copy - nbr.Bindings[i] = binding - } + copy(nbr.Bindings, br.Bindings) return nbr } From 76d96b97dc298785f3a16a63c5898530e8950050 Mon Sep 17 00:00:00 2001 From: yisaer Date: Mon, 30 Jan 2023 14:36:25 +0800 Subject: [PATCH 3/6] fix 40843 --- executor/BUILD.bazel | 1 - 1 file changed, 1 deletion(-) diff --git a/executor/BUILD.bazel b/executor/BUILD.bazel index 8b0e824288c99..c8881bec70917 100644 --- a/executor/BUILD.bazel +++ b/executor/BUILD.bazel @@ -192,7 +192,6 @@ go_library( "//util/servermemorylimit", "//util/set", "//util/size", - "//util/slice", "//util/sqlexec", "//util/stmtsummary", "//util/stringutil", From f64e05ab489f314e39320deb0316f60b6ad8b37e Mon Sep 17 00:00:00 2001 From: yisaer Date: Mon, 30 Jan 2023 15:14:12 +0800 Subject: [PATCH 4/6] fix 40843 --- bindinfo/handle.go | 6 +++--- executor/show.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bindinfo/handle.go b/bindinfo/handle.go index f023cc263d812..ef859a6372e5a 100644 --- a/bindinfo/handle.go +++ b/bindinfo/handle.go @@ -1130,9 +1130,9 @@ const ( func (h *BindHandle) getOnePendingVerifyJob() (string, string, Binding) { cache := h.bindInfo.Value.Load().(*bindCache) tmp := cache.GetAllBindRecords() - bindRecords := make([]*BindRecord, 0, len(tmp)) - for i, bindRecord := range tmp { - bindRecords[i] = bindRecord.Copy() + bindRecords := make([]*BindRecord, 0) + for _, bindRecord := range tmp { + bindRecords = append(bindRecords, bindRecord.Copy()) } for _, bindRecord := range bindRecords { for _, bind := range bindRecord.Bindings { diff --git a/executor/show.go b/executor/show.go index 5da5f78493479..130f743d914bb 100644 --- a/executor/show.go +++ b/executor/show.go @@ -316,9 +316,9 @@ func (e *ShowExec) fetchShowBind() error { } else { tmp = domain.GetDomain(e.ctx).BindHandle().GetAllBindRecord() } - bindRecords := make([]*bindinfo.BindRecord, 0, len(tmp)) - for i, bindRecord := range tmp { - bindRecords[i] = bindRecord.Copy() + bindRecords := make([]*bindinfo.BindRecord, 0) + for _, bindRecord := range tmp { + bindRecords = append(bindRecords, bindRecord.Copy()) } // Remove the invalid bindRecord. ind := 0 From b4c641cb484bac7a8cf303d98ab530250d02e4c8 Mon Sep 17 00:00:00 2001 From: yisaer Date: Mon, 30 Jan 2023 15:58:01 +0800 Subject: [PATCH 5/6] fix 40843 --- bindinfo/handle.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bindinfo/handle.go b/bindinfo/handle.go index ef859a6372e5a..59919e2b5ad85 100644 --- a/bindinfo/handle.go +++ b/bindinfo/handle.go @@ -1129,12 +1129,7 @@ const ( func (h *BindHandle) getOnePendingVerifyJob() (string, string, Binding) { cache := h.bindInfo.Value.Load().(*bindCache) - tmp := cache.GetAllBindRecords() - bindRecords := make([]*BindRecord, 0) - for _, bindRecord := range tmp { - bindRecords = append(bindRecords, bindRecord.Copy()) - } - for _, bindRecord := range bindRecords { + for _, bindRecord := range cache.GetAllBindRecords() { for _, bind := range bindRecord.Bindings { if bind.Status == PendingVerify { return bindRecord.OriginalSQL, bindRecord.Db, bind From 8c14f9d78bd3f8235e81afb5d22fbc2f263f47a2 Mon Sep 17 00:00:00 2001 From: yisaer Date: Mon, 30 Jan 2023 17:10:49 +0800 Subject: [PATCH 6/6] fix 40843 --- bindinfo/bind_record.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bindinfo/bind_record.go b/bindinfo/bind_record.go index 536016a51783b..50e8e0ba20784 100644 --- a/bindinfo/bind_record.go +++ b/bindinfo/bind_record.go @@ -121,6 +121,7 @@ func (br *BindRecord) Copy() *BindRecord { OriginalSQL: br.OriginalSQL, Db: br.Db, } + nbr.Bindings = make([]Binding, len(br.Bindings)) copy(nbr.Bindings, br.Bindings) return nbr }