codeql icon indicating copy to clipboard operation
codeql copied to clipboard

Confused about the query time

Open icy17 opened this issue 1 year ago • 1 comments
trafficstars

Hi! I'm using a query like:

from FunctionCall target
 where
 predicate1(target)
 and predicate2(target)
 and predicate3(target)
 and predicate4(target)
 select target, target.getLocation().toString()

I found that if I query one predicate at a time, the time is very short, if I query 4 times separately, will the intersection of the results be the result of querying all the predicates at once? If so, why is the sum of the time for the separate query so much shorter than the time for the one-time query?

icy17 avatar Jul 19 '24 10:07 icy17

I'm not sure I fully understand your question. I assume you are using the CodeQL for VSCode extension's quick-evaluation feature to evaluate the 4 predicates in isolation and to run the query as a whole. Measuring runtime like that is quite tricky, because CodeQL caches intermediate results, so if you ran the whole query, the individual predicates are likely to be fast because their results are in the cache. There is a command CodeQL: Clear Cache that might help a bit.

Another difference is that the whole query calculates the locations and their toString values. This probably doesn't cost much time, but if there are a lot of locations it might be noticeable.

aibaars avatar Jul 19 '24 15:07 aibaars