Skip to content

Commit 81a7f62

Browse files
hawkingreiti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#56614
Signed-off-by: ti-chi-bot <[email protected]>
1 parent e316107 commit 81a7f62

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,38 @@ 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+
<<<<<<< HEAD
722+
=======
723+
drop table if exists t0, t1;
724+
CREATE TABLE t0(c0 int);
725+
CREATE TABLE t1(c0 int);
726+
SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0));
727+
c0 c0
728+
drop table if exists t1, t2, t3, t4;
729+
CREATE TABLE t1 (a int, b int, c int);
730+
CREATE TABLE t2 (a int, b int, c int);
731+
CREATE TABLE t3 (a int, b int, c int);
732+
CREATE TABLE t4 (a int, b int, c int);
733+
INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
734+
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
735+
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
736+
INSERT INTO t4 VALUES (3,2,0), (4,2,0);
737+
CREATE INDEX idx_b ON t2(b);
738+
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
739+
FROM (t3,t4)
740+
LEFT JOIN
741+
(t1,t2)
742+
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
743+
a b a b a b
744+
NULL NULL 2 2 3 2
745+
NULL NULL 2 2 4 2
746+
4 2 1 2 3 2
747+
4 2 1 2 3 2
748+
4 2 1 2 3 2
749+
4 2 1 2 4 2
750+
4 2 1 2 4 2
751+
4 2 1 2 4 2
752+
show warnings;
753+
Level Code Message
754+
drop table if exists t1, t2, t3, t4;
755+
>>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614))

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,31 @@ 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+
<<<<<<< HEAD
496+
=======
497+
498+
# TestIssue53766
499+
drop table if exists t0, t1;
500+
CREATE TABLE t0(c0 int);
501+
CREATE TABLE t1(c0 int);
502+
SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0));
503+
504+
# TestIssue56472
505+
drop table if exists t1, t2, t3, t4;
506+
CREATE TABLE t1 (a int, b int, c int);
507+
CREATE TABLE t2 (a int, b int, c int);
508+
CREATE TABLE t3 (a int, b int, c int);
509+
CREATE TABLE t4 (a int, b int, c int);
510+
INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
511+
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
512+
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
513+
INSERT INTO t4 VALUES (3,2,0), (4,2,0);
514+
CREATE INDEX idx_b ON t2(b);
515+
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
516+
FROM (t3,t4)
517+
LEFT JOIN
518+
(t1,t2)
519+
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
520+
show warnings;
521+
drop table if exists t1, t2, t3, t4;
522+
>>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614))

0 commit comments

Comments
 (0)