Skip to content

Commit 1832b27

Browse files
authored
statstics: avoid unnecessary try when to sync load (#56614) (#56638)
close #56472
1 parent e316107 commit 1832b27

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
@@ -718,3 +718,30 @@ Projection_11 6.00 root 1->Column#18
718718
└─Projection_17(Probe) 10000.00 root cast(test.t61a85298.col_71, double BINARY)->Column#19
719719
└─TableReader_19 10000.00 root data:TableFullScan_18
720720
└─TableFullScan_18 10000.00 cop[tikv] table:t61a85298 keep order:false, stats:pseudo
721+
drop table if exists t1, t2, t3, t4;
722+
CREATE TABLE t1 (a int, b int, c int);
723+
CREATE TABLE t2 (a int, b int, c int);
724+
CREATE TABLE t3 (a int, b int, c int);
725+
CREATE TABLE t4 (a int, b int, c int);
726+
INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
727+
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
728+
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
729+
INSERT INTO t4 VALUES (3,2,0), (4,2,0);
730+
CREATE INDEX idx_b ON t2(b);
731+
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
732+
FROM (t3,t4)
733+
LEFT JOIN
734+
(t1,t2)
735+
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
736+
a b a b a b
737+
NULL NULL 2 2 3 2
738+
NULL NULL 2 2 4 2
739+
4 2 1 2 3 2
740+
4 2 1 2 3 2
741+
4 2 1 2 3 2
742+
4 2 1 2 4 2
743+
4 2 1 2 4 2
744+
4 2 1 2 4 2
745+
show warnings;
746+
Level Code Message
747+
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
@@ -492,3 +492,22 @@ FROM (
492492
) AS derived_table
493493
WHERE 16739493649928310215 MEMBER OF (derived_table.col_60767)
494494
OR NOT (JSON_CONTAINS(derived_table.col_60767, '6019730272580550835'));
495+
496+
# TestIssue56472
497+
drop table if exists t1, t2, t3, t4;
498+
CREATE TABLE t1 (a int, b int, c int);
499+
CREATE TABLE t2 (a int, b int, c int);
500+
CREATE TABLE t3 (a int, b int, c int);
501+
CREATE TABLE t4 (a int, b int, c int);
502+
INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
503+
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
504+
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
505+
INSERT INTO t4 VALUES (3,2,0), (4,2,0);
506+
CREATE INDEX idx_b ON t2(b);
507+
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
508+
FROM (t3,t4)
509+
LEFT JOIN
510+
(t1,t2)
511+
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
512+
show warnings;
513+
drop table if exists t1, t2, t3, t4;

0 commit comments

Comments
 (0)