Ich habe die folgende Abfrage:PostgreSQL-Index für jsonb @> Suche
SELECT "survey_results".* FROM "survey_results" WHERE (raw @> '{"client":{"token":"test_token"}}');
EXPLAIN ANALYZE
kehrt folgende Ergebnisse:
Seq Scan on survey_results (cost=0.00..352.68 rows=2 width=2039) (actual time=132.942..132.943 rows=1 loops=1)
Filter: (raw @> '{"client": {"token": "test_token"}}'::jsonb)
Rows Removed by Filter: 2133
Planning time: 0.157 ms
Execution time: 132.991 ms
(5 rows)
Ich möchte auf client
Schlüssel in raw
Feldindex hinzufügen, so wird die Suche schneller. Ich weiß nicht, wie ich es machen soll. Wenn ich Index für ganze raw
Spalte wie folgt hinzu:
CREATE INDEX test_index on survey_results USING GIN (raw);
dann funktioniert alles wie erwartet. Ich will Index für ganzes raw
nicht hinzufügen, weil ich viele Aufzeichnungen in der Datenbank habe und ich nicht seine Größe vergrößern möchte.