title: SQL query on one to many relationship with multiple filters
body: <p>I have some experience with SQL but I still couldn't find out how can I do the following query performance efficient.</p>
  
  <p>I have 2 tables - <code>Box</code> and <code>Item</code>. <code>Box</code> has <code>id</code> attribute which is the primary key (and some more), and <code>Item</code> has <code>box_id</code>, <code>type</code>, <code>name</code>. Each table has billions of records, each box has on average 10 items.
  <strong>I want to query all the boxes that have at least one item with a given type, and at least one item with a given name (could be the same item or different).</strong> The query should be paginated with page size of 10.
  I used single column indexing on all <code>Item</code> attributes. The following query for that (the first page) takes a very long duration (more than a minute):</p>
  
  <p><code>SELECT Box.id FROM Box WHERE 
  (EXISTS (SELECT 1 FROM Item WHERE Item.box_id = Box.id AND Item.type = 'my_type')) AND
  (EXISTS (SELECT 1 FROM Item WHERE Item.box_id = Box.id AND Item.name = 'my_name'))
  LIMIT 10
  </code></p>
  
  <p>I think that the problem is making the intersection between boxes filtered in each part of the query (querying with just one of the constraints returns about million records). I am using Aurora PostgreSQL 9.6.6.</p>