I have a query that is very fast in finding the records it wants, but it takes too long to "extract" the data from the JSON field if I have a few hundred results. Is there a way to speed up the extraction process with this query and data structure? At about 500 results, the query takes around 3 seconds. If I remove the extract, it's basically instant.
The query returns exactly the data that I want, it's just too slow:
SELECT
unit_uid,
JSON_EXTRACT(rateplans, '$."2023-03-14"','$."2023-03-15"') AS rateplans
FROM
property_listings_rateplans
WHERE
unit_uid IN (1527,1639,5,9,17,20,24,27,1873,4279)
The structure of the data is like this but with a lot more values and more dates in the rateplans data:
unit_uid (int) | rateplans (JSON) |
---|---|
1527 | { "2023-03-14": { "date": "2022-12-02", "price": 17500, "online": 1 }, "2023-03-15": { "date": "2022-12-03", "price": 17500, "online": 1 }, } |
1639 | { "2023-03-14": { "date": "2022-12-02", "price": 17500, "online": 1, }, "2023-03-15": { "date": "2022-12-03", "price": 17500, "online": 1, },} |
Any ideas on how I should tackle this?
Edit: I should also add that there will eventually be millions of unit_uids and approximately 2 years worth of dates in each JSON field as well as more key:value pairs within each date. This is just a sample of the live data.