You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/doc/14-sql-commands/00-ddl/20-table/60-optimize-table.md
+2-78Lines changed: 2 additions & 78 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ The objective of optimizing a table in Databend is to compact or purge its histo
8
8
Databend's Time Travel feature relies on historical data. If you purge historical data from a table with the command `OPTIMIZE TABLE <your_table> PURGE` or `OPTIMIZE TABLE <your_table> ALL`, the table will not be eligible for time travel. The command removes all snapshots (except the most recent one) and their associated segments,block files and table statistic file.
9
9
:::
10
10
11
-
## What are Snapshot, Segment, Block and Table statistic file?
11
+
## What are Snapshot, Segment, Block?
12
12
13
13
Snapshot, segment, and block are the concepts Databend uses for data storage. Databend uses them to construct a hierarchical structure for storing table data.
14
14
@@ -20,8 +20,6 @@ A snapshot is a JSON file that does not save the table's data but indicate the s
20
20
21
21
A segment is a JSON file that organizes the storage blocks (at least 1, at most 1,000) where the data is stored. If you run [FUSE_SEGMENT](../../../15-sql-functions/111-system-functions/fuse_segment.md) against a snapshot with the snapshot ID, you can find which segments are referenced by the snapshot.
22
22
23
-
A table statistic file is a JSON file that save table statistic data, such as distinct values of table column.
24
-
25
23
Databends saves actual table data in parquet files and considers each parquet file as a block. If you run [FUSE_BLOCK](../../../15-sql-functions/111-system-functions/fuse_block.md) against a snapshot with the snapshot ID, you can find which blocks are referenced by the snapshot.
26
24
27
25
Databend creates a unique ID for each database and table for storing the snapshot, segment, and block files and saves them to your object storage in the path `<bucket_name>/[root]/<db_id>/<table_id>/`. Each snapshot, segment, and block file is named with a UUID (32-character lowercase hexadecimal string).
@@ -31,7 +29,6 @@ Databend creates a unique ID for each database and table for storing the snapsho
Purges the historical data of table. Only the latest snapshot (including the segments, blocks and table statistic file referenced by this snapshot) will be kept.
73
+
(For more explanations of table statistic file, see [ANALYZE TABLE](./80-analyze-table.md).)
Works the same way as `OPTIMIZE TABLE <table_name> PURGE`.
100
97
101
-
-`ANALYZE TABLE <table_name>`
102
-
103
-
Estimates the number of distinct values of each column in a table.
104
-
105
-
- It does not display the estimated results after execution. To show the estimated results, use the function [FUSE_STATISTIC](../../../15-sql-functions/111-system-functions/fuse_statistic.md).
106
-
- The command does not identify distinct values by comparing them but by counting the number of storage segments and blocks. This might lead to a significant difference between the estimated results and the actual value, for example, multiple blocks holding the same value. In this case, Databend recommends compacting the storage segments and blocks to merge them as much as possible before you run the estimation.
107
-
108
98
## Examples
109
99
110
100
This example compacts and purges historical data from a table:
The objective of analyzing a table in Databend is to calculate table statistics, such as distinct number of columns.
6
+
7
+
## What is Table statistic file?
8
+
9
+
A table statistic file is a JSON file that save table statistic data, such as distinct values of table column.
10
+
11
+
Databend creates a unique ID for each database and table for storing the table statistic file and saves them to your object storage in the path `<bucket_name>/[root]/<db_id>/<table_id>/`. Each table statistic file is named with a UUID (32-character lowercase hexadecimal string).
Estimates the number of distinct values of each column in a table.
25
+
26
+
- It does not display the estimated results after execution. To show the estimated results, use the function [FUSE_STATISTIC](../../../15-sql-functions/111-system-functions/fuse_statistic.md).
27
+
- The command does not identify distinct values by comparing them but by counting the number of storage segments and blocks. This might lead to a significant difference between the estimated results and the actual value, for example, multiple blocks holding the same value. In this case, Databend recommends compacting the storage segments and blocks to merge them as much as possible before you run the estimation.
28
+
29
+
## Examples
30
+
31
+
This example estimates the number of distinct values for each column in a table and shows the results with the function FUSE_STATISTIC:
32
+
33
+
```sql
34
+
createtablet(a uint64);
35
+
36
+
insert into t values (5);
37
+
insert into t values (6);
38
+
insert into t values (7);
39
+
40
+
select*from t order by a;
41
+
42
+
----
43
+
5
44
+
6
45
+
7
46
+
47
+
-- FUSE_STATISTIC will not return any results until you run an estimation with OPTIMIZE TABLE.
48
+
select*from fuse_statistic('db_09_0020', 't');
49
+
50
+
analyze table `t`;
51
+
52
+
select*from fuse_statistic('db_09_0020', 't');
53
+
54
+
----
55
+
(0,3);
56
+
57
+
58
+
insert into t values (5);
59
+
insert into t values (6);
60
+
insert into t values (7);
61
+
62
+
select*from t order by a;
63
+
64
+
----
65
+
5
66
+
5
67
+
6
68
+
6
69
+
7
70
+
7
71
+
72
+
-- FUSE_STATISTIC returns results of your last estimation. To get the most recent estimated values, run the estimation again.
73
+
-- OPTIMIZE TABLE does not identify distinct values by comparing them but by counting the number of storage segments and blocks.
74
+
select*from fuse_statistic('db_09_0020', 't');
75
+
76
+
----
77
+
(0,3);
78
+
79
+
analyze table `t`;
80
+
81
+
select*from fuse_statistic('db_09_0020', 't');
82
+
83
+
----
84
+
(0,6);
85
+
86
+
-- Best practice: Compact the table before running the estimation.
0 commit comments