Hi @morrie, If your objective is to optimize the query, I’d recommend optimizing the beer segment of the query. You could create the following index
create index beer_brewery on
beer-sample(type,brewery_id) where type=“beer” using GSI;
and push the optimization before the join to filter as much as possible using both the b.type=“beer” and b.brewery_id="…". with the nested loop join, this will eliminate the number of items you need to loop over in “b” (beers).
select br.name brewery, b.name beer, b.style style, b.brewery_id from
beer-sample b join
beer-sample br on keys b.brewery_id where b.type=“beer” and b.brewery_id=“yards_brewing” order by beer, style;
if you can compare the “explains”, you will see that you can avoid the primary scan with the index and push the filter earlier in the exec plan.
does this help?