Yeah I mean it's pretty annoying that DISTINCT isn't smart enough in postgres to use this optimization. Still haven't found an optimization that works for doing DISTINCT after filtering by a field. (I.e. all distinct device_ids that show up for domain foo.)