Skip to content

Commit dcc9b66

Browse files
committed
Merge branch 'main' into visit-recursive-evaluation
2 parents 23b9abc + 48bf15f commit dcc9b66

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

ql/ql/src/codeql_ql/StructuredLogs.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ module KindPredicatesLog {
241241

242242
AppearsAs getAppearsAs() { result = this.getObject("appearsAs") }
243243

244+
int getMillis() { result = this.getNumber("millis") }
245+
244246
predicate hasCompletionTime(
245247
int year, string month, int day, int hours, int minute, int second, int millisecond
246248
) {
@@ -265,6 +267,12 @@ module KindPredicatesLog {
265267
Array getRA(string ordering) { result = this.getObject("ra").getArray(ordering) }
266268

267269
string getAnOrdering() { exists(this.getRA(result)) }
270+
271+
override string toString() {
272+
if exists(this.getPredicateName())
273+
then result = this.getPredicateName()
274+
else result = "<Summary event>"
275+
}
268276
}
269277

270278
class SentinelEmpty extends SummaryEvent {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Shows a list of the "slow" predicates by wallclock time.
3+
*/
4+
5+
import ql
6+
import codeql_ql.StructuredLogs
7+
8+
int predicateRank(KindPredicatesLog::SummaryEvent evt) {
9+
evt =
10+
rank[result](KindPredicatesLog::SummaryEvent y, int m | m = y.getMillis() | y order by m desc)
11+
}
12+
13+
from KindPredicatesLog::SummaryEvent evt
14+
where predicateRank(evt) < 50
15+
select evt, evt.getMillis() as time order by time desc
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)