planner: unexpected error when using Plan Cache with JSON
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```
CREATE TABLE `t88d8f90d` (
`col_39` timestamp NOT NULL DEFAULT '2035-09-25 00:00:00',
`col_40` int unsigned DEFAULT '4189283437',
`col_41` bigint NOT NULL,
`col_42` year(4) NOT NULL,
`col_43` json DEFAULT NULL,
`col_44` varchar(335) CHARACTER SET gbk COLLATE gbk_bin NOT NULL DEFAULT '饱腤',
`col_45` tinyint NOT NULL DEFAULT '-43',
`col_46` json NOT NULL,
`col_47` float NOT NULL DEFAULT '778.31006',
PRIMARY KEY (`col_41`,`col_44`(4)) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
PARTITION BY KEY (`col_41`) PARTITIONS 4;
CREATE TABLE `t298a0103` (
`col_76` date NOT NULL,
`col_77` mediumint DEFAULT NULL,
KEY `idx_19` (`col_77`,`col_76`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
PARTITION BY KEY (`col_77`) PARTITIONS 7;
INSERT INTO `t88d8f90d` values ('2026-07-12 00:00:00', 86004303, 350018215833520874, '1992', '["CVgsTnt7ieljb7ntVkpfIlkWKnMKerac03S8ZkyHPGrnxKsQKk80cNDaOJX76IPF","WCKbHTPZSi9bTrDyngcxq7TYs87lCDnX89OQZwMBOEyjv3Tl3HwVIjRK8gBkPJcV", "ZItDcJEv5LULaY16fSxtuQWpU20AA6bojeGnc6v67kzmgS1LUgDKbsOXCASxieB0"]', "s蔝簧郇猆4莊恠3T藵U6n轋", -1, '["kysM4N8UF53nVELmFpGl0eoJyH8fmHTQdBF1P9Pc9Ovs8VOrYFqA4kPAASUbkvuU","Xi7srlugcPa5FFDeYnpWKnMJaR6NluCUOMIWQZTsYk0BhA8KwLMS4TvFZbZ6yS6j","X8LirlcJdK5z5uHkBRd4SLhI1UePGUZUivRONd6ELhHVGE3OnUcOkyrqJ2cu9TMO","45yX0UshmA6s9X6K5JMneGsoWdgHSwJK7HJu9tk7x2AFhZiLnidKvHh9lU3pqz1u"]', 3295.8152);
prepare `l5Iq1SSe#jyLCJes` from "select /*+ use_index_merge( t298a0103,t88d8f90d ) */ /*+ */ /*+ HASH_JOIN_BUILD( t298a0103 ) */ min( distinct t298a0103.col_77 ) as r0 , bit_xor( t298a0103.col_77 ) as r1 , locate( t88d8f90d.col_43 , t88d8f90d.col_43 ) as r2 , count( t298a0103.col_77 ) as r3 , mid( t88d8f90d.col_43 , 0 , 0 ) as r4 from t298a0103 join t88d8f90d on t298a0103.col_77 = t88d8f90d.col_43 where t88d8f90d.col_42 in ( ? ,? ,? ) group by t88d8f90d.col_43 having not( JSON_CONTAINS( t88d8f90d.col_43 , ? ) ) order by r0,r1,r2,r3,r4 limit 243573596";
set @i0 = '*s=%5iQRnI!NfV#4';
set @i1 = 'q6&Ka(e2wnsDI9DI';
set @i2 = '^&@OEu4Na%o=C-4#';
set @i3 = '5Qbmo1Z9JizMNVlXqWPIhSeZukV1U9BpzwscLZRDjaKHgUStTeb79UvOegajEXwS';
execute `l5Iq1SSe#jyLCJes` using @i0,@i1,@i2,@i3;
-- ERROR 1105 (HY000): invalid data type: Illegal Json text: Error("trailing characters", line: 1, column: 2)
select /*+ use_index_merge( t298a0103,t88d8f90d ) */ /*+ */ /*+ HASH_JOIN_BUILD( t298a0103 ) */ min( distinct t298a0103.col_77 ) as r0 , bit_xor( t298a0103.col_77 ) as r1 , locate( t88d8f90d.col_43 , t88d8f90d.col_43 ) as r2 , count( t298a0103.col_77 ) as r3 , mid( t88d8f90d.col_43 , 0 , 0 ) as r4 from t298a0103 join t88d8f90d on t298a0103.col_77 = t88d8f90d.col_43 where t88d8f90d.col_42 in ( '*s=%5iQRnI!NfV#4' ,'q6&Ka(e2wnsDI9DI' ,'^&@OEu4Na%o=C-4#' ) group by t88d8f90d.col_43 having not( JSON_CONTAINS( t88d8f90d.col_43 , "5Qbmo1Z9JizMNVlXqWPIhSeZukV1U9BpzwscLZRDjaKHgUStTeb79UvOegajEXwS" ) ) order by r0,r1,r2,r3,r4 limit 243573596;
-- Empty set, 9 warnings (0.01 sec)
```
### 2. What did you expect to see? (Required)
No error.
### 3. What did you see instead (Required)
```
ysql> execute `l5Iq1SSe#jyLCJes` using @i0,@i1,@i2,@i3;
ERROR 1105 (HY000): Invalid JSON text: The document root must not be followed by other values
```
### 4. What is your TiDB version? (Required)
Master
Contributor guide
Assessment
This issue has not been assessed yet.