-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: support placeholder argument for AS OF SYSTEM TIME #30955
Comments
For additional context:
if we considered that last avenue, we'd then hit another followup snag. The handling of placeholders inside a scalar expression is done as part of the general type checking logic. This also requires a valid current txn object. So in order to move forward here, we'd need to:
|
I may be misunderstanding. The code we have today for dealing with The below cockroach/pkg/sql/sem/tree/as_of.go Lines 56 to 59 in eaedf38
|
I think the lift here isn't too crazy. Firstly, we have a I'm not saying this is a trivial change by any stretch, but I'm not sure how many new concepts we really need. |
+1 to this -- this is the main thing that's preventing our use of prepared statements |
Another note if we implement this: Right now, since the argument is a constant expression, we use that constant as the timestamp to use when preparing the statement. A suggestion was made above that we could instead prepare the statement as of "now." However, that doesn't work well with the pgwire extended protocol, which says that a sequence of |
Here's a use case I was hoping to use prepared statements and Server APIThe API serves a simple paged search. Requests pass in a timestamp ($2), and responses return one as well. The idea is to use SELECT id
FROM data_table
AS OF SYSTEM TIME $2
ORDER BY id
LIMIT 10 OFFSET $3 ClientThe client passes the timestamp in all search requests (updating the timestamp as the server's responses do). |
Plus one. Time travel queries with bound parameters are absolutely necessary. On the client side the postgres driver cannot use prepared statements and spends a lot of time in parsing the query every single time as a result. |
Dropping in to comment my support for this |
We don't support placeholders for
AS OF SYSTEM TIME
:This means that the time value has to be embedded in the SQL string. Given that the time changes a lot, this does not play nicely with prepared statement reuse by drivers (and in the future, with caching plans). Ideally, we should support a placeholder here.
Semantically this is a bit dubious, given that the table schemas (and even existence) can vary with time. We would require that the statement parses correctly with the state of the world at prepare time (in other words, we prepare "as of now").
If we fix this, backporting to 2.1 would be a good idea, to avoid proliferation of the undesirable usage.
Note: @mjibson points out that in some cases, a relative time can be used as a workaround, eg
AS OF SYSTEM TIME '-1m'
.CC @knz
Jira issue: CRDB-4816
The text was updated successfully, but these errors were encountered: