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
Copy file name to clipboardExpand all lines: docs/language/learn-ql/writing-queries/debugging-queries.rst
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ This topic offers some simple tips on how to avoid common problems that can affe
5
5
Before reading the tips below, it is worth reiterating a few important points about CodeQL and the QL language:
6
6
7
7
- CodeQL `predicates <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ and `classes <https://help.semmle.com/QL/ql-handbook/types.html#classes>`__ are evaluated to database `tables <https://en.wikipedia.org/wiki/Table_(database)>`__. Large predicates generate large tables with many rows, and are therefore expensive to compute.
8
-
- The QL language is implemented using standard database operations and `relational algebra <https://en.wikipedia.org/wiki/Relational_algebra>`__ (such as join, projection, union, etc.). For further information about query languages and databases, see :doc:`About QL <../about-ql>`.
9
-
- Queries are evaluated *bottom-up*, which means that a predicate is not evaluated until **all** of the predicates that it depends on are evaluated. For more information on query evaluation, see `Evaluation of QL programs <https://help.semmle.com/QL/ql-handbook/evaluation.html>`__ in the QL handbook.
8
+
- The QL language is implemented using standard database operations and `relational algebra <https://en.wikipedia.org/wiki/Relational_algebra>`__ (such as join, projection, and union). For further information about query languages and databases, see :doc:`About QL <../about-ql>`.
9
+
- Queries are evaluated *bottom-up*, which means that a predicate is not evaluated until *all* of the predicates that it depends on are evaluated. For more information on query evaluation, see `Evaluation of QL programs <https://help.semmle.com/QL/ql-handbook/evaluation.html>`__ in the QL handbook.
10
10
11
11
Performance tips
12
12
----------------
13
13
14
-
Follow the guidelines below to ensure that you don't get get tripped up by the most common CodeQL performance pitfalls.
14
+
Follow the guidelines below to ensure that you don't get tripped up by the most common CodeQL performance pitfalls.
15
15
16
16
Eliminate cartesian products
17
17
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -20,7 +20,7 @@ The performance of a predicate can often be judged by considering roughly how ma
20
20
One way of creating badly performing predicates is by using two variables without relating them in any way, or only relating them using a negation.
21
21
This leads to computing the `Cartesian product <https://en.wikipedia.org/wiki/Cartesian_product>`__ between the sets of possible values for each variable, potentially generating a huge table of results.
22
22
23
-
This can occur whenever you inadvertently fail to specify restrictions on your variables.
23
+
This can occur if you don't specify restrictions on your variables.
24
24
25
25
For instance, consider the following predicate that checks whether a Java method ``m`` may access a field ``f``::
26
26
@@ -60,15 +60,15 @@ is preferred over::
60
60
61
61
predicate foo(Expr e)
62
62
63
-
From the type context, the query optimizer deduces that some parts of the program are redundant and removes them, or **specializes** them.
63
+
From the type context, the query optimizer deduces that some parts of the program are redundant and removes them, or *specializes* them.
64
64
65
65
Avoid complex recursion
66
66
~~~~~~~~~~~~~~~~~~~~~~~
67
67
68
68
`Recursion <https://help.semmle.com/QL/ql-handbook/recursion.html>`__ is about self-referencing definitions.
69
69
It can be extremely powerful as long as it is used appropriately.
70
70
On the whole, you should try to make recursive predicates as simple as possible.
71
-
That is, you should define a **base case** that allows the predicate to *bottom out*, along with a single **recursive call**::
71
+
That is, you should define a *base case* that allows the predicate to *bottom out*, along with a single *recursive call*::
72
72
73
73
int depth(Stmt s) {
74
74
exists(Callable c | c.getBody() = s | result = 0) // base case
0 commit comments