| 1 |
set default_storage_engine=innodb; |
| 2 |
CREATE TABLE t( |
| 3 |
j JSON, |
| 4 |
stored_gc JSON GENERATED ALWAYS AS (JSON_EXTRACT(j, '$[0]')) STORED, |
| 5 |
virtual_gc JSON GENERATED ALWAYS AS (JSON_EXTRACT(j, '$[1]')) VIRTUAL); |
| 6 |
INSERT INTO t(j) VALUES |
| 7 |
(JSON_ARRAY(1, 2)), (JSON_ARRAY(2, 1)), (JSON_ARRAY(10, 10)), (JSON_ARRAY(5)); |
| 8 |
SELECT * FROM t ORDER BY stored_gc; |
| 9 |
j stored_gc virtual_gc |
| 10 |
[1, 2] 1 2 |
| 11 |
[2, 1] 2 1 |
| 12 |
[5] 5 NULL |
| 13 |
[10, 10] 10 10 |
| 14 |
SELECT * FROM t ORDER BY virtual_gc; |
| 15 |
j stored_gc virtual_gc |
| 16 |
[5] 5 NULL |
| 17 |
[2, 1] 2 1 |
| 18 |
[1, 2] 1 2 |
| 19 |
[10, 10] 10 10 |
| 20 |
DROP TABLE t; |
| 21 |
# ---------------------------------------------------------------------- |
| 22 |
# Test of generated columns that call JSON functions |
| 23 |
# ---------------------------------------------------------------------- |
| 24 |
CREATE TABLE t(id INT, j JSON, |
| 25 |
gc INT GENERATED ALWAYS AS (JSON_EXTRACT(j, '$[0]'))); |
| 26 |
INSERT INTO t(id, j) VALUES (0, '"5"'), (1, '[]'), (2, '[1,2]'), (3, '5'); |
| 27 |
INSERT INTO t(j) VALUES ('{}'); |
| 28 |
ERROR 22018: Invalid JSON value for CAST to INTEGER from column json_extract at row 1 |
| 29 |
INSERT INTO t(j) VALUES ('{"a":1}'); |
| 30 |
ERROR 22018: Invalid JSON value for CAST to INTEGER from column json_extract at row 1 |
| 31 |
INSERT INTO t(j) VALUES ('"abc"'); |
| 32 |
ERROR 22018: Invalid JSON value for CAST to INTEGER from column json_extract at row 1 |
| 33 |
INSERT INTO t(j) VALUES (''); |
| 34 |
ERROR 22032: Invalid JSON text: "The document is empty." at position 0 in value for column 't.j'. |
| 35 |
INSERT INTO t(j) VALUES ('['); |
| 36 |
ERROR 22032: Invalid JSON text: "Invalid value." at position 1 in value for column 't.j'. |
| 37 |
SELECT * FROM t ORDER BY id; |
| 38 |
id j gc |
| 39 |
0 "5" 5 |
| 40 |
1 [] NULL |
| 41 |
2 [1, 2] 1 |
| 42 |
3 5 5 |
| 43 |
UPDATE t SET j = '[123]'; |
| 44 |
SELECT * FROM t ORDER BY id; |
| 45 |
id j gc |
| 46 |
0 [123] 123 |
| 47 |
1 [123] 123 |
| 48 |
2 [123] 123 |
| 49 |
3 [123] 123 |
| 50 |
UPDATE t SET j = '['; |
| 51 |
ERROR 22032: Invalid JSON text: "Invalid value." at position 1 in value for column 't.j'. |
| 52 |
DROP TABLE t; |
| 53 |
CREATE TABLE t(id INT, j JSON, |
| 54 |
gc JSON GENERATED ALWAYS AS (JSON_ARRAY(j))); |
| 55 |
INSERT INTO t(id, j) |
| 56 |
VALUES (1, '1'), (2, '[true, false]'), (3, '{"a":1,"b":2}'); |
| 57 |
INSERT INTO t(j) VALUES (''); |
| 58 |
ERROR 22032: Invalid JSON text: "The document is empty." at position 0 in value for column 't.j'. |
| 59 |
INSERT INTO t(j) VALUES ('['); |
| 60 |
ERROR 22032: Invalid JSON text: "Invalid value." at position 1 in value for column 't.j'. |
| 61 |
SELECT * FROM t ORDER BY id; |
| 62 |
id j gc |
| 63 |
1 1 [1] |
| 64 |
2 [true, false] [[true, false]] |
| 65 |
3 {"a": 1, "b": 2} [{"a": 1, "b": 2}] |
| 66 |
UPDATE t SET j = '"abc"'; |
| 67 |
SELECT * FROM t ORDER BY id; |
| 68 |
id j gc |
| 69 |
1 "abc" ["abc"] |
| 70 |
2 "abc" ["abc"] |
| 71 |
3 "abc" ["abc"] |
| 72 |
UPDATE t SET j = '['; |
| 73 |
ERROR 22032: Invalid JSON text: "Invalid value." at position 1 in value for column 't.j'. |
| 74 |
DROP TABLE t; |
| 75 |
CREATE TABLE t(ts TIMESTAMP, j JSON AS (CAST(ts AS JSON))); |
| 76 |
INSERT INTO t(ts) VALUES ('2000-01-01 00:00:00'); |
| 77 |
SELECT CAST(JSON_ARRAY(ts, j) AS CHAR) FROM t; |
| 78 |
CAST(JSON_ARRAY(ts, j) AS CHAR) |
| 79 |
["2000-01-01 00:00:00.000000", "2000-01-01 00:00:00.000000"] |
| 80 |
DROP TABLE t; |
| 81 |
# |
| 82 |
# Bug#21491442 VARIANT::FORCED_RETURN() [WITH T = JSON_SCALAR*]: |
| 83 |
# ASSERTION `FALSE' FAILED. |
| 84 |
# |
| 85 |
create table t (a json, b blob, |
| 86 |
c int generated always as (1!=a) virtual not null) engine=innodb; |
| 87 |
insert into t(a) values('[1]'); |
| 88 |
insert into t(a) values('[1]'); |
| 89 |
select a,c from t; |
| 90 |
a c |
| 91 |
[1] 1 |
| 92 |
[1] 1 |
| 93 |
prepare ps1 from 'insert into t(a) values(?)'; |
| 94 |
set @a='[1]'; |
| 95 |
execute ps1 using @a; |
| 96 |
execute ps1 using @a; |
| 97 |
select a,c from t; |
| 98 |
a c |
| 99 |
[1] 1 |
| 100 |
[1] 1 |
| 101 |
[1] 1 |
| 102 |
[1] 1 |
| 103 |
drop table t; |
| 104 |
create temporary table t (a json, b blob, |
| 105 |
c int generated always as (1!=a) virtual not null) engine=innodb; |
| 106 |
insert into t(a) values('[1]'); |
| 107 |
insert into t(a) values('[1]'); |
| 108 |
select a,c from t; |
| 109 |
a c |
| 110 |
[1] 1 |
| 111 |
[1] 1 |
| 112 |
prepare ps1 from 'insert into t(a) values(?)'; |
| 113 |
set @a='[1]'; |
| 114 |
execute ps1 using @a; |
| 115 |
execute ps1 using @a; |
| 116 |
select a,c from t; |
| 117 |
a c |
| 118 |
[1] 1 |
| 119 |
[1] 1 |
| 120 |
[1] 1 |
| 121 |
[1] 1 |
| 122 |
drop table t; |
| 123 |
# |
| 124 |
# WL#8170: Expression analyzer for GC. |
| 125 |
# Queries with GC and JSON_EXTRACT compared to strings should use index |
| 126 |
# |
| 127 |
create table t1( |
| 128 |
f1 json, |
| 129 |
gc varchar(20) character set utf8mb4 as |
| 130 |
(json_unquote(json_extract(f1,"$"))) stored, |
| 131 |
key gc_idx(gc)); |
| 132 |
insert into t1(f1) values ('"qwe"'),('"rty"'),('"uiop"'); |
| 133 |
insert into t1(f1) values ('"zxc"'),('"vbn"'),('"mnb"'); |
| 134 |
insert into t1(f1) select f1 from t1; |
| 135 |
insert into t1(f1) select f1 from t1; |
| 136 |
insert into t1(f1) values ('"asd"'),('"asdf"'),('"asasas"'); |
| 137 |
set @save_opt_sw= @@optimizer_switch; |
| 138 |
set @@optimizer_switch="index_condition_pushdown=off"; |
| 139 |
set @string_literal='asd'; |
| 140 |
select f1 from t1 where gc = "asd"; |
| 141 |
f1 |
| 142 |
"asd" |
| 143 |
explain select f1 from t1 where gc = "asd"; |
| 144 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 145 |
1 SIMPLE t1 NULL ref gc_idx gc_idx 83 const 1 100.00 NULL |
| 146 |
Warnings: |
| 147 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` = 'asd') |
| 148 |
select f1 from t1 where gc = @string_literal; |
| 149 |
f1 |
| 150 |
"asd" |
| 151 |
explain select f1 from t1 where gc = @string_literal; |
| 152 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 153 |
1 SIMPLE t1 NULL ref gc_idx gc_idx 83 const 1 100.00 NULL |
| 154 |
Warnings: |
| 155 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` = (@`string_literal`)) |
| 156 |
select f1 from t1 where json_extract(f1,"$") = "asd"; |
| 157 |
f1 |
| 158 |
"asd" |
| 159 |
explain select f1 from t1 where json_extract(f1,"$") = "asd"; |
| 160 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 161 |
1 SIMPLE t1 NULL ref gc_idx gc_idx 83 const 1 100.00 NULL |
| 162 |
Warnings: |
| 163 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` = 'asd') |
| 164 |
select f1 from t1 where json_extract(f1,"$") = @string_literal; |
| 165 |
f1 |
| 166 |
"asd" |
| 167 |
explain select f1 from t1 where json_extract(f1,"$") = @string_literal; |
| 168 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 169 |
1 SIMPLE t1 NULL ref gc_idx gc_idx 83 const 1 100.00 NULL |
| 170 |
Warnings: |
| 171 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` = (@`string_literal`)) |
| 172 |
select f1 from t1 where "asd" = json_extract(f1,"$"); |
| 173 |
f1 |
| 174 |
"asd" |
| 175 |
explain select f1 from t1 where "asd" = json_extract(f1,"$"); |
| 176 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 177 |
1 SIMPLE t1 NULL ref gc_idx gc_idx 83 const 1 100.00 NULL |
| 178 |
Warnings: |
| 179 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where ('asd' = `test`.`t1`.`gc`) |
| 180 |
select f1 from t1 where @string_literal = json_extract(f1,"$"); |
| 181 |
f1 |
| 182 |
"asd" |
| 183 |
explain select f1 from t1 where @string_literal = json_extract(f1,"$"); |
| 184 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 185 |
1 SIMPLE t1 NULL ref gc_idx gc_idx 83 const 1 100.00 NULL |
| 186 |
Warnings: |
| 187 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where ((@`string_literal`) = `test`.`t1`.`gc`) |
| 188 |
set @string_literal = 'z'; |
| 189 |
select f1 from t1 where gc > "z"; |
| 190 |
f1 |
| 191 |
"zxc" |
| 192 |
"zxc" |
| 193 |
"zxc" |
| 194 |
"zxc" |
| 195 |
explain select f1 from t1 where gc > "z"; |
| 196 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 197 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 198 |
Warnings: |
| 199 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` > 'z') |
| 200 |
select f1 from t1 where gc > @string_literal; |
| 201 |
f1 |
| 202 |
"zxc" |
| 203 |
"zxc" |
| 204 |
"zxc" |
| 205 |
"zxc" |
| 206 |
explain select f1 from t1 where gc > @string_literal; |
| 207 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 208 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 209 |
Warnings: |
| 210 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` > <cache>((@`string_literal`))) |
| 211 |
select f1 from t1 where json_extract(f1,"$") > "z"; |
| 212 |
f1 |
| 213 |
"zxc" |
| 214 |
"zxc" |
| 215 |
"zxc" |
| 216 |
"zxc" |
| 217 |
explain select f1 from t1 where json_extract(f1,"$") > "z"; |
| 218 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 219 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 220 |
Warnings: |
| 221 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` > 'z') |
| 222 |
select f1 from t1 where json_extract(f1,"$") > @string_literal; |
| 223 |
f1 |
| 224 |
"zxc" |
| 225 |
"zxc" |
| 226 |
"zxc" |
| 227 |
"zxc" |
| 228 |
explain select f1 from t1 where json_extract(f1,"$") > @string_literal; |
| 229 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 230 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 231 |
Warnings: |
| 232 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` > <cache>((@`string_literal`))) |
| 233 |
set @string_lo = 'v'; |
| 234 |
set @string_hi = 'z'; |
| 235 |
select f1 from t1 where gc > "v" and gc < "z"; |
| 236 |
f1 |
| 237 |
"vbn" |
| 238 |
"vbn" |
| 239 |
"vbn" |
| 240 |
"vbn" |
| 241 |
explain select f1 from t1 where gc > "v" and gc < "z"; |
| 242 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 243 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 244 |
Warnings: |
| 245 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where ((`test`.`t1`.`gc` > 'v') and (`test`.`t1`.`gc` < 'z')) |
| 246 |
select f1 from t1 where gc > @string_lo and gc < @string_hi; |
| 247 |
f1 |
| 248 |
"vbn" |
| 249 |
"vbn" |
| 250 |
"vbn" |
| 251 |
"vbn" |
| 252 |
explain select f1 from t1 where gc > @string_lo and gc < @string_hi; |
| 253 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 254 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 255 |
Warnings: |
| 256 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where ((`test`.`t1`.`gc` > <cache>((@`string_lo`))) and (`test`.`t1`.`gc` < <cache>((@`string_hi`)))) |
| 257 |
select f1 from t1 |
| 258 |
where json_extract(f1,"$") > "v" and json_extract(f1,"$") < "z"; |
| 259 |
f1 |
| 260 |
"vbn" |
| 261 |
"vbn" |
| 262 |
"vbn" |
| 263 |
"vbn" |
| 264 |
select f1 from t1 |
| 265 |
where json_extract(f1,"$") > @string_lo and json_extract(f1,"$") < @string_hi; |
| 266 |
f1 |
| 267 |
"vbn" |
| 268 |
"vbn" |
| 269 |
"vbn" |
| 270 |
"vbn" |
| 271 |
explain |
| 272 |
select f1 from t1 |
| 273 |
where json_extract(f1,"$") > @string_lo and json_extract(f1,"$") < @string_hi; |
| 274 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 275 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 276 |
Warnings: |
| 277 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where ((`test`.`t1`.`gc` > <cache>((@`string_lo`))) and (`test`.`t1`.`gc` < <cache>((@`string_hi`)))) |
| 278 |
select f1 from t1 where gc between "v" and "z"; |
| 279 |
f1 |
| 280 |
"vbn" |
| 281 |
"vbn" |
| 282 |
"vbn" |
| 283 |
"vbn" |
| 284 |
explain select f1 from t1 where gc between "v" and "z"; |
| 285 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 286 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 287 |
Warnings: |
| 288 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` between 'v' and 'z') |
| 289 |
select f1 from t1 where gc between @string_lo and @string_hi; |
| 290 |
f1 |
| 291 |
"vbn" |
| 292 |
"vbn" |
| 293 |
"vbn" |
| 294 |
"vbn" |
| 295 |
explain select f1 from t1 where gc between @string_lo and @string_hi; |
| 296 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 297 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 298 |
Warnings: |
| 299 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` between <cache>((@`string_lo`)) and <cache>((@`string_hi`))) |
| 300 |
select f1 from t1 where json_extract(f1,"$") between "v" and "z"; |
| 301 |
f1 |
| 302 |
"vbn" |
| 303 |
"vbn" |
| 304 |
"vbn" |
| 305 |
"vbn" |
| 306 |
Warning 1235 This version of MySQL doesn't yet support 'comparison of JSON in the BETWEEN operator' |
| 307 |
Warnings: |
| 308 |
explain select f1 from t1 where json_extract(f1,"$") between "v" and "z"; |
| 309 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 310 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 311 |
Warnings: |
| 312 |
Warning 1235 This version of MySQL doesn't yet support 'comparison of JSON in the BETWEEN operator' |
| 313 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` between 'v' and 'z') |
| 314 |
select f1 from t1 where json_extract(f1,"$") between @string_lo and @string_hi; |
| 315 |
f1 |
| 316 |
"vbn" |
| 317 |
"vbn" |
| 318 |
"vbn" |
| 319 |
"vbn" |
| 320 |
Warning 1235 This version of MySQL doesn't yet support 'comparison of JSON in the BETWEEN operator' |
| 321 |
Warnings: |
| 322 |
explain |
| 323 |
select f1 from t1 where json_extract(f1,"$") between @string_lo and @string_hi; |
| 324 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 325 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 4 100.00 Using where |
| 326 |
Warnings: |
| 327 |
Warning 1235 This version of MySQL doesn't yet support 'comparison of JSON in the BETWEEN operator' |
| 328 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` between <cache>((@`string_lo`)) and <cache>((@`string_hi`))) |
| 329 |
set @string_1 = 'asd'; |
| 330 |
set @string_2 = 'asasas'; |
| 331 |
set @string_3 = 'asdf'; |
| 332 |
select f1 from t1 where gc in ("asd","asasas","asdf"); |
| 333 |
f1 |
| 334 |
"asasas" |
| 335 |
"asd" |
| 336 |
"asdf" |
| 337 |
explain select f1 from t1 where gc in ("asd","asasas","asdf"); |
| 338 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 339 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 3 100.00 Using where |
| 340 |
Warnings: |
| 341 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` in ('asd','asasas','asdf')) |
| 342 |
select f1 from t1 where gc in (@string_1, @string_2, @string_3); |
| 343 |
f1 |
| 344 |
"asasas" |
| 345 |
"asd" |
| 346 |
"asdf" |
| 347 |
explain select f1 from t1 where gc in (@string_1, @string_2, @string_3); |
| 348 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 349 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 3 100.00 Using where |
| 350 |
Warnings: |
| 351 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` in (<cache>((@`string_1`)),<cache>((@`string_2`)),<cache>((@`string_3`)))) |
| 352 |
select f1 from t1 where json_extract(f1,"$") in ("asd","asasas","asdf"); |
| 353 |
f1 |
| 354 |
"asasas" |
| 355 |
"asd" |
| 356 |
"asdf" |
| 357 |
explain select f1 from t1 where json_extract(f1,"$") in ("asd","asasas","asdf"); |
| 358 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 359 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 3 100.00 Using where |
| 360 |
Warnings: |
| 361 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` in ('asd','asasas','asdf')) |
| 362 |
select f1 from t1 |
| 363 |
where json_extract(f1,"$") in (@string_1, @string_2, @string_3); |
| 364 |
f1 |
| 365 |
"asasas" |
| 366 |
"asd" |
| 367 |
"asdf" |
| 368 |
explain |
| 369 |
select f1 from t1 |
| 370 |
where json_extract(f1,"$") in (@string_1, @string_2, @string_3); |
| 371 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 372 |
1 SIMPLE t1 NULL range gc_idx gc_idx 83 NULL 3 100.00 Using where |
| 373 |
Warnings: |
| 374 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` in (<cache>((@`string_1`)),<cache>((@`string_2`)),<cache>((@`string_3`)))) |
| 375 |
select f1 from t1 where json_unquote(json_extract(f1,"$")) = "asd"; |
| 376 |
f1 |
| 377 |
"asd" |
| 378 |
explain select f1 from t1 where json_unquote(json_extract(f1,"$")) = "asd"; |
| 379 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 380 |
1 SIMPLE t1 NULL ref gc_idx gc_idx 83 const 1 100.00 NULL |
| 381 |
Warnings: |
| 382 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` = 'asd') |
| 383 |
select f1 from t1 where json_unquote(json_extract(f1,"$")) = @string_literal; |
| 384 |
f1 |
| 385 |
explain |
| 386 |
select f1 from t1 where json_unquote(json_extract(f1,"$")) = @string_literal; |
| 387 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 388 |
1 SIMPLE t1 NULL ref gc_idx gc_idx 83 const 1 100.00 NULL |
| 389 |
Warnings: |
| 390 |
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`gc` = (@`string_literal`)) |
| 391 |
set @@optimizer_switch= @save_opt_sw; |
| 392 |
drop table t1; |
| 393 |
create table t1(f1 varchar(10), gc varchar(10) as (json_unquote(f1)) stored, |
| 394 |
key gc_idx(gc)); |
| 395 |
insert into t1(f1) values ('"qwe"'),('"rty"'),('"uiop"'); |
| 396 |
select f1 from t1 where lower(f1)="qwe"; |
| 397 |
f1 |
| 398 |
drop table t1; |
| 399 |
# |
| 400 |
# |
| 401 |
# Bug#21054516:QUERY HAVING SQL_BIG_RESULT ON JSON DATA GIVES EXTRA |
| 402 |
# ROWS IN OUTPUT |
| 403 |
# |
| 404 |
CREATE TABLE t1 ( |
| 405 |
pk integer auto_increment key, |
| 406 |
col_varchar_255_utf8_key varchar(255) CHARACTER SET utf8 |
| 407 |
); |
| 408 |
Warnings: |
| 409 |
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. |
| 410 |
INSERT INTO t1 VALUES (NULL, 'q') , (NULL, 'tgzvsj') , |
| 411 |
(NULL, 'b') , (NULL, 'q') , (NULL, 'up') , (NULL, 'up') ; |
| 412 |
ALTER TABLE t1 ADD COLUMN json_varchar255_utf8_key json; |
| 413 |
UPDATE t1 SET json_varchar255_utf8_key = |
| 414 |
JSON_OBJECT('col_varchar_255_utf8_key', col_varchar_255_utf8_key); |
| 415 |
ALTER TABLE t1 MODIFY col_varchar_255_utf8_key VARCHAR(255) |
| 416 |
GENERATED ALWAYS AS |
| 417 |
(JSON_EXTRACT(json_varchar255_utf8_key,'$.col_varchar_255_utf8_key[0]')) |
| 418 |
STORED; |
| 419 |
SELECT SQL_BIG_RESULT table1.json_varchar255_utf8_key AS field1, count(*) |
| 420 |
FROM t1 AS table1 LEFT JOIN t1 AS table2 ON table1.pk <= table2.pk |
| 421 |
GROUP BY field1; |
| 422 |
field1 count(*) |
| 423 |
{"col_varchar_255_utf8_key": "up"} 3 |
| 424 |
{"col_varchar_255_utf8_key": "q"} 9 |
| 425 |
{"col_varchar_255_utf8_key": "b"} 4 |
| 426 |
{"col_varchar_255_utf8_key": "tgzvsj"} 5 |
| 427 |
Warnings: |
| 428 |
Warning 1235 This version of MySQL doesn't yet support 'sorting of non-scalar JSON values' |
| 429 |
DROP TABLE t1; |
| 430 |
# |
| 431 |
# Bug#26352119: WHERE JSON_EXTRACT() ON GEN KEY |
| 432 |
# |
| 433 |
SET NAMES utf8mb4 COLLATE utf8mb4_ja_0900_as_cs; |
| 434 |
CREATE TABLE t1 (j JSON, pk VARCHAR(10) AS (j->>'$.id') STORED PRIMARY KEY); |
| 435 |
INSERT INTO t1 (j) VALUES ('{"id":"a"}'), ('{"id":"b"}'), ('{"id":"c"}'); |
| 436 |
ANALYZE TABLE t1; |
| 437 |
Table Op Msg_type Msg_text |
| 438 |
test.t1 analyze status OK |
| 439 |
EXPLAIN SELECT * FROM t1 WHERE j->>'$.id'='b'; |
| 440 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 441 |
1 SIMPLE t1 NULL const PRIMARY PRIMARY 42 const 1 100.00 NULL |
| 442 |
Warnings: |
| 443 |
Note 1003 /* select#1 */ select '{"id": "b"}' AS `j`,'b' AS `pk` from `test`.`t1` where true |
| 444 |
SELECT * FROM t1 WHERE j->>'$.id'='b'; |
| 445 |
j pk |
| 446 |
{"id": "b"} b |
| 447 |
DROP TABLE t1; |
| 448 |
SET NAMES DEFAULT; |