Skip to content

Explore Best Practices

Habits that keep Explore queries fast, readable, and safe with sensitive data, so a workspace you come back to next week still answers the question it was written for.

Before you start

The two ways a query can run are covered in SQL Modes. How results load, expire, and are masked is covered in Results.

Writing Queries

Put the order in the SQL

Rows come back in the order the source produces them, which can differ from one run to the next. Clicking a column header sorts only the rows loaded so far, not the whole result. When the order matters, write ORDER BY in the query, so the first page is the one you want and every later page follows it.

Select columns by name

Name the columns you need instead of SELECT *. The result is smaller and loads faster, and each column that shows a field as it is keeps its link to the field, with its active anomaly count in the header. When a query reads a table with masked fields, the checks ask for this: a * that excludes, renames, or replaces columns cannot run, and you are asked to select the columns by name.

Name every expression with AS

Give each computed column its own name with AS. Over a table with masked fields, an expression without a name, or two columns with the same name, is refused before the query runs. Named columns also make better chart titles and CSV headers.

Keep scratch queries in one workspace

With nothing selected, Run sends the statement under the cursor, and a bar beside the line numbers marks which one. Several queries separated by ; can live in one workspace, and you run the one you are on. Select part of a statement to run only that part.

Narrow the query while you draft it

When you are still shaping a query on a large table, add a WHERE clause or a LIMIT so each try returns quickly. Remove it for the final run. Results load as you scroll, so a limit is not needed to keep the grid responsive.


Choosing the SQL Mode

Start in the datastore's own SQL

A query in the datastore's own SQL runs on the datastore and can read the other datastores that share its connection, by prefix. Qualytics mode reads each container whole before the query runs, so for plain tables on a database, the datastore's own SQL is usually the faster choice. Save as computed table also needs this mode.

Switch to Qualytics mode for computed assets and files

Computed tables, computed files, and computed fields exist only in Qualytics, so a query that reads them runs in Qualytics mode, with Spark SQL. When the editor finds one in your SQL, it offers Run in Qualytics. File datastores always run in this mode, and a query there that reads one file container can be kept as a computed file with Save as computed file. Keep each query to the containers it needs: Spark SQL reads at most 10 at a time.

Write column names as the container spells them

In Qualytics mode, container names are matched in any letter case, but Spark SQL matches column names by case. Copy column names from Assets or autocomplete rather than typing them in another case.

Join the base tables instead of a computed join

Neither mode reads a computed join. Read the tables it is built from and write the join in your SQL.


Workspaces

Name workspaces for the question they answer

A new workspace is called Untitled, and the list soon fills with Untitled 2, Untitled 3. Rename a workspace as soon as it answers something, with the question in the name ("Open orders by region", "Duplicate customer emails"). The list is grouped by last edit, and the hover card shows the datastore, the last run, and the SQL, but a clear name is what you scan for.

Duplicate before you rework a query that works

Duplicate makes a copy named Copy of <name> with the same datastore, SQL, and mode. Rework the copy, and the original keeps the version you trusted.

Treat workspaces as personal

Workspaces are private to the person who created them; no one else can open them, Admins included. To hand a query to someone, copy the SQL from the editor or from the workspace's History tab and share it.


Results

Keep a few results open at a time

Each person keeps up to three open results. Opening a fourth closes the one read least recently, and a result nobody reads for 30 minutes expires. Running again in a workspace replaces that workspace's previous result. Work in a small number of workspaces at once, and download or copy what you need from a result before you move on to many others.

Aggregate before you chart

A chart draws only the rows loaded so far. Group and aggregate in SQL so the result holds one row per category, and the chart reflects the whole answer rather than the first page. More than 20 bars fold the rest into Other.

Pick the right download for large results

Download offers the rows loaded so far, right away, or the whole result, read from the stored result up to 1,000,000 rows. For more than that, filter or aggregate in SQL first. A result also stops at a size limit set for your deployment and says it stopped at the size limit; narrow the query rather than trying to read past it. Downloads can be turned off for a deployment, in which case the button is not shown.

Filter on the container tab instead of scrolling

On a container's Explore tab, a WHERE filter returns the rows you are looking for in the first page. For some containers the tab shows only the first 100 rows, so scrolling there cannot reach the rest.


Masked Data

Leave masked columns out unless you need them

A masked field can be used to filter, join, or count without showing its values. Select it only when you need to read it. Columns computed from a masked field come back as ***MASKED*** too, not only the field itself.

Write plain SQL over masked tables

Over a table with masked fields, keep each result column traceable to the field it shows: name columns instead of reading them by position or through a variable, give expressions a name with AS, and keep masked fields out of functions that turn values into rows. Shapes the check cannot trace are refused rather than run. Masking is a safeguard, not a guarantee, so also limit what the datastore's connection can read in the database itself. See SQL Modes.

Reveal only when the task needs it

Show masked values runs the query again with the values shown, and every reveal is recorded in the masking audit log. Reveal for the task at hand, then use Re-mask values . A CSV download made while values are revealed contains them, so re-mask before you download a file you plan to share.

Read errors without the masked tables

When a query over a table with masked fields fails, the database's message is hidden, because it could quote masked values. Check the SQL, or run the failing part without the masked tables to see the full message.


See Also