Skip to content

Commit 537739c

Browse files
author
james
committed
docs: address review comments
1 parent 23d1e06 commit 537739c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

docs/language/learn-ql/writing-queries/debugging-queries.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,28 @@ In the following example, we explore some lookups on two ``Element``\ s:
9797
.. code-block:: ql
9898
9999
predicate similar(Element e1, Element e2) {
100-
e1.getName() = e2.getName() and
101-
e1.getFile() = e2.getFile() and
102-
e1.getLocation().getStartLine() = e2.getLocation().getStartLine()
100+
e1.getName() = e2.getName() and
101+
e1.getFile() = e2.getFile() and
102+
e1.getLocation().getStartLine() = e2.getLocation().getStartLine()
103103
}
104104
105105
Going from ``Element -> File`` and ``Element -> Location -> StartLine`` is linear--that is, there is only one ``File``, ``Location``, etc. for each ``Element``.
106106

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:
108108

109109
.. code-block:: ql
110110
111111
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()
115115
}
116-
116+
117117
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+
)
122122
}
123123
124124
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

Comments
 (0)