Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statistics: fix missing nil check for mv index #50313

Merged
merged 1 commit into from
Jan 11, 2024
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
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');