-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Allow AS OF SYSTEM TIME (AOST) to be passed to EXPLAIN #43294
Description
In version 19.2.1, if you stick EXPLAIN on the front of a query that includes AS OF SYSTEM TIME, it fails with the following error message:
pq: AS OF SYSTEM TIME must be provided on a top-level statement
I would like to be able to take a query that includes AS OF SYSTEM TIME and pass it to EXPLAIN without having to edit out the AOST portion.
More generally, this was surprising to me because my expectation of EXPLAIN is that I can pretty much just "slap an EXPLAIN on it" with any arbitrary SQL query.
In the SQL shell, this is the difference between:
- up arrow
- ctrl-a (beginning of line)
- type "EXPLAIN "
vs. doing a bunch of possibly painful inline edits, including maybe making a mistake so that the query that gets EXPLAINed does not exactly match your intended query, etc.
From client code, it could also be unpleasant depending on your environment, since you couldn't just prepend an EXPLAIN e.g.
$query = 'EXPLAIN ' . $query;In this case, I was trying to see if / how the EXPLAIN output would actually differ if AOST were used on a query. In the AOST docs we say re: performance that
This clause can be used to read historical data (also known as "time travel queries") and can also be advantageous for performance as it decreases transaction conflicts
but it's pretty vague. I wanted to run an EXPLAIN to see if there were other performance implications to the query plan that could be seen vs. running the same query without AOST.
It also makes documenting things more verbose in some cases (such as work I'm doing on this docs PR since the workflow is not (1) run query, (2) slap an EXPLAIN on the query, it's the whole inline-edit-and-don't-make-a-mistake thing mentioned above, which also requires mentioning this limitation inline in those (unrelated) docs, which adds cognitive weight to the user.
From a UX perspective, this limitation is a bit unfortunate if we are expecting people to write AOST queries on a regular basis to get good performance, which I think we are.
Related issues: I searched around and did find #30534 which may be the technical reason for this limitation but is not about this particular use case.
Exact version info:
SELECT VERSION();
version
+---------------------------------------------------------------------------------------+
CockroachDB CCL v19.2.1 (x86_64-apple-darwin14, built 2019/11/18 23:17:47, go1.12.12)
(1 row)