From d7d9bea5e8f1bd67109dfa2859d42d73057d006f Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Thu, 23 Feb 2023 14:27:39 +0000 Subject: [PATCH] QL: Add a query for computing the join order metric for non-recursive predicates. --- .../src/queries/performance/LargeJoinOrder.ql | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ql/ql/src/queries/performance/LargeJoinOrder.ql diff --git a/ql/ql/src/queries/performance/LargeJoinOrder.ql b/ql/ql/src/queries/performance/LargeJoinOrder.ql new file mode 100644 index 00000000000..3d51affd20f --- /dev/null +++ b/ql/ql/src/queries/performance/LargeJoinOrder.ql @@ -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