title: How to redesign a database to find distinct values more effectively?
body: <p>I often have a need to select a set of distincs values from a column with low selectivity in a big table while joining it to some other table where I can't really filter the entries in the resulting set to some reasonable amount.</p>
  
  <p>For example, I have a table with 20M rows, with column someID which has 200 unique values. I join this table with some other result set on another column and filter 20M rows down to, say, 10M rows (still a lot), and then need to find distinct someID. So I end up with a 10M rows scan no matter what, which is a pain.</p>
  
  <p>In this join, there is no way to filter the results more, 10M records is really the set I need to find distint someID in.</p>
  
  <p>Is there any standard approach to redesign the tables or create some additional table to make this work better? </p>