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

query gets 'encoding failed' using distinct and elt function #50850

Closed
wjhuang2016 opened this issue Jan 31, 2024 · 1 comment · Fixed by #50146
Closed

query gets 'encoding failed' using distinct and elt function #50850

wjhuang2016 opened this issue Jan 31, 2024 · 1 comment · Fixed by #50146
Assignees
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. fuzz/randomtest severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@wjhuang2016
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `tl4fd484a9` (
  `col_8` double NOT NULL DEFAULT '8101.804333035654',
  `col_9` bigint(20) unsigned DEFAULT NULL,
  `col_10` bit(8) DEFAULT NULL,
  `col_11` bit(42) DEFAULT NULL,
  UNIQUE KEY `idx_4` (`col_9`),
  UNIQUE KEY `idx_5` (`col_9`),
  UNIQUE KEY `idx_6` (`col_9`,`col_10`,`col_8`),
  UNIQUE KEY `idx_7` (`col_9`,`col_8`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
PARTITION BY HASH (`col_9`) PARTITIONS 2;

INSERT INTO `tl4fd484a9` VALUES (23.007995724948362,9223372036854775808,x'd5',x'036bda736b9f'), (2591.3122474206766,5752943349156553245,NULL,x'02b77969361c'), (4479.317291827713,15055294211639017111,x'aa',x'01eee6f9a4a3'), (7628.938897170623,7496567757002745451,x'eb',x'0287ad3ecd13'), (8347.197576995819,6203659976161826151,x'18',x'01d6475a8df2'), (8710.54054998306,8514535559911610148,x'e2',x'03f899c130b2'), (1195.077740002609,3436186226464611422,x'50',x'0093ab260f48'), (1013.7500694146422,7471092280998844033,x'dd',x'03939af0ec85'), (5521.611017775993,16394145724846312682,x'61',x'01c06f356d0a'), (8587.461307265945,1885935207250807462,x'60',x'035a03c4dff2'), (7650.576352691503,14483491971408231742,x'91',x'02c6eaea03a1'), (2851.908224583381,15373714602380758326,NULL,x'00b8a992625f'), (5204.233883775764,12245754788232558702,x'8c',x'005b42a9761e'), (711.5713246022093,9223372036854775807,x'15',x'03ce7c19cc28'), (6700.8257413585525,11960899368204480686,x'5a',x'01a07ebf627f'), (3715.8911161876927,16717915239921191114,x'19',x'0183db6da03f'), (5588.550656466107,3324080768693532255,x'69',x'029bfa03f27e'), (6736.377121180751,4102219363823857377,x'34',x'02389972a4bc'), (5010.654821363877,1,x'01',x'012d8efdb99d'), (2555.2202292511456,NULL,x'27',x'02a09857f11c'), (6513.333951893525,7297996079516535344,x'ff',x'00123dbb5766'), (7211.133912898516,16059815461817714863,x'88',x'000000000000'), (3223.450063930532,10556257816865671061,x'76',x'035575eb3736'), (5934.213444452291,3506157312092400137,x'2f',x'0099bb76950a'), (5613.036187642952,13165727662517512195,x'01',x'01ffb1103861'), (161.42937173636415,NULL,x'3f',x'032eedd972eb'), (8632.659024782468,16757755969895857419,x'5d',NULL), (7047.649466854864,14821390344080511959,x'a6',x'0012a171b473'), (7442.306955199656,12094326225722438418,x'12',x'000000000000'), (1795.1199576186712,1328447598647750078,x'2d',x'0325b495eba1'), (7467.011217133958,9561095661261955906,x'01',x'011834544fb1'), (2972.7118048537704,18446744073709551615,x'b1',x'01977242631c'), (3161.6599685270917,7911534160713813860,x'37',x'03782feb0295'), (9546.629394674586,17028252544791959939,x'ff',x'01d73fa1f0fa'), (2306.9705216860984,1630137914052885313,x'31',x'005d59426708'), (7601.530447792593,6986807871336145185,x'd5',x'016998085258'), (7058.842877388801,8570807740729504101,x'a5',x'0112cc74569e'), (615.6011553350702,11897798906906134285,x'34',x'03d135a573c2'), (3801.6115898094317,11678651343133193774,x'3a',x'009f3c65f2c5'), (6779.239615471537,2484649041714012147,x'65',x'03b9cba6820d');

SELECT DISTINCT ELT(2, `tl4fd484a9`.`col_8`, `tl4fd484a9`.`col_10`) AS `r0` FROM `tl4fd484a9`;

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

No error

3. What did you see instead (Required)

mysql> SELECT DISTINCT ELT(2, `tl4fd484a9`.`col_8`, `tl4fd484a9`.`col_10`) AS `r0` FROM `tl4fd484a9`;
ERROR 1105 (HY000): encoding failed

4. What is your TiDB version? (Required)

4e41699

@wjhuang2016 wjhuang2016 added type/bug The issue is confirmed as a bug. fuzz/randomtest labels Jan 31, 2024
@wjhuang2016 wjhuang2016 changed the title query get 'encoding failed' using distinct and elt function query gets 'encoding failed' using distinct and elt function Jan 31, 2024
@windtalker windtalker added sig/sql-infra SIG: SQL Infra and removed sig/execution SIG execution labels Feb 1, 2024
@windtalker
Copy link
Contributor

windtalker commented Feb 1, 2024

The root cause seems TiDB think the result string of ELT(2, `tl4fd484a9`.`col_8`, `tl4fd484a9`.`col_10`) has unicode0900AICI collator, but tl4fd484a9`.`col_10 is actually a bit column, and cast(test.tl4fd484a9.col_10, var_string(1)) actually can not make the result a valid utf string if the input string is not utf valid string, so it may meet encode error. I would change the label to sig infra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. fuzz/randomtest severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants