I have a table:
CREATE TABLE skill (
user_id integer NOT NULL,
data jsonb
);
And gin index on jsonb column:
CREATE INDEX idx_user_id_knowledge ON skill USING gin (data);
INSERT INTO skill(user_id, data)
VALUES (1, '{"technology": "PHP", "knowledge": 77 }'),
(2, '{"technology": "PHP", "knowledge": 79 }'),
(3, '{"technology": "PHP", "knowledge": 97 }'),
(4, '{"technology": "MySQL", "knowledge": 85 }'),
(5, '{"technology": "MySQL", "knowledge": 89 }');
But when I run EXPLAIN query:
EXPLAIN
SELECT * FROM skill
WHERE data->>'technology' = 'PHP' AND (data->>'knowledge')::NUMERIC > 50;
The output is as follows:
Seq Scan on skill (cost=0.00..41.75 rows=2 width=36)
Filter: (((data ->> 'technology'::text) = 'PHP'::text) AND (((data ->> 'knowledge'::text))::numeric > '50'::numeric))
Why doesn't the query planner use the gin index I created instead of Seq. Scan ?