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

index buckets bound couldn't decode itself out with corresponding index column type. #49823

Closed
AilinKid opened this issue Dec 27, 2023 · 2 comments · Fixed by #49945
Closed
Assignees

Comments

@AilinKid
Copy link
Contributor

AilinKid commented Dec 27, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

use test
create table t(a datetime, b int, index ia(a,b));
insert into t value('2023-12-27',1),(null, 2),('2023-12-28',3),(null,4);
analyze table t with 0 topn;
explain select * from t where a > 1;
show stats_buckets where db_name = 'test';

AND mock the code in v6.5.4 showExec

// ValueToString converts a possible encoded value to a formatted string. If the value is encoded, then
// idxCols equals to number of origin values, else idxCols is 0.
func ValueToString(vars *variable.SessionVars, value *types.Datum, idxCols int, idxColumnTypes []byte) (string, error) {
	if idxCols == 0 {
		return value.ToString()
	}
	var loc *time.Location
	if vars != nil {
		loc = vars.Location()
	}
	// Ignore the error and treat remaining part that cannot decode successfully as bytes.
	decodedVals, remained, err := codec.DecodeRange(value.GetBytes(), idxCols, idxColumnTypes, loc)
	// Ignore err explicit to pass errcheck.
        // mock the code here, rather than ignore it!!!
	if err != nil {
		panic(err.Error())
	}
	if len(remained) > 0 {
		decodedVals = append(decodedVals, types.NewBytesDatum(remained))
	}
	str, err := types.DatumsToString(decodedVals, true)
	return str, err
}

2. What did you expect to see? (Required)

show stats_buckets where table_name = 'xxx' and column_name = 'xxx'\G

3. What did you see instead (Required)

show stats_buckets successfully

4. What is your TiDB version? (Required)

panic with recovery with msg: invalid encoded key flag 0

@AilinKid AilinKid added type/bug This issue is a bug. sig/planner SIG: Planner severity/moderate labels Dec 27, 2023
@AilinKid AilinKid self-assigned this Dec 27, 2023
@AilinKid
Copy link
Contributor Author

from @time-and-fate the minumun reproduce step

use test
create table t(a datetime, b int, index ia(a,b));
insert into t value('2023-12-27',1),(null, 2),('2023-12-28',3),(null,4);
analyze table t with 0 topn;
explain select * from t where a > 1;
show stats_buckets where db_name = 'test';

basic reason is that:
image
after fix this, show stats buckets can show correctness result
img_v3_026h_a5a94b59-4eac-48a8-9ef0-13bb9a5acbfg

@tiancaiamao
Copy link
Contributor

B.T.W, it's better to avoid the ONCALL id in github @AilinKid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants