You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Patch #1: Support view references in generated column substitution.
REF_ITEM was not considered in Item::can_be_substituted_for_gc() and
get_gc_for_expr(), so optimizer failed to use multi-valued index
from a view.
The patch is also applicable to view references in general, thus not
restricted to multi-valued indexes.
This is a contribution by Yubao Liu.
Change-Id: Iaa82a1245c80641fab0ed3a2d0f459e4e9bc26c1
Copy file name to clipboardExpand all lines: mysql-test/suite/json/r/array_index.result
+119Lines changed: 119 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2455,4 +2455,123 @@ vc j
2455
2455
[2,3,4] [2, 3, 4]
2456
2456
[3,4,5] [3, 4, 5]
2457
2457
DROP TABLE t;
2458
+
# Bug#33275457: Fix multi-valued index
2459
+
CREATE TABLE t1 (
2460
+
f1 VARCHAR(50) NOT NULL PRIMARY KEY,
2461
+
f2 JSON NOT NULL,
2462
+
INDEX idx2 ( (CAST(f2 AS CHAR(50) ARRAY)) )
2463
+
);
2464
+
CREATE VIEW v1 AS
2465
+
SELECT * FROM t1, JSON_TABLE(f2, '$[*]' COLUMNS(i FOR ORDINALITY, id VARCHAR(50) PATH '$')) AS ids;
2466
+
INSERT INTO t1 VALUES ('foo', '["aa", "bb"]'), ('bar', '["xx", "yy"]');
2467
+
ANALYZE TABLE t1;
2468
+
Table Op Msg_type Msg_text
2469
+
test.t1 analyze status OK
2470
+
EXPLAIN SELECT * FROM t1 WHERE 'xx' MEMBER OF (f2);
2471
+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2472
+
1 SIMPLE t1 NULL ref idx2 idx2 203 const 1 100.00 Using where
2473
+
Warnings:
2474
+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` where json'"xx"' member of (cast(`f2` as char(50) array))
2475
+
EXPLAIN SELECT * FROM t1 WHERE json_contains(f2, '"xx"');
2476
+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2477
+
1 SIMPLE t1 NULL range idx2 idx2 203 NULL 1 100.00 Using where; Using MRR
2478
+
Warnings:
2479
+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` where json_contains(cast(`f2` as char(50) array),json'["xx"]')
2480
+
EXPLAIN SELECT * FROM t1 WHERE json_overlaps(f2, '["xx", "zz"]');
2481
+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2482
+
1 SIMPLE t1 NULL range idx2 idx2 203 NULL 2 100.00 Using where; Using MRR
2483
+
Warnings:
2484
+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` where json_overlaps(cast(`f2` as char(50) array),json'["xx", "zz"]')
2485
+
EXPLAIN SELECT * FROM v1 WHERE 'xx' MEMBER OF (f2);
2486
+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2487
+
1 SIMPLE t1 NULL ref idx2 idx2 203 const 1 100.00 Using where
2488
+
1 SIMPLE ids NULL ALL NULL NULL NULL NULL 2 100.00 Table function: json_table; Using temporary
2489
+
Warnings:
2490
+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`ids`.`i` AS `i`,`ids`.`id` AS `id` from `test`.`t1` join json_table(`test`.`t1`.`f2`, '$[*]' columns (`i` for ordinality, `id` varchar(50) character set utf8mb4 path '$')) `ids` where json'"xx"' member of (cast(`f2` as char(50) array))
2491
+
EXPLAIN SELECT * FROM v1 WHERE json_contains(f2, '"xx"');
2492
+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2493
+
1 SIMPLE t1 NULL range idx2 idx2 203 NULL 1 100.00 Using where; Using MRR
2494
+
1 SIMPLE ids NULL ALL NULL NULL NULL NULL 2 100.00 Table function: json_table; Using temporary
2495
+
Warnings:
2496
+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`ids`.`i` AS `i`,`ids`.`id` AS `id` from `test`.`t1` join json_table(`test`.`t1`.`f2`, '$[*]' columns (`i` for ordinality, `id` varchar(50) character set utf8mb4 path '$')) `ids` where json_contains(cast(`f2` as char(50) array),json'["xx"]')
2497
+
EXPLAIN SELECT * FROM v1 WHERE json_overlaps(f2, '["xx", "zz"]');
2498
+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2499
+
1 SIMPLE t1 NULL range idx2 idx2 203 NULL 2 100.00 Using where; Using MRR
2500
+
1 SIMPLE ids NULL ALL NULL NULL NULL NULL 2 100.00 Table function: json_table; Using temporary
2501
+
Warnings:
2502
+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`ids`.`i` AS `i`,`ids`.`id` AS `id` from `test`.`t1` join json_table(`test`.`t1`.`f2`, '$[*]' columns (`i` for ordinality, `id` varchar(50) character set utf8mb4 path '$')) `ids` where json_overlaps(cast(`f2` as char(50) array),json'["xx", "zz"]')
2503
+
EXPLAIN
2504
+
SELECT *
2505
+
FROM t1, JSON_TABLE(f2, '$[*]' COLUMNS(i FOR ORDINALITY, id VARCHAR(50)
2506
+
PATH '$')) AS ids
2507
+
WHERE 'xx' MEMBER OF (f2);
2508
+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2509
+
1 SIMPLE t1 NULL ref idx2 idx2 203 const 1 100.00 Using where
2510
+
1 SIMPLE ids NULL ALL NULL NULL NULL NULL 2 100.00 Table function: json_table; Using temporary
2511
+
Warnings:
2512
+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`ids`.`i` AS `i`,`ids`.`id` AS `id` from `test`.`t1` join json_table(`test`.`t1`.`f2`, '$[*]' columns (`i` for ordinality, `id` varchar(50) character set utf8mb4 path '$')) `ids` where json'"xx"' member of (cast(`f2` as char(50) array))
2513
+
EXPLAIN
2514
+
SELECT *
2515
+
FROM t1, JSON_TABLE(f2, '$[*]' COLUMNS(i FOR ORDINALITY, id VARCHAR(50)
2516
+
PATH '$')) AS ids
2517
+
WHERE json_contains(f2, '"xx"');
2518
+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2519
+
1 SIMPLE t1 NULL range idx2 idx2 203 NULL 1 100.00 Using where; Using MRR
2520
+
1 SIMPLE ids NULL ALL NULL NULL NULL NULL 2 100.00 Table function: json_table; Using temporary
2521
+
Warnings:
2522
+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`ids`.`i` AS `i`,`ids`.`id` AS `id` from `test`.`t1` join json_table(`test`.`t1`.`f2`, '$[*]' columns (`i` for ordinality, `id` varchar(50) character set utf8mb4 path '$')) `ids` where json_contains(cast(`f2` as char(50) array),json'["xx"]')
2523
+
EXPLAIN
2524
+
SELECT *
2525
+
FROM t1, JSON_TABLE(f2, '$[*]' COLUMNS(i FOR ORDINALITY, id VARCHAR(50)
2526
+
PATH '$')) AS ids
2527
+
WHERE json_overlaps(f2, '["xx", "zz"]');
2528
+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
2529
+
1 SIMPLE t1 NULL range idx2 idx2 203 NULL 2 100.00 Using where; Using MRR
2530
+
1 SIMPLE ids NULL ALL NULL NULL NULL NULL 2 100.00 Table function: json_table; Using temporary
2531
+
Warnings:
2532
+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`ids`.`i` AS `i`,`ids`.`id` AS `id` from `test`.`t1` join json_table(`test`.`t1`.`f2`, '$[*]' columns (`i` for ordinality, `id` varchar(50) character set utf8mb4 path '$')) `ids` where json_overlaps(cast(`f2` as char(50) array),json'["xx", "zz"]')
2533
+
SELECT * FROM t1 WHERE 'xx' MEMBER OF (f2);
2534
+
f1 f2
2535
+
bar ["xx", "yy"]
2536
+
SELECT * FROM t1 WHERE json_contains(f2, '"xx"');
2537
+
f1 f2
2538
+
bar ["xx", "yy"]
2539
+
SELECT * FROM t1 WHERE json_overlaps(f2, '["xx", "zz"]');
2540
+
f1 f2
2541
+
bar ["xx", "yy"]
2542
+
SELECT * FROM v1 WHERE 'xx' MEMBER OF (f2);
2543
+
f1 f2 i id
2544
+
bar ["xx", "yy"] 1 xx
2545
+
bar ["xx", "yy"] 2 yy
2546
+
SELECT * FROM v1 WHERE json_contains(f2, '"xx"');
2547
+
f1 f2 i id
2548
+
bar ["xx", "yy"] 1 xx
2549
+
bar ["xx", "yy"] 2 yy
2550
+
SELECT * FROM v1 WHERE json_overlaps(f2, '["xx", "zz"]');
2551
+
f1 f2 i id
2552
+
bar ["xx", "yy"] 1 xx
2553
+
bar ["xx", "yy"] 2 yy
2554
+
SELECT *
2555
+
FROM t1, JSON_TABLE(f2, '$[*]' COLUMNS(i FOR ORDINALITY, id VARCHAR(50)
2556
+
PATH '$')) AS ids
2557
+
WHERE 'xx' MEMBER OF (f2);
2558
+
f1 f2 i id
2559
+
bar ["xx", "yy"] 1 xx
2560
+
bar ["xx", "yy"] 2 yy
2561
+
SELECT *
2562
+
FROM t1, JSON_TABLE(f2, '$[*]' COLUMNS(i FOR ORDINALITY, id VARCHAR(50)
2563
+
PATH '$')) AS ids
2564
+
WHERE json_contains(f2, '"xx"');
2565
+
f1 f2 i id
2566
+
bar ["xx", "yy"] 1 xx
2567
+
bar ["xx", "yy"] 2 yy
2568
+
SELECT *
2569
+
FROM t1, JSON_TABLE(f2, '$[*]' COLUMNS(i FOR ORDINALITY, id VARCHAR(50)
0 commit comments