statistics: fix missing nil check for mv index (#50313)

close pingcap/tidb#50298
This commit is contained in:
Zhou Kunqin
2024-01-11 19:28:54 +08:00
committed by GitHub
parent ad0917ea00
commit 1ad36eb0ef
3 changed files with 19 additions and 1 deletions

View File

@ -448,7 +448,7 @@ func (coll *HistColl) GetAnalyzeRowCount() float64 {
func (coll *HistColl) GetScaledRealtimeAndModifyCnt(idxStats *Index) (realtimeCnt, modifyCnt int64) {
// In theory, we can apply this scale logic on all indexes. But currently, we only apply it on the mv index to avoid
// any unexpected changes caused by factors like precision difference.
if idxStats.Info == nil || !idxStats.Info.MVIndex || !idxStats.IsFullLoad() {
if idxStats == nil || idxStats.Info == nil || !idxStats.Info.MVIndex || !idxStats.IsFullLoad() {
return coll.RealtimeCount, coll.ModifyCount
}
analyzeRowCount := coll.GetAnalyzeRowCount()

View File

@ -704,3 +704,13 @@ select * from t ignore index (mvi) where json_contains(j, '[]');
j
[]
["abc"]
drop table if exists t;
create table t(a int, b json);
insert into t value (1, '{"a":[1,2,3], "b": [2,3,4]}');
analyze table t;
alter table t add index ibb( (cast(b->'$.b' as signed array)) );
explain select /*+ use_index_merge(t) */ * from t where 10 member of (b->'$.b');
id estRows task access object operator info
IndexMerge_7 1.00 root type: union
├─IndexRangeScan_5(Build) 1.00 cop[tikv] table:t, index:ibb(cast(json_extract(`b`, _utf8mb4'$.b') as signed array)) range:[10,10], keep order:false, stats:partial[ibb:missing, b:unInitialized]
└─TableRowIDScan_6(Probe) 1.00 cop[tikv] table:t keep order:false, stats:partial[ibb:missing, b:unInitialized]

View File

@ -245,3 +245,11 @@ insert into t values ('[]');
insert into t values ('["abc"]');
select * from t use index (mvi) where json_contains(j, '[]');
select * from t ignore index (mvi) where json_contains(j, '[]');
# TestIssue50298
drop table if exists t;
create table t(a int, b json);
insert into t value (1, '{"a":[1,2,3], "b": [2,3,4]}');
analyze table t;
alter table t add index ibb( (cast(b->'$.b' as signed array)) );
explain select /*+ use_index_merge(t) */ * from t where 10 member of (b->'$.b');