Skip to content

Commit 91fc4f5

Browse files
💬Generate LLM translations (#1820)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 1b099a4 commit 91fc4f5

File tree

1 file changed

+139
-22
lines changed

1 file changed

+139
-22
lines changed
Lines changed: 139 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,140 @@
1-
---
2-
title: LAST_QUERY_ID
3-
---
4-
5-
返回当前会话中最近查询的查询ID,索引可以是(-1, 1, 1+2)...,超出范围的索引将返回空字符串。
6-
7-
## 语法
8-
9-
```sql
10-
LAST_QUERY_ID(<index>)
11-
```
12-
13-
## 示例
14-
15-
```sql
16-
SELECT LAST_QUERY_ID(-1);
17-
18-
┌──────────────────────────────────────┐
19-
│ last_query_id((- 1)) │
20-
├──────────────────────────────────────┤
21-
│ a6f615c6-5bad-4863-8558-afd01889448c │
22-
└──────────────────────────────────────┘
1+
---
2+
title: LAST_QUERY_ID
3+
---
4+
5+
基于查询的顺序,返回当前会话中查询的 ID。
6+
7+
:::note
8+
此函数目前仅支持通过 MySQL 协议,这意味着您必须使用与 MySQL 协议兼容的客户端连接到 Databend 才能使其工作。
9+
:::
10+
11+
## 语法
12+
13+
```sql
14+
LAST_QUERY_ID(<index>)
15+
```
16+
`index` 指定当前会话中的查询顺序,接受正数和负数,默认值为 `-1`
17+
- 正索引(从 `1` 开始)检索会话开始后的第 n 个查询。
18+
- 负索引从当前查询向后检索第 n 个查询。
19+
-`index``-1` 时,它返回当前查询的查询 ID。
20+
- 要检索上一个查询,请将 `index` 设置为 `-2`
21+
- 如果索引超出查询历史记录,则返回 NULL。
22+
23+
## 示例
24+
25+
此示例在新会话中运行三个简单查询,然后使用正索引和负索引来检索 `SELECT 3` 的查询 ID:
26+
27+
| | Positive | Negative |
28+
|----------------------------------------------|----------|----------|
29+
| `SELECT 1` | 1 | -4 |
30+
| `SELECT 2` | 2 | -3 |
31+
| `SELECT 3` | 3 | -2 |
32+
| `SELECT LAST_QUERY_ID(-2), LAST_QUERY_ID(3)` | 4 | -1 |
33+
34+
```bash
35+
MacBook-Air:~ eric$ mysql -u root -h 127.0.0.1 -P 3307
36+
Welcome to the MySQL monitor. Commands end with ; or \g.
37+
Your MySQL connection id is 9
38+
Server version: 8.0.90-v1.2.720-nightly-2280cc9480(rust-1.85.0-nightly-2025-04-08T04:40:36.379825500Z) 0
39+
40+
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
41+
42+
Oracle is a registered trademark of Oracle Corporation and/or its
43+
affiliates. Other names may be trademarks of their respective
44+
owners.
45+
46+
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
47+
48+
mysql> select 1;
49+
+------+
50+
| 1 |
51+
+------+
52+
| 1 |
53+
+------+
54+
1 row in set (0.02 sec)
55+
Read 1 rows, 1.00 B in 0.004 sec., 264.46 rows/sec., 264.46 B/sec.
56+
57+
mysql> select 2;
58+
+------+
59+
| 2 |
60+
+------+
61+
| 2 |
62+
+------+
63+
1 row in set (0.01 sec)
64+
Read 1 rows, 1.00 B in 0.003 sec., 366.94 rows/sec., 366.94 B/sec.
65+
66+
mysql> select 3;
67+
+------+
68+
| 3 |
69+
+------+
70+
| 3 |
71+
+------+
72+
1 row in set (0.01 sec)
73+
Read 1 rows, 1.00 B in 0.003 sec., 373.16 rows/sec., 373.16 B/sec.
74+
75+
mysql> SELECT LAST_QUERY_ID(-2), LAST_QUERY_ID(3);
76+
+--------------------------------------+--------------------------------------+
77+
| last_query_id(- 2) | last_query_id(3) |
78+
+--------------------------------------+--------------------------------------+
79+
| 74dd6dca-f9b0-44cd-99f4-ac7d11d47fee | 74dd6dca-f9b0-44cd-99f4-ac7d11d47fee |
80+
+--------------------------------------+--------------------------------------+
81+
1 row in set (0.02 sec)
82+
Read 1 rows, 1.00 B in 0.006 sec., 167.95 rows/sec., 167.95 B/sec.
83+
```
84+
85+
此示例演示了当 `<index>``-1` 时,该函数返回当前查询的查询 ID:
86+
87+
```bash
88+
MacBook-Air:~ eric$ mysql -u root -h 127.0.0.1 -P 3307
89+
Welcome to the MySQL monitor. Commands end with ; or \g.
90+
Your MySQL connection id is 10
91+
Server version: 8.0.90-v1.2.720-nightly-2280cc9480(rust-1.85.0-nightly-2025-04-08T04:40:36.379825500Z) 0
92+
93+
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
94+
95+
Oracle is a registered trademark of Oracle Corporation and/or its
96+
affiliates. Other names may be trademarks of their respective
97+
owners.
98+
99+
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
100+
101+
mysql> SELECT LAST_QUERY_ID(-1), LAST_QUERY_ID();
102+
+--------------------------------------+--------------------------------------+
103+
| last_query_id(- 1) | last_query_id() |
104+
+--------------------------------------+--------------------------------------+
105+
| 5a1afbc2-dc16-4b69-a0e6-615e0b970cb1 | 5a1afbc2-dc16-4b69-a0e6-615e0b970cb1 |
106+
+--------------------------------------+--------------------------------------+
107+
1 row in set (0.01 sec)
108+
Read 1 rows, 1.00 B in 0.003 sec., 393.68 rows/sec., 393.68 B/sec.
109+
110+
mysql> SELECT LAST_QUERY_ID(-2);
111+
+--------------------------------------+
112+
| last_query_id(- 2) |
113+
+--------------------------------------+
114+
| 5a1afbc2-dc16-4b69-a0e6-615e0b970cb1 |
115+
+--------------------------------------+
116+
1 row in set (0.01 sec)
117+
Read 1 rows, 1.00 B in 0.003 sec., 381.61 rows/sec., 381.61 B/sec.
118+
119+
mysql> SELECT LAST_QUERY_ID(1);
120+
+--------------------------------------+
121+
| last_query_id(1) |
122+
+--------------------------------------+
123+
| 5a1afbc2-dc16-4b69-a0e6-615e0b970cb1 |
124+
+--------------------------------------+
125+
1 row in set (0.01 sec)
126+
Read 1 rows, 1.00 B in 0.003 sec., 353.63 rows/sec., 353.63 B/sec.
127+
```
128+
129+
`index` 超出查询历史记录时,将返回 NULL。
130+
131+
```bash
132+
mysql> SELECT LAST_QUERY_ID(-100), LAST_QUERY_ID(100);
133+
+----------------------+--------------------+
134+
| last_query_id(- 100) | last_query_id(100) |
135+
+----------------------+--------------------+
136+
| | |
137+
+----------------------+--------------------+
138+
1 row in set (0.02 sec)
139+
Read 1 rows, 1.00 B in 0.008 sec., 128.69 rows/sec., 128.69 B/sec.
23140
```

0 commit comments

Comments
 (0)