Skip to content

Commit

Permalink
Merge branch 'main' into fix_purge
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyass authored Sep 27, 2023
2 parents b850274 + 84b0451 commit 761de94
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ In Databend, it's advisable to aim for an ideal block size of either 100MB (unco
- Segment & block compactions support distributed execution in cluster environments. You can enable them by setting ENABLE_DISTRIBUTED_COMPACT to 1. This helps enhance data query performance and scalability in cluster environments.

```sql
SET ENABLE_DISTRIBUTED_COMPACT = 1;
SET enable_distributed_compact = 1;
```

### Segment Compaction
Expand Down
2 changes: 1 addition & 1 deletion docs/doc/14-sql-commands/10-dml/dml-copy-into-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ COPY INTO provides a summary of the data loading results with these columns:
COPY INTO supports distributed execution in cluster environments. You can enable distributed COPY INTO by setting ENABLE_DISTRIBUTED_COPY_INTO to 1. This helps enhance data loading performance and scalability in cluster environments.

```sql
SET ENABLE_DISTRIBUTED_COPY_INTO = 1;
SET enable_distributed_copy_into = 1;
```

## Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/doc/14-sql-commands/10-dml/dml-replace.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ VALUES (123, 'John Doe', 60000, '[email protected]');
REPLACE INTO supports distributed execution in cluster environments. You can enable distributed REPLACE INTO by setting ENABLE_DISTRIBUTED_REPLACE_INTO to 1. This helps enhance data loading performance and scalability in cluster environments.

```sql
SET ENABLE_DISTRIBUTED_REPLACE_INTO = 1;
SET enable_distributed_replace_into = 1;
```

## Examples
Expand Down
142 changes: 32 additions & 110 deletions docs/doc/14-sql-commands/40-show/show-table-status.md
Original file line number Diff line number Diff line change
@@ -1,138 +1,60 @@
---
title: SHOW TABLE STATUS
---
import FunctionDescription from '@site/src/components/FunctionDescription';

Shows the status of the tables in a database. The status information includes various physical sizes and timestamps about a table, see [Examples](#examples) for details.
<FunctionDescription description="Introduced or updated: v1.2.131"/>

The command returns status information of all the tables in the current database by default. Use a FROM | IN clause to specify another database rather than the current one. You can also filter tables with a LIKE or WHERE clause.
Shows the status of the tables in a database. The status information includes various physical sizes and timestamps about a table, see [Examples](#examples) for details.

## Syntax

```sql
SHOW TABLE STATUS
[{FROM | IN} db_name]
[{FROM | IN} <database_name>]
[LIKE 'pattern' | WHERE expr]
```

| Parameter | Description |
|-----------|-----------------------------------------------------------------------------------------------------------------------------|
| FROM / IN | Specifies a database. If omitted, the command returns the results from the current database. |
| LIKE | Filters the results by the table names using case-sensitive pattern matching. |
| WHERE | Filters the results using an expression in the WHERE clause. |

## Examples

```sql
CREATE TABLE t(id INT);
The following example displays the status of tables in the current database, providing details such as name, engine, rows, and other relevant information:

-- Show status of all tables in the current database
```sql
SHOW TABLE STATUS;
*************************** 1. row ***************************
Name: t
Engine: FUSE
Version: 0
Row_format: NULL
Rows: 0
Avg_row_length: NULL
Data_length: 0
Max_data_length: NULL
Index_length: 0
Data_free: NULL
Auto_increment: NULL
Create_time: 2022-04-08 04:13:48.988 +0000
Update_time: NULL
Check_time: NULL
Collation: NULL
Checksum: NULL
Comment:
```

The following returns status information of the table named "t":

```sql
SHOW TABLE STATUS LIKE 't';
*************************** 1. row ***************************
Name: t
Engine: FUSE
Version: 0
Row_format: NULL
Rows: 0
Avg_row_length: NULL
Data_length: 0
Max_data_length: NULL
Index_length: 0
Data_free: NULL
Auto_increment: NULL
Create_time: 2022-04-08 04:13:48.988 +0000
Update_time: NULL
Check_time: NULL
Collation: NULL
Checksum: NULL
Comment:
name |engine|version|row_format|rows|avg_row_length|data_length|max_data_length|index_length|data_free|auto_increment|create_time |update_time|check_time|collation|checksum|comment|cluster_by|
-------+------+-------+----------+----+--------------+-----------+---------------+------------+---------+--------------+-----------------------------+-----------+----------+---------+--------+-------+----------+
books |FUSE | 0| | 2| | 160| | 713| | |2023-09-25 06:40:47.237 +0000| | | | | | |
mytable|FUSE | 0| | 5| | 40| | 1665| | |2023-08-28 07:53:05.455 +0000| | | | | |((a + 1)) |
ontime |FUSE | 0| | 199| | 147981| | 22961| | |2023-09-19 07:04:06.414 +0000| | | | | | |
```

The following uses a LIKE clause to return status information of the tables with a name starting with "t":
The following example displays the status of tables in the current database where the names start with 'my':

```sql
SHOW TABLE STATUS LIKE 't%';
*************************** 1. row ***************************
Name: t
Engine: FUSE
Version: 0
Row_format: NULL
Rows: 0
Avg_row_length: NULL
Data_length: 0
Max_data_length: NULL
Index_length: 0
Data_free: NULL
Auto_increment: NULL
Create_time: 2022-04-08 04:13:48.988 +0000
Update_time: NULL
Check_time: NULL
Collation: NULL
Checksum: NULL
Comment:
```

The following uses a WHERE clause to return status information of the tables with a name starting with "t":
SHOW TABLE STATUS LIKE 'my%';

```sql
SHOW TABLE STATUS WHERE name LIKE 't%';
*************************** 1. row ***************************
Name: t
Engine: FUSE
Version: 0
Row_format: NULL
Rows: 0
Avg_row_length: NULL
Data_length: 0
Max_data_length: NULL
Index_length: 0
Data_free: NULL
Auto_increment: NULL
Create_time: 2022-04-08 04:13:48.988 +0000
Update_time: NULL
Check_time: NULL
Collation: NULL
Checksum: NULL
Comment:
name |engine|version|row_format|rows|avg_row_length|data_length|max_data_length|index_length|data_free|auto_increment|create_time |update_time|check_time|collation|checksum|comment|cluster_by|
-------+------+-------+----------+----+--------------+-----------+---------------+------------+---------+--------------+-----------------------------+-----------+----------+---------+--------+-------+----------+
mytable|FUSE | 0| | 5| | 40| | 1665| | |2023-08-28 07:53:05.455 +0000| | | | | |((a + 1)) |
```

The following returns status information of all tables in the database `default`:
The following example displays the status of tables in the current database where the number of rows is greater than 100:

:::note
When using the SHOW TABLE STATUS query, be aware that some column names, such as "rows," may be interpreted as SQL keywords, potentially leading to errors. To avoid this issue, always enclose column names with backticks, as shown in this example. This ensures that column names are treated as identifiers rather than keywords in the SQL query.
:::

```sql
SHOW TABLE STATUS FROM 'default';
*************************** 1. row ***************************
Name: t
Engine: FUSE
Version: 0
Row_format: NULL
Rows: 0
Avg_row_length: NULL
Data_length: 0
Max_data_length: NULL
Index_length: 0
Data_free: NULL
Auto_increment: NULL
Create_time: 2022-04-08 04:13:48.988 +0000
Update_time: NULL
Check_time: NULL
Collation: NULL
Checksum: NULL
Comment:
SHOW TABLE STATUS WHERE `rows` > 100;

name |engine|version|row_format|rows|avg_row_length|data_length|max_data_length|index_length|data_free|auto_increment|create_time |update_time|check_time|collation|checksum|comment|cluster_by|
------+------+-------+----------+----+--------------+-----------+---------------+------------+---------+--------------+-----------------------------+-----------+----------+---------+--------+-------+----------+
ontime|FUSE | 0| | 199| | 147981| | 22961| | |2023-09-19 07:04:06.414 +0000| | | | | | |
```
111 changes: 50 additions & 61 deletions docs/doc/14-sql-commands/40-show/show-tables.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: SHOW TABLES
---
import FunctionDescription from '@site/src/components/FunctionDescription';

<FunctionDescription description="Introduced or updated: v1.2.131"/>

Lists the tables in the current or a specified database.

Expand All @@ -12,106 +15,92 @@ SHOW [FULL] TABLES
[HISTORY]
[LIKE '<pattern>' | WHERE <expr>]
```
Where:

`[FULL]`: Lists the tables with their property information. See [Examples](#examples) for more details.

`[{FROM | IN} <database_name>]`: Specifies a database. If omitted, the command returns the results from the current database.

`[HISTORY]`: If present, the results will include the dropped tables that are still within their retention period (24 hours by default).

`[LIKE '<pattern>']`: Filters the results by the table names using pattern matching.

`[WHERE <expr>]`: Filters the results using an expression in the WHERE clause.
| Parameter | Description |
|-----------|-----------------------------------------------------------------------------------------------------------------------------|
| FULL | Lists the tables with their property information. See [Examples](#examples) for more details. |
| FROM / IN | Specifies a database. If omitted, the command returns the results from the current database. |
| HISTORY | If present, the results will include the dropped tables that are still within their retention period (24 hours by default). |
| LIKE | Filters the results by the table names using case-sensitive pattern matching. |
| WHERE | Filters the results using an expression in the WHERE clause. |

## Examples

The following example lists all the tables in the current database:
The following example lists the names of all tables in the current database (default):

```sql
SHOW TABLES;

---
| tables_in_default |
|-------------------|
| hr_team |
| members |
| members_previous |
| members_view |
| support_team |
| t1 |
Tables_in_default|
-----------------+
books |
mytable |
ontime |
products |
```

The following example lists all the tables with their properties information:

```sql
SHOW FULL TABLES;

---
| tables_in_default | table_type | table_catalog | engine | create_time | num_rows | data_size | data_compressed_size | index_size |
|-------------------|------------|---------------|--------|-------------------------------|----------|-----------|----------------------|------------|
| hr_team | BASE TABLE | default | FUSE | 2022-08-29 12:58:09.992 +0000 | 4 | 80 | 674 | 774 |
| members | BASE TABLE | default | FUSE | 2022-08-29 17:53:34.282 +0000 | 2 | 38 | 392 | 460 |
| members_previous | BASE TABLE | default | FUSE | 2022-08-29 18:20:57.599 +0000 | 0 | 0 | 0 | 0 |
| members_view | BASE TABLE | default | VIEW | 2022-09-02 18:24:04.658 +0000 | \N | \N | \N | \N |
| support_team | BASE TABLE | default | FUSE | 2022-08-29 12:57:45.469 +0000 | 3 | 57 | 350 | 387 |
| t1 | BASE TABLE | default | FUSE | 2022-08-23 18:08:40.158 +0000 | 0 | 0 | 0 | 0 |
tables |table_type|database|catalog|engine|cluster_by|create_time |num_rows|data_size|data_compressed_size|index_size|
--------+----------+--------+-------+------+----------+-----------------------------+--------+---------+--------------------+----------+
books |BASE TABLE|default |default|FUSE | |2023-09-25 06:40:47.237 +0000| 2| 160| 579| 713|
mytable |BASE TABLE|default |default|FUSE |((a + 1)) |2023-08-28 07:53:05.455 +0000| 5| 40| 958| 1665|
ontime |BASE TABLE|default |default|FUSE | |2023-09-19 07:04:06.414 +0000| 199| 147981| 26802| 22961|
products|BASE TABLE|default |default|FUSE | |2023-09-06 07:09:00.619 +0000| 3| 99| 387| 340|
```

The following example demonstrates that the results will include dropped tables when the option HISTORY is present:
The following example demonstrates that the results will include dropped tables when the optional parameter HISTORY is present:

```sql
DROP TABLE t1;
DROP TABLE products;

SHOW TABLES;

---
| tables_in_default |
|-------------------|
| hr_team |
| members |
| members_previous |
| members_view |
| support_team |
Tables_in_default|
-----------------+
books |
mytable |
ontime |

SHOW TABLES HISTORY;

---
| tables_in_default | drop_time |
|-------------------|-------------------------------|
| hr_team | NULL |
| members | NULL |
| members_previous | NULL |
| members_view | NULL |
| support_team | NULL |
| t1 | 2022-09-02 18:29:27.918 +0000 |
Tables_in_default |drop_time |
------------------------+-----------------------------+
books |NULL |
mytable |NULL |
ontime |NULL |
products |2023-09-27 01:14:21.421 +0000|
```

The following example lists the tables containing the string "team" at the end of their name:
The following example lists the tables containing the string "time" at the end of their name:

```sql
SHOW TABLES LIKE '%team';
SHOW TABLES LIKE '%time';

---
| tables_in_default |
|-------------------|
| hr_team |
| support_team |
```
:::tip
Please note that the pattern matching is CASE-SENSITIVE. No results will be returned if you code the previous statement like this:
Tables_in_default|
-----------------+
ontime |

```sql
SHOW TABLES LIKE '%TEAM';
-- CASE-SENSITIVE pattern matching.
-- No results will be returned if you code the previous statement like this:
SHOW TABLES LIKE '%TIME';
```
:::

The following example lists the views in the current database using a WHERE clause:
The following example lists tables where the data size is greater than 1,000 bytes:

```sql
SHOW TABLES WHERE engine = 'VIEW';
SHOW TABLES WHERE data_size > 1000 ;

---
| tables_in_default |
|-------------------|
| members_view |
Tables_in_default|
-----------------+
ontime |
```
Binary file modified docs/public/img/load/load-extra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 761de94

Please sign in to comment.