Is it possible to create effective index on jsonb column to timestamp value in postgresql?
I tried this advice Create timestamp index from JSON on PostgreSQL but ORDER and SIMPLE WHERE operations are still using seq scan without index.
And query execution time with an index and without index no difference:
SELECT * FROM bums.mytable_no_ind ORDER BY (ts->>'date')::TIMESTAMP DESC
and
EXPLAIN ANALYZE SELECT * FROM bums.mytable_no_ind WHERE (ts->>'date')::TIMESTAMP = NOW()
Information about table:
create table bums.mytable_no_ind (
s serial primary key,
ts jsonb,
x int,
y int,
z int
);
insert into bums.mytable_no_ind (ts, x, y, z)
select
('{"date": "' || clock_timestamp() || '"}')::jsonb,
500 * RANDOM(),
500 * RANDOM(),
500 * RANDOM()
from generate_series(1, 1000000)
;