Skip to content

Commit 5b51b58

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 c89d677 commit 5b51b58

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

pkg/statistics/handle/handle_hist.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package handle
1616

1717
import (
18-
"fmt"
18+
stderrors "errors"
1919
"math/rand"
2020
"sync"
2121
"time"
@@ -80,7 +80,6 @@ func (h *Handle) SendLoadRequests(sc *stmtctx.StatementContext, neededHistItems
8080
}
8181
}
8282
})
83-
8483
if len(remainedItems) <= 0 {
8584
return nil
8685
}
@@ -326,7 +325,14 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
326325
failpoint.Inject("handleOneItemTaskPanic", nil)
327326
t := time.Now()
328327
needUpdate := false
328+
<<<<<<< HEAD:pkg/statistics/handle/handle_hist.go
329329
wrapper, err = h.readStatsForOneItem(sctx, item, wrapper)
330+
=======
331+
wrapper, err = s.readStatsForOneItem(sctx, item, wrapper, isPkIsHandle, task.Item.FullLoad)
332+
if stderrors.Is(err, errGetHistMeta) {
333+
return nil
334+
}
335+
>>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614)):pkg/statistics/handle/syncload/stats_syncload.go
330336
if err != nil {
331337
return err
332338
}
@@ -346,6 +352,8 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
346352
return nil
347353
}
348354

355+
var errGetHistMeta = errors.New("fail to get hist meta")
356+
349357
// readStatsForOneItem reads hist for one column/index, TODO load data via kv-get asynchronously
350358
func (h *Handle) readStatsForOneItem(sctx sessionctx.Context, item model.TableItemID, w *statsWrapper) (*statsWrapper, error) {
351359
failpoint.Inject("mockReadStatsForOnePanic", nil)
@@ -360,6 +368,18 @@ func (h *Handle) readStatsForOneItem(sctx sessionctx.Context, item model.TableIt
360368
var hg *statistics.Histogram
361369
var err error
362370
isIndexFlag := int64(0)
371+
<<<<<<< HEAD:pkg/statistics/handle/handle_hist.go
372+
=======
373+
hg, lastAnalyzePos, statsVer, flag, err := storage.HistMetaFromStorageWithHighPriority(sctx, &item, w.colInfo)
374+
if err != nil {
375+
return nil, err
376+
}
377+
if hg == nil {
378+
logutil.BgLogger().Warn("fail to get hist meta for this histogram, possibly a deleted one", zap.Int64("table_id", item.TableID),
379+
zap.Int64("hist_id", item.ID), zap.Bool("is_index", item.IsIndex))
380+
return nil, errGetHistMeta
381+
}
382+
>>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614)):pkg/statistics/handle/syncload/stats_syncload.go
363383
if item.IsIndex {
364384
isIndexFlag = 1
365385
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ CREATE TABLE t0(c0 int);
582582
CREATE TABLE t1(c0 int);
583583
SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0));
584584
c0 c0
585+
<<<<<<< HEAD
585586
drop table if exists t;
586587
create table t (id int unique key, c int);
587588
insert into t values (1, 10);
@@ -592,3 +593,32 @@ _tidb_rowid
592593
1
593594
2
594595
3
596+
=======
597+
drop table if exists t1, t2, t3, t4;
598+
CREATE TABLE t1 (a int, b int, c int);
599+
CREATE TABLE t2 (a int, b int, c int);
600+
CREATE TABLE t3 (a int, b int, c int);
601+
CREATE TABLE t4 (a int, b int, c int);
602+
INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
603+
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
604+
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
605+
INSERT INTO t4 VALUES (3,2,0), (4,2,0);
606+
CREATE INDEX idx_b ON t2(b);
607+
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
608+
FROM (t3,t4)
609+
LEFT JOIN
610+
(t1,t2)
611+
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
612+
a b a b a b
613+
NULL NULL 2 2 3 2
614+
NULL NULL 2 2 4 2
615+
4 2 1 2 3 2
616+
4 2 1 2 3 2
617+
4 2 1 2 3 2
618+
4 2 1 2 4 2
619+
4 2 1 2 4 2
620+
4 2 1 2 4 2
621+
show warnings;
622+
Level Code Message
623+
drop table if exists t1, t2, t3, t4;
624+
>>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614))

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,31 @@ CREATE TABLE t0(c0 int);
453453
CREATE TABLE t1(c0 int);
454454
SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0));
455455

456+
<<<<<<< HEAD
456457
# TestIssue58581
457458
drop table if exists t;
458459
create table t (id int unique key, c int);
459460
insert into t values (1, 10);
460461
insert into t values (2, 20);
461462
insert into t values (3, 30);
462463
select _tidb_rowid from t where id in (1, 2, 3);
464+
=======
465+
# TestIssue56472
466+
drop table if exists t1, t2, t3, t4;
467+
CREATE TABLE t1 (a int, b int, c int);
468+
CREATE TABLE t2 (a int, b int, c int);
469+
CREATE TABLE t3 (a int, b int, c int);
470+
CREATE TABLE t4 (a int, b int, c int);
471+
INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
472+
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
473+
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
474+
INSERT INTO t4 VALUES (3,2,0), (4,2,0);
475+
CREATE INDEX idx_b ON t2(b);
476+
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
477+
FROM (t3,t4)
478+
LEFT JOIN
479+
(t1,t2)
480+
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
481+
show warnings;
482+
drop table if exists t1, t2, t3, t4;
483+
>>>>>>> 10647c9d733 (statstics: avoid unnecessary try when to sync load (#56614))

0 commit comments

Comments
 (0)