Querious Docs

The Query Editor

Running pieces of SQL, reformatting it, and moving around in it.

The query editor holds as much SQL as you like and treats it as a sequence of statements, so you can run one, run a selection, or run everything. This page covers editing and executing queries, see Selected Database / Search Path for how those affect the execution, and Query Results covers what comes back.

The query editor
The query editor

Query Editors #

The Query view can hold multiple query editors, each with its own SQL and results. You can also open SQL files into an editor to edit and run them.

Click on the menu to the right of the Queries section header in the sidebar to open a new editor.

Right-click on a query editor in the sidebar to manipulate it directly.

Multiple query editors

What the Run Button Does #

The Run button can either:

  • Run All Queries
  • Run Current Query
The query view run button options

You can choose what clicking the button does. In the button's menu under the section labelled "Run Button (Command-Return) Will:" are the choices:

Setting Runs
Always Run All Queries Ignores selection/location, and always runs all queries.
Always Run Current or Selected Queries If there is a selection, that exact selected text is run as queries. Otherwise, the "current" query determined by the cursor location, is run.
Run All Queries if there is No Selection If there is a selection, that exact selected text is run as queries. Otherwise, all queries are run.

Whichever behavior you choose becomes the behavior when clicking the button or pressing Command-Return. The opposite behavior is then mapped to Command-Shift-Return, so both behaviors are always available.

Query Markers: The left-side line number gutter beside the editor text view marks each statement. Right-click on a marker for Run Query and Explain Query on that statement alone. Right-clicking in the statement's text itself also offers the same commands.

Formatting #

The Query Formatting menu (right-click within the query text view) reformats the selected SQL, or the whole editor when nothing is selected.

Command Effect
Format Reformats into a readable layout, using the selected options below.
Minify Collapses to as few characters as possible, using the selected options below.
Options Effect
Reindent Reindents the SQL when enabled.
Indent Major Clauses Indents SELECT, FROM, WHERE, etc as blocks when enabled.
Strip Comments Removes comments when enabled.
Keywords → … Choose a case for SQL keywords.
Functions → … Choose a case for function names, independent of keywords.

Editing Commands #

Command What it does
Comment Comments or uncomments the selected lines.
Shift Left, Shift Right Changes the indentation of the selection.
Find…, Find Next, Find Previous, Find and Replace…, Use Selection for Find The standard find commands, in the Edit menu.
Go to Line… Jumps to a line number.
Jump to Selection Scrolls the selection into view.
Next Query, Previous Query Moves the insertion point between statements.

Editors and Files #

Each query editor is independent. Switch with ViewGo to Next Editor and Go to Previous Editor.

An editor can be backed by a file on disk. The execution bar's menu offers:

  • Open in New Editor — opens SQL into a new editor.
  • Save and Save as SQL File… — write the contents to a file. Once an editor has a file, Save updates it and Revert discards unsaved changes.
  • Save as Saved Query… — stores it in Saved Queries instead of on disk.
  • Close — closes the editor.

Explaining a Query #

Explain Query shows how the server would run the statement under the cursor, without executing it. Where supported, Querious uses EXPLAIN EXTENDED and follows it with SHOW WARNINGS, which shows how the server rewrote your query and is often more informative than the plan.

To check whether a query uses an index

  1. Put the insertion point in the statement and choose Explain Query from the right-click menu or the statement's marker.
  2. On MySQL, read the type and key columns for whether an index is used and which. rows estimates how many rows will be examined.
  3. If you see a full scan where you expected an index, check Index Usage and the table's Indexes and Keys.