Restructure the query for max=foo so Postgres chooses a better execution plan.