I have a table called objects
with a jsonb
column, and I’m trying to run a query to get distinct key-value pairs from the JSON data. Currently, I’m using the following query:
SELECT DISTINCT keys, values
FROM objects, LATERAL jsonb_each_text(tags) AS each(keys, values);
However, this query is relatively slow, and I’m wondering if there are ways to optimize it.
How can I speed up this query?
Is it possible to create an index on the result of the LATERAL jsonb_each_text(tags) function to improve performance?
Can we avoid using materialized view (ref: How to index on an array of jsonb objects to get distinct values)?
5