Help › Work in notebooks

Work in notebooks

Keep queries, their results and charts, your notes and Python together in a notebook, run its cells on one connection, and save it as a Jupyter notebook file.

Querlyn 0.1.0 is not released yet. This help describes it ahead of release.

A notebook keeps queries, what they returned, and your notes together in one file: an October report with its numbers and charts, a runbook whose steps run in order, an investigation you can hand to a colleague. Querlyn saves notebooks as Jupyter notebook files (.ipynb), so other notebook programs open them too, and opens the notebooks they make; see Open notebooks from others.

A notebook is a list of cells:

  • Query cells hold statements in the connection's language: SQL, or the shell syntax on MongoDB and CQL on Cassandra. Each has the full editor (completion, diagnostics, formatting, find) and shows its results under it.
  • Text cells hold notes in Markdown: headings, lists, links, tables, code and pictures. They show as text; double-click one to change it.
  • Python cells run in a Jupyter kernel on this computer and take query results as pandas DataFrames: see Run Python in a notebook.

Make a notebook

  • Help › Open the Welcome Notebook (Help › Open the Welcome Notebook, also on the welcome page) opens a notebook that shows what notebooks do, on a small sample database: Northwind Outfitters, an invented shop for outdoor gear, with customers, products and a year of orders. The first time, Querlyn makes the database in its data folder and a connection to it named Northwind Outfitters (sample); you can delete both, and they are made again when you open the Welcome notebook. It also opens the first time Querlyn starts on a computer without connections.
  • File › New Notebook (File › New Notebook, also on the welcome page and when no tab is open) opens a notebook with one empty query cell, on the connection selected in the sidebar.
  • File › Save as Notebook (File › Save as Notebook) turns a query tab into a notebook: its text becomes a query cell, with the tab's last result, under a text cell that says where and when it ran.
  • Notebook › Open Runbook… (Notebook › Open Runbook…, also in a connection's context menu) opens one of Querlyn's troubleshooting notebooks on the connection you choose: slow queries, locks, sizes, replication lag and connections, in queries that only read. See Troubleshoot a server with a runbook.
  • Open a notebook file with Open File…, by dropping it on the window, or with File › Open Recent Notebook… (File › Open Recent Notebook…), which lists the notebooks you opened or saved lately in Quick Open.

Add and arrange cells

The notebook's toolbar adds a Query, Text or Python cell under the selected one, and so do Query, Text and Python under the last cell. Its Pivot, Chart, Filter, Sheet menu adds a pivot table, chart or filter of a result above, chosen from menus without writing SQL (see Pivot, chart and filter a result without SQL), or a range of a Google Sheet as a result (see Read a Google Sheet into a notebook). In a narrow window, or beside a Python kernel's name unless the window is wide, the toolbar has one Add menu instead, with every kind of cell. The selected cell has its own buttons, at its top right: run it, explain it, move it, change its type, hide or clear its results, and delete it. Right-click a cell for the same commands and those of its connection and result. Each is a command, in the Notebook menu and the command palette too:

  • Notebook › Add Query Cell Above and Notebook › Add Query Cell Below; Notebook › Add Text Cell Below; Notebook › Add Python Cell Below.
  • Notebook › Change Cell to Text, Notebook › Change Cell to Query and Notebook › Change Cell to Python. The cell keeps its text and loses its results.
  • Notebook › Move Cell Up and Notebook › Move Cell Down. To move a cell further, drag it by the grip in the margin beside its number (shown on the selected cell and on the cell under the pointer): a line shows where it will land.
  • Notebook › Delete Cell. Deleted cells can be brought back, the last first, with Notebook › Undo Delete Cell.
  • Notebook › Collapse or Expand Output and Notebook › Collapse or Expand Cell Text fold a cell's results or its text away. A folded part says so; click it to open it again.
  • Notebook › Clear Cell Results and Notebook › Clear All Results remove results, so the file does not keep them.

The keyboard does all of this too, as in Jupyter: see Use the keyboard in notebooks.

Run cells

  • Notebook › Run Cell (⌘↩ on macOS or Ctrl+Enter on Windows and Linux) runs every statement of the selected cell.
  • Notebook › Run Cell and Select Below (⇧↩ on macOS or Shift+Enter on Windows and Linux) runs it and moves to the next cell, adding a query cell at the end.
  • Notebook › Run Cell and Insert Below (⌥↩ on macOS or Alt+Enter on Windows and Linux) runs it and adds a query cell under it.
  • Notebook › Run All Cells (Run All in the toolbar) runs every query and Python cell from the top; Notebook › Run Cells Above runs those above the selected cell, and Notebook › Run Selected Cell and Below the selected cell and those under it.

The cells of one run go to the server one after another, in order, and the run stops at the first statement that fails: that cell is selected with its error, and the cells after it say they did not run. A cell that says what it needs of its server (a runbook's cells do) is skipped, with why, when the server lacks it; the others run. Cancel stops the run. Running a text cell shows its Markdown.

A notebook's cells run on one session of its connection, as a query tab's statements do: a temporary table, a setting or a transaction one cell makes is there for the next. The toolbar shows the session's transaction with Commit and Roll Back, as in a query tab. Closing the notebook closes its session. Cells on connections of their own have one session for each connection.

Each cell that ran shows a number in the margin, in the order the cells ran, and above its text when it ran, on which connection and how long it took.

A query cell's markers (:region) take their values from the notebook's parameters, set once at its top: see Give a notebook parameters.

When you change a cell, the results that depend on it are marked out of date. Notebook › Run Cell and Dependents (⇧⌘↩ on macOS or Ctrl+Shift+Enter on Windows and Linux) runs a cell and what depends on it, and Notebook › Run Out-of-Date Cells every out-of-date result, without querying again the results that did not change: see Keep a notebook's results up to date.

Results in cells

A query cell shows what its statements returned under its text: each result in a grid, its messages, its error, or a chart. Select the cell to work with its result as in any tab: sort, filter, copy, export, look at values, chart it, or profile its columns. Results in a notebook are read-only; to edit rows, run the query in a query tab.

A query cell's grid loads rows as you scroll, as a tab's does. The cells of a notebook share one memory budget, the one a query tab's results have: when their rows together pass it, the cells farthest from the one you are on let go of their rows first, down to the rows the file saves (see How much a notebook saves). Such a cell says so; run it again to see every row. When you run cells again while a cell still has rows to read, it keeps the rows it read and reads no more.

Explain a cell

With a query cell selected, Query › Explain shows the plan of the statement at the cursor in the cell, and so does Explain Analyze where the engine has it; see Explain a query. To see what an index changed, explain the statement in one cell, change it, explain it again, and choose Query › Compare Plans…: a cell's plans are compared with each other, or with the same statement's plan in another cell or tab; see Compare two plans.

Run cells on Production

The same safety applies to a notebook as to a query tab, for every statement of every cell in a run. On a Production connection, Run All checks the statements of all its cells before anything runs and asks once for the whole run: the question names each cell and statement that needs it ("Cell 3, statement 1: DELETE without WHERE on cart_items"). Nothing runs until you answer; Cancel runs none of the cells. A read-only connection refuses a run that would write, naming the cells, before anything runs.

Masked columns are masked in a notebook's cells as everywhere, and are never written to its file.

Choose the connection

The connection menu in the notebook's toolbar chooses the connection its cells run on, and the database menu beside it the database. The notebook file keeps the connection's name, engine, host and database (never a password), so that when it is opened again on this computer it runs on the same connection. Changing the connection starts a new session; while the session has an open transaction, commit or roll it back first.

A query cell can also run on a connection of its own, and a scratch cell joins the results of cells on different connections: see Run notebook cells on several connections.

Save a notebook

File › Save (⌘S on macOS or Ctrl+S on Windows and Linux) writes the notebook to its file; the first time, and with Save As…, you choose where. A notebook with unsaved changes has a dot on its tab, and closing it or quitting asks first.

The file keeps every cell's text, and the results of the cells as they were when you saved, so the notebook reads the same in another program or on another computer. Values are saved exactly, so a decimal or a timestamp reads back as it was, and a chart is saved as a picture too.

Masked columns are never saved: their values are left out of the file and the column is marked masked, so the notebook shows them masked when it is opened again, wherever it is opened.

If the file changed on disk since you opened it, saving asks whether to replace it or open what is there.

Notebooks that are open in tabs when Querlyn quits open again in their tabs when it starts, as their files are then; nothing runs and nothing connects. A notebook that was never saved is not opened again.

To share what a notebook found with someone who does not use Querlyn, export it as a report. To have your computer run a saved notebook at set times and write its report, schedule it.

A query cell that ran more than once says what changed since its last run. To read a notebook as a page of text, charts and tables without its code, show it as a dashboard.

How much a notebook saves

To keep the file small, results are saved within a bound: unless you change it, the first 1,000 rows of each result, at most 1 MB each and 16 MB in all. Whole rows are cut, and a cell whose result was cut says what the file keeps; so does the file, for other programs.

The bound is the notebook's own, and the file states it, so a notebook keeps its bound on every computer. The button at the left of the line under the cells shows it; it opens Notebook › Notebook Settings… (Notebook › Notebook Settings…), where you change the rows and megabytes of each result and the megabytes of all of them (up to 100,000 rows, 16 MB and 48 MB). Use Defaults fills in the bound new notebooks get, which is set by [notebooks] in the settings file. The new bound applies from the next save.

Help for Querlyn 0.1.0. All help topics