Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/language/learn-ql/advanced/advanced-ql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ Advanced QL

Topics on advanced uses of QL. These topics assume that you are familiar with QL and the basics of query writing.

- :doc:`Choosing appropriate ways to constrain types <constraining-types>`
- :doc:`Determining the most specific types of a variable <determining-specific-types-variables>`
- :doc:`Monotonic aggregates in QL <monotonic-aggregates>`
73 changes: 0 additions & 73 deletions docs/language/learn-ql/advanced/constraining-types.rst

This file was deleted.

This file was deleted.

22 changes: 22 additions & 0 deletions docs/language/learn-ql/writing-queries/debugging-queries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ is preferred over::

From the type context, the query optimizer deduces that some parts of the program are redundant and removes them, or *specializes* them.

Determine the most specific types of a variable
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you are unfamiliar with the library used in a query, you can use CodeQL to determine what types an entity has. There is a predicate called ``getAQlClass()``, which returns the most specific QL types of the entity that it is called on.

For example, if you were working with a Java database, you might use ``getAQlClass()`` on every ``Expr`` in a callable called ``c``:

.. code-block:: ql

import java

from Expr e, Callable c
where
c.getDeclaringType().hasQualifiedName("my.namespace.name", "MyClass")
and c.getName() = "c"
and e.getEnclosingCallable() = c
select e, e.getAQlClass()

The result of this query is a list of the most specific types of every ``Expr`` in that function. You will see multiple results for expressions that are represented by more than one type, so it will likely return a very large table of results.

Use ``getAQlClass()`` as a debugging tool, but don't include it in the final version of your query, as it slows down performance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this would be more visible as a note/warning?


Avoid complex recursion
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down