I got millions of points stored with a PointZM (lon,lat,depth, time epoch) geometry column
ST_SetSRID(st_makepoint(longitude,latitude,-z,date_part('epoch', "timestamp"::timestamp)),4326) as timegeom
I have created a GIST(geometry gist_geometry_ops_nd) index on the column
Now, how to query this in space and time?
I have tried using the &&& operator:
select * from huge_spatial_table
where timegeom &&& st_3dmakebox(st_setsrid(st_makepoint(0.05278027,29.47846469,0,date_part('epoch', '2013-01-01'::timestamp)),4326),
st_setsrid(st_makepoint(37.50180758,45.37019107,-50,date_part('epoch', '2018-01-01'::timestamp)),4326))
But the time dimension is not filtered when doing this.
When filtering time using st_m(geometry) it works, but the index is not used on the time dimension which is what I want.
select * from huge_spatial_table
where timegeom &&& st_3dmakebox(st_setsrid(st_makepoint(0.05278027,29.47846469,0,date_part('epoch', '2013-01-01'::timestamp)),4326),
st_setsrid(st_makepoint(37.50180758,45.37019107,-50,date_part('epoch', '2018-01-01'::timestamp)),4326))
and st_m(timegeom)>date_part('epoch', '2013-01-01'::timestamp)
and st_m(timegeom)<date_part('epoch', '2018-01-01'::timestamp)
Explain:
"Index Scan using idx_huge_spatial_table on huge_spatial_table (cost=0.55..2.78 rows=1 width=184)"
" Index Cond: (timegeom &&& '010F0000A0E6100000060000000103000080010000000500000045500CFB0306AB3F3DD773A97C7A3D40000000000000000045500CFB0306AB3FEB75C56B62AF46400000000000000000117E143B3BC04240EB75C56B62AF46400000000000000000117E143B3BC042403DD773A97C7A3D40000000000000000045500CFB0306AB3F3DD773A97C7A3D4000000000000000000103000080010000000500000045500CFB0306AB3F3DD773A97C7A3D4000000000000049C0117E143B3BC042403DD773A97C7A3D4000000000000049C0117E143B3BC04240EB75C56B62AF464000000000000049C045500CFB0306AB3FEB75C56B62AF464000000000000049C045500CFB0306AB3F3DD773A97C7A3D4000000000000049C00103000080010000000500000045500CFB0306AB3F3DD773A97C7A3D40000000000000000045500CFB0306AB3F3DD773A97C7A3D4000000000000049C045500CFB0306AB3FEB75C56B62AF464000000000000049C045500CFB0306AB3FEB75C56B62AF4640000000000000000045500CFB0306AB3F3DD773A97C7A3D40000000000000000001030000800100000005000000117E143B3BC042403DD773A97C7A3D400000000000000000117E143B3BC04240EB75C56B62AF46400000000000000000117E143B3BC04240EB75C56B62AF464000000000000049C0117E143B3BC042403DD773A97C7A3D4000000000000049C0117E143B3BC042403DD773A97C7A3D4000000000000000000103000080010000000500000045500CFB0306AB3F3DD773A97C7A3D400000000000000000117E143B3BC042403DD773A97C7A3D400000000000000000117E143B3BC042403DD773A97C7A3D4000000000000049C045500CFB0306AB3F3DD773A97C7A3D4000000000000049C045500CFB0306AB3F3DD773A97C7A3D4000000000000000000103000080010000000500000045500CFB0306AB3FEB75C56B62AF4640000000000000000045500CFB0306AB3FEB75C56B62AF464000000000000049C0117E143B3BC04240EB75C56B62AF464000000000000049C0117E143B3BC04240EB75C56B62AF4640000000000000000045500CFB0306AB3FEB75C56B62AF46400000000000000000'::geometry)"
" Filter: ((st_m(timegeom) > '1356998400'::double precision) AND (st_m(timegeom) < '1514764800'::double precision))"
Is it even possible to do spatio-temporal queries using an index in PostGIS?
Btw, I am using postgres 9.6 and PostGIS 2.3.2