Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pkg/statistics/handle/handle_hist.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package handle

import (
"fmt"
stderrors "errors"
"math/rand"
"sync"
"time"
Expand Down Expand Up @@ -80,7 +80,6 @@ func (h *Handle) SendLoadRequests(sc *stmtctx.StatementContext, neededHistItems
}
}
})

if len(remainedItems) <= 0 {
return nil
}
Expand Down Expand Up @@ -327,6 +326,10 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
t := time.Now()
needUpdate := false
wrapper, err = h.readStatsForOneItem(sctx, item, wrapper)
if stderrors.Is(err, errGetHistMeta) {
metrics.ReadStatsHistogram.Observe(float64(time.Since(t).Milliseconds()))
return nil
}
if err != nil {
return err
}
Expand All @@ -346,6 +349,8 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
return nil
}

var errGetHistMeta = errors.New("fail to get stats version for this histogram")

// readStatsForOneItem reads hist for one column/index, TODO load data via kv-get asynchronously
func (h *Handle) readStatsForOneItem(sctx sessionctx.Context, item model.TableItemID, w *statsWrapper) (*statsWrapper, error) {
failpoint.Inject("mockReadStatsForOnePanic", nil)
Expand Down Expand Up @@ -424,9 +429,11 @@ func (h *Handle) readStatsForOneItem(sctx sessionctx.Context, item model.TableIt
return nil, errors.Trace(err)
}
if len(rows) == 0 {
logutil.BgLogger().Error("fail to get stats version for this histogram, normally this wouldn't happen, please check if this column or index has a histogram record in `mysql.stats_histogram`", 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 stats version for this histogram, normally this wouldn't happen, please check if this column or index has a histogram record in `mysql.stats_histogram`, table_id:%v, hist_id:%v, is_index:%v", item.TableID, item.ID, item.IsIndex))
logutil.BgLogger().Error("fail to get stats version for this histogram, normally this wouldn't happen, please check if this column or index has a histogram record in `mysql.stats_histogram`",
zap.Int64("table_id", item.TableID),
zap.Int64("hist_id", item.ID),
zap.Bool("is_index", item.IsIndex))
return nil, errGetHistMeta
}
statsVer := rows[0].GetInt64(0)
if item.IsIndex {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,30 @@ _tidb_rowid
1
2
3
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;
18 changes: 18 additions & 0 deletions tests/integrationtest/t/planner/core/issuetest/planner_issue.test
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,21 @@ insert into t values (1, 10);
insert into t values (2, 20);
insert into t values (3, 30);
select _tidb_rowid from t where id in (1, 2, 3);
# 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;