Gary Bentley - 2011-03-29

Hi,

This is deliberate. The functions are not aware of grouping/aggregation operations such as "count". Instead it is better to do:

SELECT :_allobjs.size
FROM Type
WHERE 1 = 1

Performance can also be improved by using the "EXECUTE ON" clauses which ensure that operations are only executed once.

Below is an example of a query from the polliwog project that uses those clauses:

SELECT name name,
@pages pages,
visitCount visitCount,
@downloads downloads,
@start start,
@end end
FROM org.polliwog.data.SearchEngineVisit
GROUP BY name
GROUP BY ORDER @pages DESC
GROUP BY LIMIT 1,10
LIMIT 1,1
EXECUTE ON GROUP_BY_RESULTS sum (pagesCount) pages,
sum (downloadSize) downloads,
min (fromDate) start,
max (toDate) end
EXECUTE ON ALL sum(pagesCount) totalPages,
sum(downloadSize) totalDownloads,
min(fromDate) searchStart,
max(toDate) searchEnd,
sum (:_allobjs, visitCount) totalVisits,
grp (:_allobjs,
name).size engines