Skip to content

Commit 1f40518

Browse files
committed
QL: Fixup the join-order query.
1 parent a86a8ce commit 1f40518

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

ql/ql/src/queries/performance/LargeJoinOrder.ql

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ predicate hasDuplication(ComputeRecursive recursive, string ordering, int i, flo
8282
)
8383
}
8484

85-
// -----
8685
/**
87-
* Holds if the bucket `bucket` has `resultSize` resultSize in the `iteration`'th iteration.
86+
* Holds if the ordering `ordering` has `resultSize` resultSize in the `iteration`'th iteration.
8887
*
89-
* For example, the "base" bucket in iteration 0 has size 42.
88+
* For example, the "base" ordering in iteration 0 has size 42.
9089
*/
9190
private predicate hasResultSize(
9291
ComputeRecursive recursive, string ordering, SummaryEvent inLayer, int iteration, float resultSize
@@ -130,9 +129,9 @@ int getSize(ComputeRecursive recursive, string predicateName, int iteration, TDe
130129
kind = TCurrent() and
131130
i = iteration
132131
|
133-
result = getInLayerEventWithName(recursive, predicateName).getDeltaSize(iteration - 1)
132+
result = getInLayerEventWithName(recursive, predicateName).getDeltaSize(i)
134133
or
135-
not exists(getInLayerEventWithName(recursive, predicateName).getDeltaSize(iteration - 1)) and
134+
not exists(getInLayerEventWithName(recursive, predicateName).getDeltaSize(i)) and
136135
result = 0
137136
)
138137
}
@@ -155,35 +154,35 @@ private predicate isDelta(string predicateName, TDeltaKind kind, string withoutS
155154
withoutSuffix = predicateName.regexpCapture("(.+)#cur_delta", 1)
156155
}
157156

158-
predicate hasDependentPredicateSizeInBucket(
159-
ComputeRecursive recursive, string bucket, SummaryEvent inLayer, int iteration,
157+
predicate hasDependentPredicateSize(
158+
ComputeRecursive recursive, string ordering, SummaryEvent inLayer, int iteration,
160159
string predicateName, float size
161160
) {
162161
exists( |
163162
inLayer = firstPredicate(recursive) and
164-
bucket = inLayer.getPipelineRuns().getRun(iteration).getRAReference()
163+
ordering = inLayer.getPipelineRuns().getRun(iteration).getRAReference()
165164
|
166165
// We treat iteration 0 as a non-recursive case
167-
if bucket = "base"
166+
if ordering = "base"
168167
then size = getDependencyWithName(recursive.getDependencies(), predicateName).getResultSize()
169168
else
170169
exists(TDeltaKind kind |
171170
size = getSize(recursive, predicateName, iteration, kind) and
172-
isDelta(getAnRaOperation(inLayer, bucket).getARhsPredicate(), kind, predicateName)
171+
isDelta(getAnRaOperation(inLayer, ordering).getARhsPredicate(), kind, predicateName)
173172
)
174173
)
175174
or
176175
exists(SummaryEvent inLayer0, float size0 |
177176
successor(recursive, inLayer0, inLayer) and
178-
hasDependentPredicateSizeInBucket(recursive, bucket, inLayer0, iteration, predicateName, size0)
177+
hasDependentPredicateSize(recursive, ordering, inLayer0, iteration, predicateName, size0)
179178
|
180179
// We treat iteration 0 as a non-recursive case
181-
if bucket = "base"
180+
if ordering = "base"
182181
then size = getDependencyWithName(recursive.getDependencies(), predicateName).getResultSize()
183182
else
184183
exists(TDeltaKind kind |
185184
size = getSize(recursive, predicateName, iteration, kind) + size0 and
186-
isDelta(getAnRaOperation(inLayer, bucket).getARhsPredicate(), kind, predicateName)
185+
isDelta(getAnRaOperation(inLayer, ordering).getARhsPredicate(), kind, predicateName)
187186
)
188187
)
189188
}
@@ -192,13 +191,13 @@ SummaryEvent getInLayerOrRecursive(ComputeRecursive recursive) {
192191
result = recursive or result.(InLayer).getComputeRecursiveEvent() = recursive
193192
}
194193

195-
predicate hasDependentPredicateSizeInBucket(
196-
ComputeRecursive recursive, string bucket, string predicateName, float size
194+
predicate hasDependentPredicateSize(
195+
ComputeRecursive recursive, string ordering, string predicateName, float size
197196
) {
198197
size =
199198
strictsum(SummaryEvent inLayer, int iteration, int s |
200199
inLayer = getInLayerOrRecursive(recursive) and
201-
hasDependentPredicateSizeInBucket(recursive, bucket, inLayer, iteration, predicateName, s)
200+
hasDependentPredicateSize(recursive, ordering, inLayer, iteration, predicateName, s)
202201
|
203202
s
204203
)
@@ -216,12 +215,12 @@ predicate hasDependentPredicateSizeInBucket(
216215
* - For a non-"base" ordering, it's defined as any `#prev_delta` or `#cur_delta` predicates
217216
* that appear in the pipeline.
218217
*/
219-
float getRecursiveBadness(ComputeRecursive recursive, string bucket) {
218+
float getRecursiveBadness(ComputeRecursive recursive, string ordering) {
220219
exists(float maxTupleCount, float resultSize, float maxDependentPredicateSize |
221-
maxTupleCount = max(float tc | hasTupleCount(recursive, bucket, _, tc) | tc) and
222-
hasResultSize(recursive, bucket, resultSize) and
220+
maxTupleCount = max(float tc | hasTupleCount(recursive, ordering, _, tc) | tc) and
221+
hasResultSize(recursive, ordering, resultSize) and
223222
maxDependentPredicateSize =
224-
max(float size | hasDependentPredicateSizeInBucket(recursive, bucket, _, size) | size) and
223+
max(float size | hasDependentPredicateSize(recursive, ordering, _, size) | size) and
225224
resultSize.maximum(maxDependentPredicateSize) > 0 and
226225
result = maxTupleCount / resultSize.maximum(maxDependentPredicateSize)
227226
)
@@ -259,9 +258,9 @@ where
259258
badness = getNonRecursiveBadness(evt) and
260259
extractSimpleInformation(evt, predicateName, index, tupleCount, duplicationPercentage, operation)
261260
or
262-
exists(string bucket |
263-
badness = getRecursiveBadness(evt, bucket) and
264-
extractRecursiveInformation(evt, predicateName, bucket, index, tupleCount,
261+
exists(string ordering |
262+
badness = getRecursiveBadness(evt, ordering) and
263+
extractRecursiveInformation(evt, predicateName, ordering, index, tupleCount,
265264
duplicationPercentage, operation)
266265
)
267266
)

0 commit comments

Comments
 (0)