I think that there is a useful optimization we could make where we drop data variables that aren't used in the query before calling "pivot".