QL: Add a query for computing the join order metric for non-recursive predicates.

This commit is contained in:
Mathias Vorreiter Pedersen
2023-02-23 14:27:39 +00:00
parent d734982e7b
commit d7d9bea5e8

View File

@@ -0,0 +1,29 @@
/**
* Shows a list of the non-recursive predicates with the worst join order as determined
* by the join order metric.
*/
import ql
import codeql_ql.StructuredLogs
import KindPredicatesLog
/**
* Gets the badness of a non-recursive predicate evaluation.
*
* The badness is the maximum number of tuples in the pipeline divided by the
* maximum of two numbers: the size of the result and the size of the largest dependency.
*/
float getBadness(ComputeSimple simple) {
exists(float maxTupleCount, float resultSize, float largestDependency, float denom |
resultSize = simple.getResultSize() and
maxTupleCount = max(simple.getPipelineRun().getCount(_)) and
largestDependency = max(simple.getDependencies().getADependency().getResultSize()) and
denom = resultSize.maximum(largestDependency) and
denom > 0 and // avoid division by zero (which would create a NaN result).
result = maxTupleCount / denom
)
}
from ComputeSimple evt, float f
where f = getBadness(evt) and f > 1.5
select evt, f order by f desc