Using ST_DWithin in subquery (PostGIS)
The query as originally written is a very inefficient way of answering this question as it involves essentially a spatial self-join, whereas in fact, the OP only wanted to know the points that were more than 5km away from the single point with id=34567. A self joins would be used if you wanted to find all points more than 5km away from all other points for every point, which is essentially an 0(n^2) operation.
An explain on the original query will show a nested loop with two full sequence scans (ie, points A and points B) plus the spatial join of ST_DWithin.
The query can be much better written as
SELECT count(S.id) FROM points AS S WHERE not ST_Dwithin(S.geometry,
(select geometry from points where id=34567), 5000);
assuming that there is an index on id and a spatial index on geometry.