Help › Work in notebooks

Keep a notebook's results up to date

See which results of a notebook are out of date after an edit, a new parameter value or a cell run again, and run a cell with what depends on it, reusing results that did not change.

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

A notebook knows which of its cells depend on which. When you change a cell, the results that were made from it are marked out of date, so you never read last hour's answer as this minute's. Querlyn runs nothing by itself: you choose when to bring them up to date, and it runs only what needs to run.

What depends on what

Querlyn reads each query cell's text and works out what it reads and what it changes. A cell depends on another when:

  • it is a scratch cell that reads the other cell's result by its name;
  • the other cell changes, makes or drops a table this cell names, on the same server: a temporary table one cell makes and the next reads, rows one cell deletes and another counts. A temporary table counts only on its own session.
  • the other cell may change anything: a procedure call, a SET, a ROLLBACK, or a statement Querlyn cannot read. Every cell on its server depends on it.
  • this cell reads something that may hide what it reads (a view, a function of the database's own, or a table Querlyn does not know yet) and the other cell changes a table on the same server.

A cell also depends on the values of the parameters it uses, and on where it runs.

A Python cell depends on every cell above it, since its kernel holds what they made, and its result is out of date once the kernel restarts. A Python cell's result is never reused: Querlyn cannot know what its code does.

When Querlyn cannot tell, it counts a cell as depending: a result marked out of date that is not is a small cost; one shown as current that is not would mislead you. Dependencies go both ways in the notebook: a cell at the bottom that deletes rows makes the count at the top out of date once it runs.

Out-of-date results

A result is out of date when:

  • its own text changed since it ran;
  • it runs on another connection or database now, or a parameter it uses has another value;
  • a cell it depends on changed, ran again after it, or is out of date itself;
  • the transaction it was read in was rolled back.

An out-of-date cell has a hatched mark beside it in the margin and says why above its result ("Out of date: cell 2 changed"). Its result stays as it was, so you can still compare. Screen readers hear it with the cell.

The file keeps which results were out of date when you saved, and the text each result was made from, so the marks are right when the notebook is opened again.

Bring results up to date

  • Notebook › Run Cell and Dependents (⇧⌘↩ on macOS or Ctrl+Shift+Enter on Windows and Linux, also on the selected cell's toolbar, its right-click menu, and Run Cell and Dependents beside an out-of-date result) runs the selected cell and every cell that depends on it. Before them, it runs the cells they depend on that must run first: those out of date, those that never ran, and those that make a temporary table or a change that is not in this session.
  • Notebook › Run Out-of-Date Cells (Run Out of Date in the toolbar, shown with how many while there are some) does the same for every out-of-date result at once.

The cells run in the order their dependencies need, as one run. On a Production connection the run asks one question for every statement that needs it, before anything runs, as Run All does, and on BigQuery each query shows what it would read first. Nothing runs when you cancel.

Results that are not run again

A reactive run does not query a server again for a result that did not change: the cell says Saved result from 9 Oct 14:01, not run again (or Result from 14:01 for one from this session), and the cells after it use that result. So a warehouse that bills by the data a query reads is not billed twice for the same answer.

A result is reused only when all of this is true:

  • it is not out of date: same text, same connection and database, same parameter values, and nothing it depends on changed;
  • every statement of its cell only reads (proven by Querlyn's parser), and none reads the clock or a random source (now(), CURRENT_DATE, random(), TABLESAMPLE);
  • it was not read inside an open transaction;
  • it is whole: every row is there, not the first rows a file keeps;
  • it ran to its end without an error, and the file says what text made it (notebooks from other programs do not).

Run Anyway beside a reused result runs its cell, and what depends on it, now. Notebook › Run Cell and Notebook › Run All Cells always run every cell they name.

Help for Querlyn 0.1.0. All help topics