Here is my json
jsondata
------------------------------------
{"key1": 1, "keyset": [10, 20, 30]}
{"key1": 1, "keyset": [10, 20]}
{"key1": 1, "keyset": [30]}
{"key1": 1 }
{"key1": 1, "key2": 1}
I tried creating index keyset
for above example
1st index using btree
CREATE INDEX test_keyset ON test_table (jsondata->'keyset');
2nd index using gin
CREATE INDEX test_keyset ON test_table USING GIN(jsondata->'keyset');
and query to select keyset
value 10,
SELECT jsondata
FROM test
JOIN LATERAL jsonb_array_elements_text(jsondata->'keyset') a(v)
ON TRUE
WHERE a.v::integer = 10;
but it is doing sequential scan(checking all rows), can anyone suggest me about which indexing method is correct(btree or gin) and efficient way of getting data from json using indexing for above example, I'm new to postgres