I was trying MySQL secondary indexing referring to MySQL Documentation, and weird thing happened.
- Firstly, I created a table with small modification per the example in the document
create table jemp(
c JSON,
g VARCHAR(20) GENERATED ALWAYS AS (c->"$.name"),
INDEX i (g)
)
- Secondly, I inserted values per the example in the document
INSERT INTO jemp (c) VALUES
('{"id": "1", "name": "Fred"}'), ('{"id": "2", "name": "Wilma"}'),
('{"id": "3", "name": "Barney"}'), ('{"id": "4", "name": "Betty"}');
- And then, I tried to perform a fuzzy search with "like" and "wildcard". This doesn't work because index doesn't support prefix
%, but it can get result.
select c->"$.name" as name from jemp where g like "%F%"
- Here is the weird thing, I removed the prefix
%, and index did work. However, I didn't get any results. Per my poor understanding of MySQL, this should work.
select c->"$.name" as name from jemp where g like "F%"
I would be so much appreciate if anyone could help me with it.