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 26f086d1d7e4b..d5bc8ced2167f 100644 --- a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result +++ b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result @@ -723,3 +723,30 @@ 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; diff --git a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test index 00cfa31d3c392..679cf8cb6c767 100644 --- a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test +++ b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test @@ -498,3 +498,22 @@ 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;