From 52e4058903d96d9abe3ef346e0991ea3ef946102 Mon Sep 17 00:00:00 2001 From: Jonas Jensen Date: Sat, 24 Aug 2019 15:31:43 +0200 Subject: [PATCH] C++: Fix lambda_capture upgrade query join order When this query was run as an upgrade script, the optimizer picked a bad join order, making the upgrade very slow on large databases. It picked a bad join order because upgrade scripts are run with no stats. --- .../lambda_capture.ql | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cpp/upgrades/814fae599505510ff15102f4c72600586734770a/lambda_capture.ql b/cpp/upgrades/814fae599505510ff15102f4c72600586734770a/lambda_capture.ql index 58026d45ada5..dec7d1f7fe51 100644 --- a/cpp/upgrades/814fae599505510ff15102f4c72600586734770a/lambda_capture.ql +++ b/cpp/upgrades/814fae599505510ff15102f4c72600586734770a/lambda_capture.ql @@ -5,11 +5,22 @@ class Field extends @membervariable { string toString() { none() } } class Location extends @location_default { string toString() { none() } } class Type extends @usertype { string toString() { none() } } +pragma[noopt] +predicate lambda_capture_new(LambdaCapture lc, Lambda l, int i, Field f, + boolean captured_by_reference, boolean is_implicit, + Location loc) +{ + exists(Type t | + lambda_capture(lc, l, i, captured_by_reference, is_implicit, loc) and + expr_types(l, t, _) and + t instanceof Type and + member(t, i, f) and + f instanceof Field + ) +} + from LambdaCapture lc, Lambda l, int i, Field f, boolean captured_by_reference, boolean is_implicit, - Location loc, Type t -where lambda_capture(lc, l, i, captured_by_reference, is_implicit, loc) - and expr_types(l, t, _) - and member(t, i, f) + Location loc +where lambda_capture_new(lc, l, i, f, captured_by_reference, is_implicit, loc) select lc, l, i, f, captured_by_reference, is_implicit, loc -