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

statments for session query #1901

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,64 @@ specific language governing permissions and limitations
under the License.
-->



## Description

This statement is used to clear query statistics

grammar:
## Syntax

```sql
CLEAN [ALL| DATABASE | TABLE] QUERY STATS [[FOR db_name]|[FROM|IN] table_name]];
CLEAN [ { ALL| DATABASE | TABLE } ] QUERY STATS [ { [ FOR <db_name>] | [ { FROM | IN } ] <table_name>]];
```

Remarks:
## Required Parameters

**1. `ALL`**

> Use ALL to clear all query statistics

**2. `DATABASE`**

> Use DATABASE to clear database query statistics

**3. `TABLE`**

> Use TABLE to clear table query statistics

## Optional Parameters

**1. `<db_name>`**

1. If ALL is specified, all query statistics are cleared, including database and table, admin privilege is needed
2. If DATABASE is specified, the query statistics of the specified database are cleared, alter privilege for this database is needed
3. If TABLE is specified, the query statistics of the specified table are cleared, alter privilege for this table is needed
> If this parameter is set, the statistics of the corresponding database are cleared

## Example
**2. `<table_name>`**

1. Clear all statistics
2.
```sql
clean all query stats;
```
> If this parameter is set, the statistics of the corresponding table are cleared

2. Clear the specified database statistics

```sql
clean database query stats for test_query_db;
```
3. Clear the specified table statistics
## Access Control Requirements

```sql
clean table query stats from test_query_db.baseall;
```
The user who executes this SQL command must have at least the following permissions:

## Keywords
| Privilege | Object | Notes |
|:-----------|:---------|:--------------------------|
| ADMIN_PRIV | ALL | If ALL is specified, the ADMIN permission is required |
| ALTER_PRIV | DATABASE | If the database is specified, the ALTER permission for the corresponding database is required |
| ADMIN_PRIV | TABLE | If you specify a table, you need alter permission for that table |

CLEAN, QUERY, STATS

## Best Practice
## Examples

```sql
clean all query stats
```

```sql
clean database query stats for test_query_db
```

```sql
clean table query stats from test_query_db.baseall
```


78 changes: 49 additions & 29 deletions docs/sql-manual/sql-statements/session/queries/KILL-QUERY.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,82 @@ specific language governing permissions and limitations
under the License.
-->

## Description

Each Doris connection runs in a separate thread. Use this statement to terminate the thread.

In Doris, each connection runs in a separate thread. You can terminate a thread using the `KILL processlist_id`statement.
## Syntax

The `processlist_id` for the thread can be found in the Id column from the SHOW PROCESSLIST output. Or you can use the `SELECT CONNECTION_ID()` command to query the current connection id.
```SQL
KILL [CONNECTION] <processlist_id>
```

Syntax:
## Varaint Syntax

```sql
KILL [CONNECTION] processlist_id
```SQL
KILL QUERY [ { <processlist_id> | <query_id> } ]
```

## Kill query
## Required Parameters

You can also terminate the query command under execution based on the processlist_id or the query_id.
**1. `<processlist_id>`**

Syntax:
> Indicates the ID of the connection thread that needs to be killed

```sql
KILL QUERY processlist_id | query_id
```
**2. `<query_id>`**

> Indicates the ID of the query to be killed

## Optional Parameters

**1. `CONNECTION`**

> Indicates whether the thread is currently connected

## Access Control Requirements

The user who executes this SQL command must have at least the following permissions:

## Example
| Privilege | Object | Notes |
|:--------------|:-----------|:-----------------------|
| GRANT_PRIV | DATABASE | GRANT permission is required for the KILL statement |

1. Check the current connection id.
wyx123654 marked this conversation as resolved.
Show resolved Hide resolved
## Usage Notes

- The thread process list identifier can be queried from the Id column output by the SHOW PROCESSLIST

- The Connection ID can be queried from SELECT CONNECTION_ID()

## Examples

```sql
mysql select connection_id();
select connection_id()
```

```text
+-----------------+
| connection_id() |
+-----------------+
| 48 |
+-----------------+
1 row in set (0.00 sec)
```

2. Check all connection id.

```sql
mysql SHOW PROCESSLIST;
SHOW PROCESSLIST
```

```text
+------------------+------+------+--------------------+---------------------+----------+---------+---------+------+-------+-----------------------------------+---------------------------------------------------------------------------------------+
| CurrentConnected | Id | User | Host | LoginTime | Catalog | Db | Command | Time | State | QueryId | Info |
+------------------+------+------+--------------------+---------------------+----------+---------+---------+------+-------+-----------------------------------+---------------------------------------------------------------------------------------+
| Yes | 48 | root | 10.16.xx.xx:44834 | 2023-12-29 16:49:47 | internal | test | Query | 0 | OK | e6e4ce9567b04859-8eeab8d6b5513e38 | SHOW PROCESSLIST |
| | 50 | root | 192.168.xx.xx:52837 | 2023-12-29 16:51:34 | internal | | Sleep | 1837 | EOF | deaf13c52b3b4a3b-b25e8254b50ff8cb | SELECT @@session.transaction_isolation |
| | 51 | root | 192.168.xx.xx:52843 | 2023-12-29 16:51:35 | internal | | Sleep | 907 | EOF | 437f219addc0404f-9befe7f6acf9a700 | /* ApplicationName=DBeaver Ultimate 23.1.3 - Metadata */ SHOW STATUS |
| | 55 | root | 192.168.xx.xx:55533 | 2023-12-29 17:09:32 | internal | test | Sleep | 271 | EOF | f02603dc163a4da3-beebbb5d1ced760c | /* ApplicationName=DBeaver Ultimate 23.1.3 - SQLEditor <Console> */ SELECT DATABASE() |
| | 47 | root | 10.16.xx.xx:35678 | 2023-12-29 16:21:56 | internal | test | Sleep | 3528 | EOF | f4944c543dc34a99-b0d0f3986c8f1c98 | select * from test |
| Yes | 48 | root | 10.16.xx.xx:44834 | 2025-01-21 16:49:47 | internal | test | Query | 0 | OK | e6e4ce9567b04859-8eeab8d6b5513e38 | SHOW PROCESSLIST |
| | 50 | root | 192.168.xx.xx:52837 | 2025-01-21 16:51:34 | internal | | Sleep | 1837 | EOF | deaf13c52b3b4a3b-b25e8254b50ff8cb | SELECT @@session.transaction_isolation |
| | 51 | root | 192.168.xx.xx:52843 | 2025-01-21 16:51:35 | internal | | Sleep | 907 | EOF | 437f219addc0404f-9befe7f6acf9a700 | /* ApplicationName=DBeaver Ultimate 23.1.3 - Metadata */ SHOW STATUS |
| | 55 | root | 192.168.xx.xx:55533 | 2025-01-21 17:09:32 | internal | test | Sleep | 271 | EOF | f02603dc163a4da3-beebbb5d1ced760c | /* ApplicationName=DBeaver Ultimate 23.1.3 - SQLEditor <Console> */ SELECT DATABASE() |
| | 47 | root | 10.16.xx.xx:35678 | 2025-01-21 16:21:56 | internal | test | Sleep | 3528 | EOF | f4944c543dc34a99-b0d0f3986c8f1c98 | select * from test |
+------------------+------+------+--------------------+---------------------+----------+---------+---------+------+-------+-----------------------------------+---------------------------------------------------------------------------------------+
5 rows in set (0.00 sec)
```

3. Kill the currently running query, which will then be displayed as canceled.

```sql
mysql kill query 55;
Query OK, 0 rows affected (0.01 sec)
kill 51
```

91 changes: 46 additions & 45 deletions docs/sql-manual/sql-statements/session/queries/SHOW-PROCESSLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,68 +25,69 @@ specific language governing permissions and limitations
under the License.
-->




## Description

Display the running threads of the user. It should be noted that except the root user who can see all running threads, other users can only see their own running threads, and cannot see the running threads of other users.
Displays the thread that the user is running

Only display current connected FE's connection list by default, you can set session variable ```set show_all_fe_connection = true``` to show all FE's connection.

grammar:
## Syntax

```sql
SHOW [FULL] PROCESSLIST
```

illustrate:

- CurrentConnected: Indicates whether the connection is currently connected
- Id: It is the unique identifier of this thread. When we find that there is a problem with this thread, we can use the kill command to add this Id value to kill this thread.
- User: refers to the user who started this thread.
- Host: Records the IP and port number of the client sending the request. Through this information, when troubleshooting the problem, we can locate which client and which process sent the request.
- LoginTime: Timestamp when the connection is make.
- Catalog: Catalog name.
- Db: which database the currently executed command is on. If no database is specified, the value is NULL .
- Command: refers to the command that the thread is executing at the moment.
- Time: Indicates the time the thread is in the current state.
- State: The state of the thread, corresponding to Command.
- QueryId: The ID of the current query statement.
- Info: Generally recorded is the statement executed by the thread. By default, only the first 100 characters are displayed, that is, the statement you see may be truncated. To see all the information, you need to use show full processlist.
## Optional Parameters

Common Command types are as follows:
**1. `FULL`**

- Query: The thread is executing a statement
- Sleep: is waiting for a client to send it an execute statement
- Quit: the thread is exiting
- Kill : The kill statement is being executed to kill the specified thread
> Indicates whether to view the connection information of other users

Other types can refer to [MySQL official website for explanation](https://dev.mysql.com/doc/refman/5.6/en/thread-commands.html)
## Return Value

## Example
| column | Instructions |
|------------------|--------------------------------------|
| CurrentConnected | Whether the connection is current |
| Id | The unique identification of this thread |
| User | The user who started this thread |
| Host | The IP address and port number of the client sending the request are recorded |
| LoginTime | Time to establish a connection |
| Catalog | In which data directory is the command currently executed |
| Db | On which database is the command being executed? If no database is specified, the value is NULL |
| Command | The command that the thread is executing at this moment |
| Time | Time when the previous command is submitted to the current status, in seconds |
| State | State of thread |
| QueryId | ID of the current query statement |
| Info | Generally, the statement executed by the thread is recorded, and only the first 100 characters are displayed by default |

1. View the threads running by the current user
Common Command types are as follows:

```SQL
SHOW PROCESSLIST
```
| column | Instructions |
| -- | -- |
| Query | The thread is executing a statement |
| Sleep | Waiting for the client to send it an execution statement |
| Quit | The thread is exiting |
| Kill | Executing the kill statement |

return
## Access Control Requirements

```
MySQL [test]> show full processlist;
+------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+
| CurrentConnected | Id | User | Host | LoginTime | Catalog | Db | Command | Time | State | QueryId | Info |
+------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+
| Yes | 0 | root | 127.0.0.1:34650 | 2023-09-06 12:01:02 | internal | test | Query | 0 | OK | c84e397193a54fe7-bbe9bc219318b75e | select 1 |
| | 1 | root | 127.0.0.1:34776 | 2023-09-06 12:01:07 | internal | | Sleep | 29 | EOF | 886ffe2894314f50-8dd73a6ca06699e4 | show full processlist |
+------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+
```
The user who executes this SQL command must have at least the following permissions:

## Keywords
| Privilege | Object | Notes |
|:-------------|:----------|:---------------------------|
| ADMIN_PRIV | DATABASE | If you want to view the connection information of other users, you need the ADMIN permission |

SHOW, PROCESSLIST
## Examples

```sql
SHOW PROCESSLIST
```

```text
+------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+
| CurrentConnected | Id | User | Host | LoginTime | Catalog | Db | Command | Time | State | QueryId | Info |
+------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+
| Yes | 0 | root | 127.0.0.1:34650 | 2025-01-21 12:01:02 | internal | test | Query | 0 | OK | c84e397193a54fe7-bbe9bc219318b75e | select 1 |
| | 1 | root | 127.0.0.1:34776 | 2025-01-21 12:01:07 | internal | | Sleep | 29 | EOF | 886ffe2894314f50-8dd73a6ca06699e4 | show full processlist |
+------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+
```

## Best Practice

Loading
Loading