My guess is that this is the problem
Hash Cond: ((table1.id)::double precision = table2.id)
Your query is casting the table1.id
to something with a fractional portion. This likely throws off planner estimates. Is id
an int or a double? Try removing your cast.
Also, don't write SQL-89:
SELECT id
FROM table1
INNER JOIN table2 USING (id)
WHERE ST_Intersects(
ST_Transform(ST_SetSRID(table2.the_geom, 2768), 4326),
ST_SetSRID(
ST_MakeBox2D(
ST_Point(-122.2119140625,38.013476231041935),
ST_Point(-122.18994140625,38.03078569382294)
),
4326
)
);