Skip to main content

Advanced query options

Learn how to use advanced query options.

The following options are available in the query editor's Advanced tab. Many query options can help you improve your app's performance. Read about best practices to learn how to optimize queries.

Require confirmation before running

If you don't want a query to run automatically (whether because parameters change or because you triggered it), you can require confirmation before running. Before the query runs, a modal is displayed (the message can be dynamic), asking whether you want to run the query.

Run queries periodically

Retool also provides the mechanism to periodically run a query in a user specified period.

Example of a query refreshing every 5 seconds (5000 milliseconds)

Disable queries dynamically

In more complex apps with many queries, you can prevent queries from running if they are not immediately needed. For example, if you are using a tabbed container, you might only want a query to run when the user switches the active tab to the second tab. To do this, you could write something like the following.

Only run a query when the second tab is active.

{{ tabbedContainer1.currentViewKey != "View 2" }} disables the query when "View 2" in the Tabbed Container is not selected.

Hide parameters from audit logs

Queries and their parameters are logged in the audit logs when they're run. You should hide sensitive parameters, such as API keys, from your audit logs. Add sensitive parameters to the Disable logging for field on the Advanced tab in the query editor. In the audit logs, these parameter values display as --blacklisted-by-developer--.

Disable tagging for query parameter

Query throttling

If app performance is slow, it might be because your queries are refreshing too frequently (e.g., on every keystroke). To solve this, you can throttle queries so they runs less frequently. The default is 750ms.

Watch inputs

If the query uses a dynamic input--for example, using a Text Input component to supply an ID parameter--and is triggered manually, you can set the query to watch and update in reaction to these inputs. In the Advanced tab under Advanced options, add inputs to watch to the Watched inputs dropdown.

In the example below, the query watches the selected row in the table. When a different row is selected, it triggers the query.

Timing options

You can control when queries run using options in the Timing section of the Advanced tab in the query editor.

Query timeout

Retool automatically times out queries that run for longer than 10 seconds (10000ms). You can adjust the Timeout after duration for queries on an individual basis in the Advanced tab of the query editor. For Retool-hosted users, the maximum duration before a query times out is 120 seconds (120000ms). Self-hosted users can set the DBCONNECTOR_QUERY_TIMEOUT_MS environment variable to change the maximum timeout value.

Delay between query runs

To update the amount of time to wait between query runs, in the Advanced tab, update the Delay between runs field. This field specifies the number of milliseconds to wait in between runs of the same query and defaults to 750 milliseconds.

Delay page load

If the query runs on page load, you can set a delay by updating the Page load delay (ms) field in the Advanced tab.

Keep variable references in sync


This setting may introduce performance issues and may not work well with transformers, so use it with caution.

If your query calls a component's setValue method, you can ensure future references to the component use the updated value by toggling on the Keep variable references inside the query with your app setting. This can be useful if you need to set and use a value in the same query.