From 81a7f6200d0563f7718ca0877fae4577f499c28d Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 14 Oct 2024 16:55:34 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #56614 Signed-off-by: ti-chi-bot --- .../handle/syncload/stats_syncload.go | 12 ++++--- .../core/issuetest/planner_issue.result | 35 +++++++++++++++++++ .../planner/core/issuetest/planner_issue.test | 28 +++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/pkg/statistics/handle/syncload/stats_syncload.go b/pkg/statistics/handle/syncload/stats_syncload.go index d21d3a76c5596..bbee5713b92fc 100644 --- a/pkg/statistics/handle/syncload/stats_syncload.go +++ b/pkg/statistics/handle/syncload/stats_syncload.go @@ -15,7 +15,7 @@ package syncload import ( - "fmt" + stderrors "errors" "math/rand" "runtime" "time" @@ -94,7 +94,6 @@ func (s *statsSyncLoad) SendLoadRequests(sc *stmtctx.StatementContext, neededHis } } }) - if len(remainedItems) <= 0 { return nil } @@ -352,6 +351,9 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err t := time.Now() needUpdate := false wrapper, err = s.readStatsForOneItem(sctx, item, wrapper, isPkIsHandle, task.Item.FullLoad) + if stderrors.Is(err, errGetHistMeta) { + return nil + } if err != nil { return err } @@ -371,6 +373,8 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err return nil } +var errGetHistMeta = errors.New("fail to get hist meta") + // readStatsForOneItem reads hist for one column/index, TODO load data via kv-get asynchronously func (*statsSyncLoad) readStatsForOneItem(sctx sessionctx.Context, item model.TableItemID, w *statsWrapper, isPkIsHandle bool, fullLoad bool) (*statsWrapper, error) { failpoint.Inject("mockReadStatsForOnePanic", nil) @@ -388,9 +392,9 @@ func (*statsSyncLoad) readStatsForOneItem(sctx sessionctx.Context, item model.Ta return nil, err } if hg == nil { - logutil.BgLogger().Error("fail to get hist meta for this histogram, possibly a deleted one", zap.Int64("table_id", item.TableID), + logutil.BgLogger().Warn("fail to get hist meta for this histogram, possibly a deleted one", zap.Int64("table_id", item.TableID), zap.Int64("hist_id", item.ID), zap.Bool("is_index", item.IsIndex)) - return nil, errors.Trace(fmt.Errorf("fail to get hist meta for this histogram, table_id:%v, hist_id:%v, is_index:%v", item.TableID, item.ID, item.IsIndex)) + return nil, errGetHistMeta } if item.IsIndex { isIndexFlag = 1 diff --git a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result index a56fab9dd5d75..f2e2baab5f3fc 100644 --- a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result +++ b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result @@ -718,3 +718,38 @@ Projection_11 6.00 root 1->Column#18 └─Projection_17(Probe) 10000.00 root cast(test.t61a85298.col_71, double BINARY)->Column#19 └─TableReader_19 10000.00 root data:TableFullScan_18 └─TableFullScan_18 10000.00 cop[tikv] table:t61a85298 keep order:false, stats:pseudo +<<<<<<< HEAD +======= +drop table if exists t0, t1; +CREATE TABLE t0(c0 int); +CREATE TABLE t1(c0 int); +SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0)); +c0 c0 +drop table if exists t1, t2, t3, t4; +CREATE TABLE t1 (a int, b int, c int); +CREATE TABLE t2 (a int, b int, c int); +CREATE TABLE t3 (a int, b int, c int); +CREATE TABLE t4 (a int, b int, c int); +INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0); +INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0); +INSERT INTO t3 VALUES (1,2,0), (2,2,0); +INSERT INTO t4 VALUES (3,2,0), (4,2,0); +CREATE INDEX idx_b ON t2(b); +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b +FROM (t3,t4) +LEFT JOIN +(t1,t2) +ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5; +a b a b a b +NULL NULL 2 2 3 2 +NULL NULL 2 2 4 2 +4 2 1 2 3 2 +4 2 1 2 3 2 +4 2 1 2 3 2 +4 2 1 2 4 2 +4 2 1 2 4 2 +4 2 1 2 4 2 +show warnings; +Level Code Message +drop table if exists t1, t2, t3, t4; +>>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614)) diff --git a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test index cf0bffe8e90f5..800d6c595a720 100644 --- a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test +++ b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test @@ -492,3 +492,31 @@ FROM ( ) AS derived_table WHERE 16739493649928310215 MEMBER OF (derived_table.col_60767) OR NOT (JSON_CONTAINS(derived_table.col_60767, '6019730272580550835')); +<<<<<<< HEAD +======= + +# TestIssue53766 +drop table if exists t0, t1; +CREATE TABLE t0(c0 int); +CREATE TABLE t1(c0 int); +SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0)); + +# TestIssue56472 +drop table if exists t1, t2, t3, t4; +CREATE TABLE t1 (a int, b int, c int); +CREATE TABLE t2 (a int, b int, c int); +CREATE TABLE t3 (a int, b int, c int); +CREATE TABLE t4 (a int, b int, c int); +INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0); +INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0); +INSERT INTO t3 VALUES (1,2,0), (2,2,0); +INSERT INTO t4 VALUES (3,2,0), (4,2,0); +CREATE INDEX idx_b ON t2(b); +SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b + FROM (t3,t4) + LEFT JOIN + (t1,t2) + ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5; +show warnings; +drop table if exists t1, t2, t3, t4; +>>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614)) From c303b57f6c43591d993705811f3fa33ac4bdc1c7 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 15 Oct 2024 10:26:42 +0800 Subject: [PATCH 2/2] update Signed-off-by: Weizhen Wang --- .../r/planner/core/issuetest/planner_issue.result | 8 -------- .../t/planner/core/issuetest/planner_issue.test | 9 --------- 2 files changed, 17 deletions(-) diff --git a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result index f2e2baab5f3fc..83c91f9f1a413 100644 --- a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result +++ b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result @@ -718,13 +718,6 @@ Projection_11 6.00 root 1->Column#18 └─Projection_17(Probe) 10000.00 root cast(test.t61a85298.col_71, double BINARY)->Column#19 └─TableReader_19 10000.00 root data:TableFullScan_18 └─TableFullScan_18 10000.00 cop[tikv] table:t61a85298 keep order:false, stats:pseudo -<<<<<<< HEAD -======= -drop table if exists t0, t1; -CREATE TABLE t0(c0 int); -CREATE TABLE t1(c0 int); -SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0)); -c0 c0 drop table if exists t1, t2, t3, t4; CREATE TABLE t1 (a int, b int, c int); CREATE TABLE t2 (a int, b int, c int); @@ -752,4 +745,3 @@ NULL NULL 2 2 4 2 show warnings; Level Code Message drop table if exists t1, t2, t3, t4; ->>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614)) diff --git a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test index 800d6c595a720..9c5364fcaced5 100644 --- a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test +++ b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test @@ -492,14 +492,6 @@ FROM ( ) AS derived_table WHERE 16739493649928310215 MEMBER OF (derived_table.col_60767) OR NOT (JSON_CONTAINS(derived_table.col_60767, '6019730272580550835')); -<<<<<<< HEAD -======= - -# TestIssue53766 -drop table if exists t0, t1; -CREATE TABLE t0(c0 int); -CREATE TABLE t1(c0 int); -SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0)); # TestIssue56472 drop table if exists t1, t2, t3, t4; @@ -519,4 +511,3 @@ SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5; show warnings; drop table if exists t1, t2, t3, t4; ->>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614))