Improve analysis of aggregate functions in selection