Following on from my previous question on this topic, Postgres combining multiple Indexes:
I have the following table on Postgres 9.2 (with postgis):
CREATE TABLE updates (
update_id character varying(50) NOT NULL,
coords geography(Point,4326) NOT NULL,
user_id character varying(50) NOT NULL,
created_at timestamp without time zone NOT NULL
);
And I am running following query on the table:
select *
from updates
where ST_DWithin(coords, ST_MakePoint(-126.4, 45.32)::geography, 30000)
and user_id='3212312'
order by created_at desc
limit 60
So given that, what Index should I use for (coords + user_id), GIST or BTree?
CREATE INDEX ix_coords_user_id ON updates USING GIST (coords, user_id);
OR
CREATE INDEX ix_coords_user_id ON updates (coords, user_id);
I was reading that BTree performs better than GIST, but am I forced to use GIST since I am using postgis geography field??
explain analyze
for both; paste the plans on explain.depesz.com and link to them here. – Craig Ringer