title: in postgres, is it possible to optimize a VIEW of UNIONs
body: <p>in the database there are many identical schemas, <code>cmp01</code>..<code>cmpa0</code></p>
  
  <p>each schema has a <code>users</code> table</p>
  
  <p>each schema's <code>users</code> table's primary key has its own unique range</p>
  
  <p>for example, in <code>cmp01.users</code> the <code>usr_id</code> is between <code>0x01000000 and 0x01ffffffff</code>.</p>
  
  <p>is there any way I could define a VIEW <code>global.users</code> that is a union of each of the <code>cmp*.union</code> tables in such a way that, if querying by <code>usr_id</code>, the optimizer would head for the correct schema?</p>
  
  <p>was thinking something like:</p>
  
  <pre><code>create view global.users as
  select * from cmp01.users where usr_id between 0x01000000 and 0x01ffffffff
  union all
  select * from cmp02.users where usr_id between 0x02000000 and 0x02ffffffff
  ....
  </code></pre>
  
  <p>would this work?  NO.  EXPLAIN ANALYZE shows all schema used.</p>
  
  <p>Is there an approach that might give good hints to the optimizer?</p>