Optimize planning for queries with large number of fields

This improves planning time by ~70x (from 3 minutes to 2.5s) when selecting from a table with 16k columns.