Skip to content
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: AS OF SYSTEM TIME doesn't support dropped databases at timestamps prior to the drop time #51380

Closed
thoszhang opened this issue Jul 13, 2020 · 2 comments
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@thoszhang
Copy link
Contributor

thoszhang commented Jul 13, 2020

Currently, AS OF SYSTEM TIME can be used to read historical data in a dropped table prior to the drop time, provided that the database still exists. However, if the database containing the table was dropped, AOST no longer works because name resolution fails during planning:

root@:26257/defaultdb> create database test;
CREATE DATABASE

Time: 3.011ms

root@:26257/defaultdb> create table test.t();
CREATE TABLE

Time: 4.49ms

root@:26257/defaultdb> select * from current_timestamp();
         current_timestamp
------------------------------------
  2020-07-13 15:40:45.259421+00:00
(1 row)

Time: 401µs

root@:26257/defaultdb> drop database test cascade;
DROP DATABASE

Time: 26.796ms

root@:26257/defaultdb> select * from test.t as of system time '2020-07-13 15:40:45.259421+00:00';
ERROR: relation "test.t" does not exist
SQLSTATE: 42P01

As I understand it, we don't make any provisions for accessing older versions of database descriptors. The database cache is just a name to ID mapping that attempts to store the latest version, and we fall back to reading the database descriptor from KV otherwise. To support this functionality, we'll need database descriptor leasing.

Jira issue: CRDB-4058

@thoszhang thoszhang added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Jul 13, 2020
@thoszhang thoszhang added this to Triage in SQL Foundations via automation Jul 13, 2020
@thoszhang thoszhang moved this from Triage to Backlog in SQL Foundations Jul 14, 2020
@vy-ton vy-ton moved this from Backlog to Triage in SQL Foundations Oct 6, 2020
@ajwerner ajwerner self-assigned this Oct 6, 2020
@thoszhang thoszhang moved this from Triage to 20.2 stability period: known issues in SQL Foundations Oct 6, 2020
@ajwerner
Copy link
Contributor

ajwerner commented Oct 6, 2020

This limitation has been lifted in 20.2 with the generalized leasing mechanism for databases. It does not seem to work for schemas unfortunately. We'll track down what causes this for schemas.

ajwerner added a commit to ajwerner/cockroach that referenced this issue Oct 6, 2020
@thoszhang thoszhang moved this from 20.2 stability period: known issues to Backlog in SQL Foundations Oct 13, 2020
@jlinder jlinder added the T-sql-schema-deprecated Use T-sql-foundations instead label Jun 16, 2021
@postamar
Copy link
Contributor

Closing as this does indeed seem to work for schemas these days.

demo@127.0.0.1:26257/defaultdb> CREATE SCHEMA barf;
CREATE SCHEMA


Time: 34ms total (execution 34ms / network 0ms)

demo@127.0.0.1:26257/defaultdb> CREATE TABLE barf.foo (x INT PRIMARY KEY);
CREATE TABLE


Time: 7ms total (execution 7ms / network 0ms)

demo@127.0.0.1:26257/defaultdb> select * from current_timestamp();
        current_timestamp
---------------------------------
  2022-03-11 16:09:45.722436+00
(1 row)


Time: 1ms total (execution 0ms / network 0ms)

demo@127.0.0.1:26257/defaultdb> DROP SCHEMA barf CASCADE;
DROP SCHEMA


Time: 123ms total (execution 123ms / network 0ms)

demo@127.0.0.1:26257/defaultdb> SELECT * FROM barf.foo AS OF SYSTEM TIME '2022-03-11 16:09:45.722436+00';
  x
-----
(0 rows)


Time: 14ms total (execution 14ms / network 0ms)

SQL Foundations automation moved this from Backlog to Closed Mar 11, 2022
@exalate-issue-sync exalate-issue-sync bot added T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) and removed T-sql-schema-deprecated Use T-sql-foundations instead labels May 10, 2023
@blathers-crl blathers-crl bot added this to Triage in SQL Foundations May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
SQL Foundations
  
Done [after migration]
Development

No branches or pull requests

4 participants