XiaoMi / soar

SQL Optimizer And Rewriter
Apache License 2.0
8.67k stars 1.32k forks source link

JSON datatype sampling error #178

Closed martianzhang closed 5 years ago

martianzhang commented 5 years ago

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
create table test_json(
id int,
`c` json DEFAULT NULL
) engine=InnoDB charset=utf8mb4;

insert into test_json values (1, '{"k1": "value", "k2": 10}');
soar -query "select * from test_json"
  1. What did you see instead?
Error 3144: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
insert into `test_json` (`id`,`c`) values (unhex("31"),unhex("7b226b31223a202276616c7565222c20226b32223a2031307d"));
  1. What version of are you using (soar -version)?
Version: 2018-12-28 22:50:30 +0800 0.10.0-81-gd9f6ef7
Branch: master
Compile: 2019-01-02 19:51:33 +0800 by go version go1.10.4 linux/amd64
GitDirty: 0
martianzhang commented 5 years ago
Error:
insert into `test_json` (`id`,`c`) values (unhex("31"),unhex("7b226b31223a202276616c7565222c20226b32223a2031307d"));

Right:
insert into `test_json` (`id`,`c`) values (unhex("31"), CONVERT(X'7b226b31223a202276616c7565222c20226b32223a2031307d' using utf8mb4))

Reference: