Skip to content

Commit

Permalink
statistics: fix missing nil check for mv index (pingcap#50313)
Browse files Browse the repository at this point in the history
  • Loading branch information
time-and-fate authored Jan 11, 2024
1 parent ad0917e commit 1ad36eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/statistics/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions tests/integrationtest/r/planner/core/indexmerge_path.result
Original file line number Diff line number Diff line change
Expand Up @@ -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]
8 changes: 8 additions & 0 deletions tests/integrationtest/t/planner/core/indexmerge_path.test
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 1ad36eb

Please sign in to comment.