Skip to content

Commit

Permalink
statstics: avoid unnecessary try when to sync load (#56614) (#56638)
Browse files Browse the repository at this point in the history
close #56472
  • Loading branch information
ti-chi-bot authored Oct 15, 2024
1 parent e316107 commit 1832b27
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/statistics/handle/syncload/stats_syncload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package syncload

import (
"fmt"
stderrors "errors"
"math/rand"
"runtime"
"time"
Expand Down Expand Up @@ -94,7 +94,6 @@ func (s *statsSyncLoad) SendLoadRequests(sc *stmtctx.StatementContext, neededHis
}
}
})

if len(remainedItems) <= 0 {
return nil
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,30 @@ Projection_11 6.00 root 1->Column#18
└─Projection_17(Probe) 10000.00 root cast(test.t61a85298.col_71, double BINARY)->Column#19
└─TableReader_19 10000.00 root data:TableFullScan_18
└─TableFullScan_18 10000.00 cop[tikv] table:t61a85298 keep order:false, stats:pseudo
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;
19 changes: 19 additions & 0 deletions tests/integrationtest/t/planner/core/issuetest/planner_issue.test
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,22 @@ FROM (
) AS derived_table
WHERE 16739493649928310215 MEMBER OF (derived_table.col_60767)
OR NOT (JSON_CONTAINS(derived_table.col_60767, '6019730272580550835'));

# 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;

0 comments on commit 1832b27

Please sign in to comment.