You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Going from ``Element -> File`` and ``Element -> Location -> StartLine`` is linear--that is, there is only one ``File``, ``Location``, etc. for each ``Element``.
106
106
107
-
However, as written it is difficult for the optimizer to pick out the best ordering. Generally, we want to do the quick, linear parts first, and then join on the resultant larger tables. Joining first and then doing the linear lookups later would likely result in poor performance. We can initiate this kind of ordering by splitting the above predicate as follows:
107
+
However, as written it is difficult for the optimizer to pick out the best ordering. Joining first and then doing the linear lookups later would likely result in poor performance. Generally, we want to do the quick, linear parts first, and then join on the resultant larger tables. We can initiate this kind of ordering by splitting the above predicate as follows:
108
108
109
109
.. code-block:: ql
110
110
111
111
predicate locInfo(Element e, string name, File f, int startLine) {
112
-
name = e.getName() and
113
-
f = e.getFile() and
114
-
startLine = e.getLocation().getStartLine()
112
+
name = e.getName() and
113
+
f = e.getFile() and
114
+
startLine = e.getLocation().getStartLine()
115
115
}
116
-
116
+
117
117
predicate sameLoc(Element e1, Element e2) {
118
-
exists(string name, File f, int startLine |
119
-
locInfo(e1, name, f, startLine) and
120
-
locInfo(e2, name, f, startLine)
121
-
)
118
+
exists(string name, File f, int startLine |
119
+
locInfo(e1, name, f, startLine) and
120
+
locInfo(e2, name, f, startLine)
121
+
)
122
122
}
123
123
124
124
Now the structure we want is clearer. We've separated out the easy part into its own predicate ``locInfo``, and the main predicate ``sameLoc`` is just a larger join.
0 commit comments