mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Merge pull request #12298 from MathiasVP/join-order-metric-query-with-more-rows
QL: Output more rows in the join order query
This commit is contained in:
@@ -273,6 +273,8 @@ module KindPredicatesLog {
|
||||
then result = this.getPredicateName()
|
||||
else result = "<Summary event>"
|
||||
}
|
||||
|
||||
Array getRA(string ordering) { result = this.getObject("ra").getArray(ordering) }
|
||||
}
|
||||
|
||||
class SentinelEmpty extends SummaryEvent {
|
||||
@@ -288,8 +290,12 @@ module KindPredicatesLog {
|
||||
|
||||
string getRAReference() { result = this.getString("raReference") }
|
||||
|
||||
Array getCounts() { result = this.getArray("counts") }
|
||||
|
||||
float getCount(int i) { result = getRanked(this.getArray("counts"), i) }
|
||||
|
||||
Array getDuplicationPercentage() { result = this.getArray("duplicationPercentages") }
|
||||
|
||||
float getDuplicationPercentage(int i) {
|
||||
result = getRanked(this.getArray("duplicationPercentages"), i)
|
||||
}
|
||||
@@ -327,6 +333,12 @@ module KindPredicatesLog {
|
||||
string getPosition() { result = this.getString("position") }
|
||||
|
||||
Predicate getPredicate() { result = getPredicateFromPosition(this.getPosition()) }
|
||||
|
||||
/**
|
||||
* Gets the RA for this event. Unlike recursive predicates, a COMPUTE_SIMPLE
|
||||
* event only has one pipeline ordering (and it's named "pipeline").
|
||||
*/
|
||||
Array getRA() { result = this.getObject("ra").getArray("pipeline") }
|
||||
}
|
||||
|
||||
/** Gets the `index`'th event that's evaluated by `recursive`. */
|
||||
|
||||
@@ -16,7 +16,7 @@ import KindPredicatesLog
|
||||
float getBadness(ComputeSimple simple) {
|
||||
exists(float maxTupleCount, float resultSize, float largestDependency, float denom |
|
||||
resultSize = simple.getResultSize() and
|
||||
maxTupleCount = max(simple.getPipelineRun().getCount(_)) and
|
||||
extractInformation(simple, maxTupleCount, _, _, _) 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).
|
||||
@@ -24,6 +24,29 @@ float getBadness(ComputeSimple simple) {
|
||||
)
|
||||
}
|
||||
|
||||
from ComputeSimple evt, float f
|
||||
where f = getBadness(evt) and f > 1.5
|
||||
select evt, f order by f desc
|
||||
pragma[nomagic]
|
||||
predicate hasPipelineRun(ComputeSimple simple, PipeLineRun run) { run = simple.getPipelineRun() }
|
||||
|
||||
predicate extractInformation(
|
||||
ComputeSimple simple, float maxTupleCount, Array tuples, Array duplicationPercentages, Array ra
|
||||
) {
|
||||
exists(PipeLineRun run |
|
||||
hasPipelineRun(simple, run) and
|
||||
maxTupleCount = max(run.getCount(_)) and
|
||||
tuples = run.getCounts() and
|
||||
duplicationPercentages = run.getDuplicationPercentage() and
|
||||
ra = simple.getRA()
|
||||
)
|
||||
}
|
||||
|
||||
from
|
||||
ComputeSimple evt, float badness, float maxTupleCount, Array tuples, Array duplicationPercentages,
|
||||
Array ra, int index
|
||||
where
|
||||
badness = getBadness(evt) and
|
||||
badness > 1.5 and
|
||||
extractInformation(evt, maxTupleCount, tuples, duplicationPercentages, ra)
|
||||
select evt.getPredicateName() as predicate_name, badness, index,
|
||||
tuples.getFloat(index) as tuple_count,
|
||||
duplicationPercentages.getFloat(index) as duplication_percentage, ra.getString(index) order by
|
||||
badness desc
|
||||
|
||||
Reference in New Issue
Block a user