Skip to content

Commit 38caad0

Browse files
author
Dave Bartolomeo
authored
Merge pull request #1604 from github/dbartol/join-order-threshold
Make bad join order warning threshold configurable
2 parents 7c1a8b3 + 131e72b commit 38caad0

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

extensions/ql-vscode/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@
290290
"pattern": "^$|^(?:[a-zA-Z0-9]+-)*[a-zA-Z0-9]+/[a-zA-Z0-9-_]+$",
291291
"patternErrorMessage": "Please enter a valid GitHub repository",
292292
"markdownDescription": "[For internal use only] The name of the GitHub repository in which the GitHub Actions workflow is run when using the \"Run Variant Analysis\" command. The repository should be of the form `<owner>/<repo>`)."
293+
},
294+
"codeQL.logInsights.joinOrderWarningThreshold": {
295+
"type": "number",
296+
"default": 50,
297+
"scope": "window",
298+
"minimum": 0,
299+
"description": "Report a warning for any join order whose metric exceeds this value."
293300
}
294301
}
295302
},

extensions/ql-vscode/src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const ROOT_SETTING = new Setting('codeQL');
5959
const TELEMETRY_SETTING = new Setting('telemetry', ROOT_SETTING);
6060
const AST_VIEWER_SETTING = new Setting('astViewer', ROOT_SETTING);
6161
const GLOBAL_TELEMETRY_SETTING = new Setting('telemetry');
62+
const LOG_INSIGHTS_SETTING = new Setting('logInsights', ROOT_SETTING);
6263

6364
export const LOG_TELEMETRY = new Setting('logTelemetry', TELEMETRY_SETTING);
6465
export const ENABLE_TELEMETRY = new Setting('enableTelemetry', TELEMETRY_SETTING);
@@ -342,6 +343,11 @@ export function allowCanaryQueryServer() {
342343
return !!CANARY_QUERY_SERVER.getValue<boolean>();
343344
}
344345

346+
export const JOIN_ORDER_WARNING_THRESHOLD = new Setting('joinOrderWarningThreshold', LOG_INSIGHTS_SETTING);
347+
348+
export function joinOrderWarningThreshold(): number {
349+
return JOIN_ORDER_WARNING_THRESHOLD.getValue<number>();
350+
}
345351

346352
/**
347353
* Avoids caching in the AST viewer if the user is also a canary user.

extensions/ql-vscode/src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
CliConfigListener,
3434
DistributionConfigListener,
3535
isCanary,
36+
joinOrderWarningThreshold,
3637
MAX_QUERIES,
3738
QueryHistoryConfigListener,
3839
QueryServerConfigListener
@@ -518,7 +519,7 @@ async function activateWithInstalledDistribution(
518519
void logger.log('Initializing evaluation log scanners.');
519520
const logScannerService = new LogScannerService(qhm);
520521
ctx.subscriptions.push(logScannerService);
521-
ctx.subscriptions.push(logScannerService.scanners.registerLogScannerProvider(new JoinOrderScannerProvider()));
522+
ctx.subscriptions.push(logScannerService.scanners.registerLogScannerProvider(new JoinOrderScannerProvider(() => joinOrderWarningThreshold())));
522523

523524
void logger.log('Reading query history');
524525
await qhm.readQueryHistory();

extensions/ql-vscode/src/log-insights/join-order.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import * as I from 'immutable';
22
import { EvaluationLogProblemReporter, EvaluationLogScanner, EvaluationLogScannerProvider } from './log-scanner';
33
import { InLayer, ComputeRecursive, SummaryEvent, PipelineRun, ComputeSimple } from './log-summary';
44

5-
const DEFAULT_WARNING_THRESHOLD = 50;
6-
75
/**
86
* Like `max`, but returns 0 if no meaningful maximum can be computed.
97
*/
@@ -454,7 +452,11 @@ class JoinOrderScanner implements EvaluationLogScanner {
454452
}
455453

456454
export class JoinOrderScannerProvider implements EvaluationLogScannerProvider {
455+
constructor(private readonly getThreshdold: () => number) {
456+
}
457+
457458
public createScanner(problemReporter: EvaluationLogProblemReporter): EvaluationLogScanner {
458-
return new JoinOrderScanner(problemReporter, DEFAULT_WARNING_THRESHOLD);
459+
const threshold = this.getThreshdold();
460+
return new JoinOrderScanner(problemReporter, threshold);
459461
}
460462
}

extensions/ql-vscode/test/pure-tests/log-scanner.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TestProblemReporter implements EvaluationLogProblemReporter {
3131
describe('log scanners', function() {
3232
it('should detect bad join orders', async function() {
3333
const scanners = new EvaluationLogScannerSet();
34-
scanners.registerLogScannerProvider(new JoinOrderScannerProvider());
34+
scanners.registerLogScannerProvider(new JoinOrderScannerProvider(() => 50));
3535
const summaryPath = path.join(__dirname, 'evaluator-log-summaries/bad-join-order.jsonl');
3636
const problemReporter = new TestProblemReporter();
3737
await scanners.scanLog(summaryPath, problemReporter);

0 commit comments

Comments
 (0)