在 Snowflake 中有没有办法找出 table 何时被截断?
In Snowflake is there a way to find out when a table was truncated?
我搜索了文档并查看了信息模式视图,但是,我不确定如何确定 table 何时被截断,有什么想法吗?
给出几个使用QUERY_HISTORY的例子。信息架构 query_history 是一个 table 函数。
最近 1 小时内的搜索历史以检查被截断的 table -
select query_id,query_text,start_time,end_time from table(information_schema.query_history(dateadd('hours'
,-1,current_timestamp()),
current_timestamp())) where query_text like 'TRUNCATE%test%';
+--------------------------------------+---------------------------+-------------------------------+-------------------------------+
| QUERY_ID | QUERY_TEXT | START_TIME | END_TIME |
|--------------------------------------+---------------------------+-------------------------------+-------------------------------|
| 01a397da-3200-5a32-0000-00006ca565d1 | TRUNCATE table test_hash; | 2022-04-13 20:38:48.536 -0700 | 2022-04-13 20:38:48.951 -0700 |
+--------------------------------------+---------------------------+-------------------------------+-------------------------------+
下面是将被截断的示例 table -
select count(*) from player;
+----------+
| COUNT(*) |
|----------|
| 4 |
+----------+
发出截断命令 -
truncate table player;
+----------------------------------+
| status |
|----------------------------------|
| Statement executed successfully. |
+----------------------------------+
将在 QUERY_HISTORY 中搜索 table 截断。
查询是区分大小写的,所以在使用in predicate 进行搜索时需要注意。
下面不会给出任何结果,因为我们使用小写查询(截断)
select query_id,query_text,start_time,end_time from table(information_schema.query_history(dateadd('hours'
,-1,current_timestamp()),current_timestamp())) where query_text like 'TRUNCATE%player%';
+----------+------------+------------+----------+
| QUERY_ID | QUERY_TEXT | START_TIME | END_TIME |
|----------+------------+------------+----------|
+----------+------------+------------+----------+
使用小写再次搜索,或者您可以使用函数将 query_text 转换为 lower/upper 并在谓词中给出相同的大小写。
例如上(query_text)像'TRUNCATE%PLAYER%';
select query_id,query_text,start_time,end_time from table(information_schema.query_history(dateadd('hours'
,-1,current_timestamp()),current_timestamp())) where query_text like 'truncate%player%';
+--------------------------------------+------------------------+-------------------------------+-------------------------------+
| QUERY_ID | QUERY_TEXT | START_TIME | END_TIME |
|--------------------------------------+------------------------+-------------------------------+-------------------------------|
| 01a397e2-3200-5a1a-0000-00006ca5560d | truncate table player; | 2022-04-13 20:46:22.083 -0700 | 2022-04-13 20:46:22.471 -0700 |
+--------------------------------------+------------------------+-------------------------------+-------------------------------+
我搜索了文档并查看了信息模式视图,但是,我不确定如何确定 table 何时被截断,有什么想法吗?
给出几个使用QUERY_HISTORY的例子。信息架构 query_history 是一个 table 函数。
最近 1 小时内的搜索历史以检查被截断的 table -
select query_id,query_text,start_time,end_time from table(information_schema.query_history(dateadd('hours'
,-1,current_timestamp()),
current_timestamp())) where query_text like 'TRUNCATE%test%';
+--------------------------------------+---------------------------+-------------------------------+-------------------------------+
| QUERY_ID | QUERY_TEXT | START_TIME | END_TIME |
|--------------------------------------+---------------------------+-------------------------------+-------------------------------|
| 01a397da-3200-5a32-0000-00006ca565d1 | TRUNCATE table test_hash; | 2022-04-13 20:38:48.536 -0700 | 2022-04-13 20:38:48.951 -0700 |
+--------------------------------------+---------------------------+-------------------------------+-------------------------------+
下面是将被截断的示例 table -
select count(*) from player;
+----------+
| COUNT(*) |
|----------|
| 4 |
+----------+
发出截断命令 -
truncate table player;
+----------------------------------+
| status |
|----------------------------------|
| Statement executed successfully. |
+----------------------------------+
将在 QUERY_HISTORY 中搜索 table 截断。 查询是区分大小写的,所以在使用in predicate 进行搜索时需要注意。 下面不会给出任何结果,因为我们使用小写查询(截断)
select query_id,query_text,start_time,end_time from table(information_schema.query_history(dateadd('hours'
,-1,current_timestamp()),current_timestamp())) where query_text like 'TRUNCATE%player%';
+----------+------------+------------+----------+
| QUERY_ID | QUERY_TEXT | START_TIME | END_TIME |
|----------+------------+------------+----------|
+----------+------------+------------+----------+
使用小写再次搜索,或者您可以使用函数将 query_text 转换为 lower/upper 并在谓词中给出相同的大小写。 例如上(query_text)像'TRUNCATE%PLAYER%';
select query_id,query_text,start_time,end_time from table(information_schema.query_history(dateadd('hours'
,-1,current_timestamp()),current_timestamp())) where query_text like 'truncate%player%';
+--------------------------------------+------------------------+-------------------------------+-------------------------------+
| QUERY_ID | QUERY_TEXT | START_TIME | END_TIME |
|--------------------------------------+------------------------+-------------------------------+-------------------------------|
| 01a397e2-3200-5a1a-0000-00006ca5560d | truncate table player; | 2022-04-13 20:46:22.083 -0700 | 2022-04-13 20:46:22.471 -0700 |
+--------------------------------------+------------------------+-------------------------------+-------------------------------+