Skip to content

Commit d7d9bea

Browse files
committed
QL: Add a query for computing the join order metric for non-recursive predicates.
1 parent d734982 commit d7d9bea

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Shows a list of the non-recursive predicates with the worst join order as determined
3+
* by the join order metric.
4+
*/
5+
6+
import ql
7+
import codeql_ql.StructuredLogs
8+
import KindPredicatesLog
9+
10+
/**
11+
* Gets the badness of a non-recursive predicate evaluation.
12+
*
13+
* The badness is the maximum number of tuples in the pipeline divided by the
14+
* maximum of two numbers: the size of the result and the size of the largest dependency.
15+
*/
16+
float getBadness(ComputeSimple simple) {
17+
exists(float maxTupleCount, float resultSize, float largestDependency, float denom |
18+
resultSize = simple.getResultSize() and
19+
maxTupleCount = max(simple.getPipelineRun().getCount(_)) and
20+
largestDependency = max(simple.getDependencies().getADependency().getResultSize()) and
21+
denom = resultSize.maximum(largestDependency) and
22+
denom > 0 and // avoid division by zero (which would create a NaN result).
23+
result = maxTupleCount / denom
24+
)
25+
}
26+
27+
from ComputeSimple evt, float f
28+
where f = getBadness(evt) and f > 1.5
29+
select evt, f order by f desc

0 commit comments

Comments
 (0)