Optimize aggregations over partition keys into simple metadata queries

Queries with the following shape are executed against partition metadata

```sql
SELECT min(key), max(key) FROM t
SELECT DISTINCT key FROM t
```