Selects and Macros in Where Clauses

If a where clause makes use of a select, the product evaluates the select for each object found by the query. However, when using a macro, the macro is evaluated one time only. This can result in a drastic performance difference.

In the sample queries below, the first query uses a select, while the second query uses a macro. The first query will return all the objects that match it, then apply the where clause. The second query will evaluate the macro and use the result as part of the query. As a result, it will return a smaller subset that already matches the owner, giving far better performance.

Examples:

temp query bus <TYPE> * * where owner = context.user
temp query bus <TYPE> * * where owner = $USER