Skip to content

Commit 10647c9

Browse files
authored
statstics: avoid unnecessary try when to sync load (#56614)
close #56472
1 parent ca8d322 commit 10647c9

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

pkg/statistics/handle/syncload/stats_syncload.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package syncload
1616

1717
import (
18-
"fmt"
18+
stderrors "errors"
1919
"math/rand"
2020
"runtime"
2121
"time"
@@ -94,7 +94,6 @@ func (s *statsSyncLoad) SendLoadRequests(sc *stmtctx.StatementContext, neededHis
9494
}
9595
}
9696
})
97-
9897
if len(remainedItems) <= 0 {
9998
return nil
10099
}
@@ -352,6 +351,9 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err
352351
t := time.Now()
353352
needUpdate := false
354353
wrapper, err = s.readStatsForOneItem(sctx, item, wrapper, isPkIsHandle, task.Item.FullLoad)
354+
if stderrors.Is(err, errGetHistMeta) {
355+
return nil
356+
}
355357
if err != nil {
356358
return err
357359
}
@@ -371,6 +373,8 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err
371373
return nil
372374
}
373375

376+
var errGetHistMeta = errors.New("fail to get hist meta")
377+
374378
// readStatsForOneItem reads hist for one column/index, TODO load data via kv-get asynchronously
375379
func (*statsSyncLoad) readStatsForOneItem(sctx sessionctx.Context, item model.TableItemID, w *statsWrapper, isPkIsHandle bool, fullLoad bool) (*statsWrapper, error) {
376380
failpoint.Inject("mockReadStatsForOnePanic", nil)
@@ -388,9 +392,9 @@ func (*statsSyncLoad) readStatsForOneItem(sctx sessionctx.Context, item model.Ta
388392
return nil, err
389393
}
390394
if hg == nil {
391-
logutil.BgLogger().Error("fail to get hist meta for this histogram, possibly a deleted one", zap.Int64("table_id", item.TableID),
395+
logutil.BgLogger().Warn("fail to get hist meta for this histogram, possibly a deleted one", zap.Int64("table_id", item.TableID),
392396
zap.Int64("hist_id", item.ID), zap.Bool("is_index", item.IsIndex))
393-
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))
397+
return nil, errGetHistMeta
394398
}
395399
if item.IsIndex {
396400
isIndexFlag = 1

tests/integrationtest/r/planner/core/issuetest/planner_issue.result

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,30 @@ CREATE TABLE t0(c0 int);
723723
CREATE TABLE t1(c0 int);
724724
SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0));
725725
c0 c0
726+
drop table if exists t1, t2, t3, t4;
727+
CREATE TABLE t1 (a int, b int, c int);
728+
CREATE TABLE t2 (a int, b int, c int);
729+
CREATE TABLE t3 (a int, b int, c int);
730+
CREATE TABLE t4 (a int, b int, c int);
731+
INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
732+
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
733+
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
734+
INSERT INTO t4 VALUES (3,2,0), (4,2,0);
735+
CREATE INDEX idx_b ON t2(b);
736+
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
737+
FROM (t3,t4)
738+
LEFT JOIN
739+
(t1,t2)
740+
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
741+
a b a b a b
742+
NULL NULL 2 2 3 2
743+
NULL NULL 2 2 4 2
744+
4 2 1 2 3 2
745+
4 2 1 2 3 2
746+
4 2 1 2 3 2
747+
4 2 1 2 4 2
748+
4 2 1 2 4 2
749+
4 2 1 2 4 2
750+
show warnings;
751+
Level Code Message
752+
drop table if exists t1, t2, t3, t4;

tests/integrationtest/t/planner/core/issuetest/planner_issue.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,22 @@ drop table if exists t0, t1;
498498
CREATE TABLE t0(c0 int);
499499
CREATE TABLE t1(c0 int);
500500
SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0));
501+
502+
# TestIssue56472
503+
drop table if exists t1, t2, t3, t4;
504+
CREATE TABLE t1 (a int, b int, c int);
505+
CREATE TABLE t2 (a int, b int, c int);
506+
CREATE TABLE t3 (a int, b int, c int);
507+
CREATE TABLE t4 (a int, b int, c int);
508+
INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
509+
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
510+
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
511+
INSERT INTO t4 VALUES (3,2,0), (4,2,0);
512+
CREATE INDEX idx_b ON t2(b);
513+
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
514+
FROM (t3,t4)
515+
LEFT JOIN
516+
(t1,t2)
517+
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
518+
show warnings;
519+
drop table if exists t1, t2, t3, t4;

0 commit comments

Comments
 (0)