Skip to content

Commit 3d04ff0

Browse files
authored
Merge pull request #7536 from soyeric128/blog-time-travel
docs: add blog
2 parents bf6f647 + d0fc976 commit 3d04ff0

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

website/blog/2022-09-08-find-peter.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Find Peter Parker in Databend
3+
description: time travel
4+
slug: time-travel
5+
date: 2022-09-08
6+
tags: [databend, time travel]
7+
authors:
8+
- name: wubx
9+
url: https://github.com/wubx
10+
image_url: https://github.com/wubx.png
11+
---
12+
13+
The most impressive part of the movie *Spider-Man: No Way Home* is "three generations coming together. In the story, when the spider-man's friend repeats the magic words "Find Peter Parker!", we surprisingly see two old friends on the screen, the previous generations of spider-man. They travel from other universes to join forces and develop cures for the villains.
14+
15+
![](../static/img/blog/spiderman.png)
16+
17+
Did you know that you have a similar magic power in Databend? That is, you can always get back the previous versions of your data in a few simple steps whenever you need them. The secret is Databend automatically creates and saves snapshots with timestamps of your tables when a data updating occurs, so you can track the history of a table and see how what it looked like at a time point in the past.
18+
19+
The following code creates a table first, and then inserts values with three separate SQL statements:
20+
21+
```sql
22+
create table spiderman(gen int, nickname varchar);
23+
24+
insert into spiderman values(1,'Peter-1');
25+
insert into spiderman values(2,'Peter-2');
26+
insert into spiderman values(3,'Peter-3');
27+
```
28+
29+
Databend creates and saves three snapshots for the code above. Each one holds a historical version of the data in the table.
30+
31+
![](../static/img/blog/peters.png)
32+
33+
To find them, use the system function [FUSE_SNAPSHOT](https://databend.rs/doc/reference/functions/system-functions/fuse_snapshot). The function returns everything you may need to know about the saved snapshots of a table, such as the snapshot IDs, timestamps, and locations.
34+
35+
```sql
36+
select snapshot_id,previous_snapshot_id, timestamp from fuse_snapshot('default','spiderman');
37+
38+
---
39+
+----------------------------------+----------------------------------+----------------------------+
40+
| snapshot_id | previous_snapshot_id | timestamp |
41+
+----------------------------------+----------------------------------+----------------------------+
42+
| 34b8df220edc4d8cb9e3e76118788686 | 4bb479751b7144d8aa2b53e5b281453f | 2022-08-30 01:18:53.202724 |
43+
| 4bb479751b7144d8aa2b53e5b281453f | a2801ed9656d42c9812f2921214f0795 | 2022-08-30 01:18:35.597615 |
44+
| a2801ed9656d42c9812f2921214f0795 | NULL | 2022-08-30 01:18:21.750208 |
45+
+----------------------------------+----------------------------------+----------------------------+
46+
```
47+
48+
You can now query the history data with a snapshot or timestamp by including the [AT](https://databend.rs/doc/reference/sql/query-syntax/dml-at) clause in the SELECT statement:
49+
50+
```sql
51+
select * from spiderman at(snapshot=>'a2801ed9656d42c9812f2921214f0795');
52+
53+
---
54+
+------+----------+
55+
| gen | nickname |
56+
+------+----------+
57+
| 1 | Peter-1 |
58+
+------+----------+
59+
```
60+
61+
```sql
62+
select * from spiderman at(timestamp=>'2022-08-30 01:18:21.750208'::timestamp);
63+
64+
---
65+
+------+----------+
66+
| gen | nickname |
67+
+------+----------+
68+
| 1 | Peter-1 |
69+
+------+----------+
70+
```
71+
72+
The "magic" explained above is part of the powerful Time Travel feature of Databend that enables you to query, back up, or restore from a specified historical version of your data. That's not all about the feature. You can do more with the snapshots to make your work easier. Join the Databend community to find out more "magic tricks".

website/static/img/blog/peters.png

85.2 KB
Loading

website/static/img/blog/spiderman.png

1.29 MB
Loading

0 commit comments

Comments
 (0)