set work_mem=24000; before running the query. postgres is doing merge and sort on disc, that's always slow. is there an index on column isin ? -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general