xy720 commented on code in PR #18805:
URL: https://github.com/apache/doris/pull/18805#discussion_r1184845289


##########
docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-QUERY-STATS.md:
##########
@@ -0,0 +1,196 @@
+---
+{
+    "title": "SHOW-QUERY-STATS",
+    "language": "zh-CN"
+}
+
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+## SHOW-QUERY-STATS
+
+
+### Name
+<version since="dev">
+SHOW QUERY STATS
+</version>
+
+### Description
+
+该语句用于展示数据库中历史查询命中的库表列的情况
+
+```sql
+SHOW QUERY STATS [[FOR db_name]|[FROM table_name]] [ALL] [VERBOSE]];
+```
+
+说明:
+
+1. 支持查询数据库和表的历史查询命中情况,重启fe后数据会重置,每个fe单独统计
+2. 通过 FROM DATABASE 和FROM TABLE 可以指定查询数据库或者表的命中情况,后面分别接数据库名或者表名
+3. ALL 可以指定是否展示所有index的查询命中情况,VERBOSE 可以展示更详细的命中情况, 这两个参数可以单独使用,
+   也可以一起使用,但是必须放在最后 而且只能用在表的查询上
+4. 如果没有use 任何数据库那么直接执行`SHOW QUERY STATS` 将展示所有数据库的命中情况

Review Comment:
   ```suggestion
   4. 如果没有 use 任何数据库那么直接执行`SHOW QUERY STATS` 将展示所有数据库的命中情况
   ```



##########
docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-QUERY-STATS.md:
##########
@@ -0,0 +1,196 @@
+---
+{
+    "title": "SHOW-QUERY-STATS",
+    "language": "zh-CN"
+}
+
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+## SHOW-QUERY-STATS
+
+
+### Name
+<version since="dev">
+SHOW QUERY STATS
+</version>
+
+### Description
+
+该语句用于展示数据库中历史查询命中的库表列的情况
+
+```sql
+SHOW QUERY STATS [[FOR db_name]|[FROM table_name]] [ALL] [VERBOSE]];
+```
+
+说明:
+
+1. 支持查询数据库和表的历史查询命中情况,重启fe后数据会重置,每个fe单独统计
+2. 通过 FROM DATABASE 和FROM TABLE 可以指定查询数据库或者表的命中情况,后面分别接数据库名或者表名

Review Comment:
   ```suggestion
   2. 通过 FOR DATABASE 和 FROM TABLE 可以指定查询数据库或者表的命中情况,后面分别接数据库名或者表名
   ```



##########
docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/CLEAN-QUERY-STATS.md:
##########
@@ -0,0 +1,75 @@
+---
+{
+    "title": "CLEAN-QUERY-STATS",
+    "language": "zh-CN"
+}
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+## CLEAN-QUERY-STATS
+
+### Name
+
+<version since="dev">
+CLEAN QUERY STATS
+</version>
+
+### Description
+
+该语句用请空查询统计信息
+
+语法:
+
+```sql
+CLEAN [ALL| DATABASE | TABLE] QUERY STATS [[FOR db_name]|[FROM|IN] 
table_name]];
+```
+
+说明:
+

Review Comment:
   may be here should tell user what kind of privilege is needed



##########
docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-QUERY-STATS.md:
##########
@@ -0,0 +1,196 @@
+---
+{
+    "title": "SHOW-QUERY-STATS",
+    "language": "zh-CN"
+}
+
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+## SHOW-QUERY-STATS
+
+
+### Name
+<version since="dev">
+SHOW QUERY STATS
+</version>
+
+### Description
+
+该语句用于展示数据库中历史查询命中的库表列的情况
+
+```sql
+SHOW QUERY STATS [[FOR db_name]|[FROM table_name]] [ALL] [VERBOSE]];
+```
+
+说明:
+
+1. 支持查询数据库和表的历史查询命中情况,重启fe后数据会重置,每个fe单独统计
+2. 通过 FROM DATABASE 和FROM TABLE 可以指定查询数据库或者表的命中情况,后面分别接数据库名或者表名
+3. ALL 可以指定是否展示所有index的查询命中情况,VERBOSE 可以展示更详细的命中情况, 这两个参数可以单独使用,
+   也可以一起使用,但是必须放在最后 而且只能用在表的查询上
+4. 如果没有use 任何数据库那么直接执行`SHOW QUERY STATS` 将展示所有数据库的命中情况
+5. 命中结果中可能有两列:
+   QueryCount:该列被查询次数
+   FilterCount: 该列作为where 条件被查询的次数
+### Example
+
+1. 展示表`baseall` 的查询命中情况
+
+   ```sql
+    MySQL [test_query_db]> show query stats from baseall;
+    +-------+------------+-------------+
+    | Field | QueryCount | FilterCount |
+    +-------+------------+-------------+
+    | k0    | 0          | 0           |
+    | k1    | 0          | 0           |
+    | k2    | 0          | 0           |
+    | k3    | 0          | 0           |
+    | k4    | 0          | 0           |
+    | k5    | 0          | 0           |
+    | k6    | 0          | 0           |
+    | k10   | 0          | 0           |
+    | k11   | 0          | 0           |
+    | k7    | 0          | 0           |
+    | k8    | 0          | 0           |
+    | k9    | 0          | 0           |
+    | k12   | 0          | 0           |
+    | k13   | 0          | 0           |
+    +-------+------------+-------------+
+    14 rows in set (0.002 sec)
+    
+    MySQL [test_query_db]> select k0, k1,k2, sum(k3) from baseall  where k9 > 
1 group by k0,k1,k2;
+    +------+------+--------+-------------+
+    | k0   | k1   | k2     | sum(`k3`)   |
+    +------+------+--------+-------------+
+    |    0 |    6 |  32767 |        3021 |
+    |    1 |   12 |  32767 | -2147483647 |
+    |    0 |    3 |   1989 |        1002 |
+    |    0 |    7 | -32767 |        1002 |
+    |    1 |    8 |    255 |  2147483647 |
+    |    1 |    9 |   1991 | -2147483647 |
+    |    1 |   11 |   1989 |       25699 |
+    |    1 |   13 | -32767 |  2147483647 |
+    |    1 |   14 |    255 |         103 |
+    |    0 |    1 |   1989 |        1001 |
+    |    0 |    2 |   1986 |        1001 |
+    |    1 |   15 |   1992 |        3021 |
+    +------+------+--------+-------------+
+    12 rows in set (0.050 sec)
+    
+    MySQL [test_query_db]> show query stats from baseall;
+    +-------+------------+-------------+
+    | Field | QueryCount | FilterCount |
+    +-------+------------+-------------+
+    | k0    | 1          | 0           |
+    | k1    | 1          | 0           |
+    | k2    | 1          | 0           |
+    | k3    | 1          | 0           |
+    | k4    | 0          | 0           |
+    | k5    | 0          | 0           |
+    | k6    | 0          | 0           |
+    | k10   | 0          | 0           |
+    | k11   | 0          | 0           |
+    | k7    | 0          | 0           |
+    | k8    | 0          | 0           |
+    | k9    | 1          | 1           |
+    | k12   | 0          | 0           |
+    | k13   | 0          | 0           |
+    +-------+------------+-------------+
+    14 rows in set (0.001 sec)
+   ```
+
+2. 展示表的所物化视图的的命中的汇总情况
+
+   ```sql
+   MySQL [test_query_db]> show query stats from table baseall all;

Review Comment:
   ```suggestion
      MySQL [test_query_db]> show query stats from baseall all;
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/CleanQueryStatsStmt.java:
##########
@@ -0,0 +1,149 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.DatabaseIf;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.cluster.ClusterNamespace;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.UserException;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.system.SystemInfoService;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * CLEAN ALL QUERY STATS;
+ * CLEAN DATABASE QUERY STATS FROM db;
+ * CLEAN TABLE QUERY STATS FROM db.table;
+ */
+public class CleanQueryStatsStmt extends DdlStmt {
+    private String dbName;
+    private TableName tableName;
+    private Scope scope;
+
+    /**
+     * CLEAN DATABASE QUERY STATS FROM db;
+     */
+    public CleanQueryStatsStmt(String dbName, Scope scope) {
+        this.dbName = dbName;
+        this.tableName = null;
+        this.scope = scope;
+    }
+
+    /**
+     * CLEAN TABLE QUERY STATS FROM db.table;
+     */
+    public CleanQueryStatsStmt(TableName tableName, Scope scope) {
+        this.dbName = null;
+        this.tableName = tableName;
+        this.scope = scope;
+    }
+
+    public CleanQueryStatsStmt() {
+        this.scope = Scope.ALL;
+        this.tableName = null;
+        this.dbName = null;
+    }
+
+    public String getDbName() {
+        return dbName;
+    }
+
+    public TableName getTableName() {
+        return tableName;
+    }
+
+    public Scope getScope() {
+        return scope;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws UserException {
+        super.analyze(analyzer);
+        switch (scope) {
+            case ALL:
+                if (!Env.getCurrentEnv().getAccessManager()
+                        .checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+                    
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
+                            "CLEAN ALL QUERY STATS");
+                }
+                break;
+            case DB:
+                if (StringUtils.isEmpty(dbName)) {
+                    dbName = analyzer.getDefaultDb();
+                }
+                if (StringUtils.isEmpty(dbName)) {
+                    
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
+                }
+                dbName = 
ClusterNamespace.getFullName(SystemInfoService.DEFAULT_CLUSTER, dbName);
+
+                
Env.getCurrentEnv().getCurrentCatalog().getDbOrAnalysisException(dbName);
+                if (!Env.getCurrentEnv().getAccessManager()
+                        .checkDbPriv(ConnectContext.get(), dbName, 
PrivPredicate.ALTER)) {
+                    
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
+                            "CLEAN DATABASE QUERY STATS FOR " + 
ClusterNamespace.getNameFromFullName(dbName));
+                }
+                break;
+            case TABLE:
+                tableName.analyze(analyzer);
+                dbName = tableName.getDb();
+                if (StringUtils.isEmpty(dbName)) {
+                    
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
+                }
+                DatabaseIf db = 
Env.getCurrentEnv().getCurrentCatalog().getDbOrAnalysisException(dbName);
+                db.getTableOrAnalysisException(tableName.getTbl());
+                if (!Env.getCurrentEnv().getAccessManager()
+                        .checkTblPriv(ConnectContext.get(), dbName, 
tableName.getTbl(), PrivPredicate.ALTER)) {
+                    
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
+                            "CLEAN TABLE QUERY STATS FROM " + tableName);
+                }
+                break;
+            default:
+                throw new IllegalStateException("Unexpected value: " + scope);
+        }
+    }
+
+    @Override
+    public String toSql() {
+        switch (scope) {
+            case ALL:
+                return "CLEAN ALL QUERY STATS";
+            case DB:
+                return "CLEAN DATABASE QUERY STATS FOR " + dbName;
+            case TABLE:
+                return "CLEAN TABLE QUERY STATS FROM " + tableName;
+            default:
+                throw new IllegalStateException("Unexpected value: " + scope);
+        }
+    }
+
+    @Override
+    public RedirectStatus getRedirectStatus() {
+        return RedirectStatus.NO_FORWARD;

Review Comment:
   it may caused the HitCount of every FE to be different?



##########
docs/zh-CN/docs/sql-manual/sql-reference/Utility-Statements/CLEAN-QUERY-STATS.md:
##########
@@ -0,0 +1,75 @@
+---
+{
+    "title": "CLEAN-QUERY-STATS",
+    "language": "zh-CN"
+}
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+## CLEAN-QUERY-STATS
+
+### Name
+
+<version since="dev">
+CLEAN QUERY STATS
+</version>
+
+### Description
+
+该语句用请空查询统计信息
+
+语法:
+
+```sql
+CLEAN [ALL| DATABASE | TABLE] QUERY STATS [[FOR db_name]|[FROM|IN] 
table_name]];
+```
+
+说明:
+
+1. 如果指定 ALL,则清空所有查询统计信息,包括数据库和表的
+2. 如果指定 DATABASE,则清空指定数据库的查询统计信息
+3. 如果指定 TABLE,则清空指定表的查询统计信息
+
+### Example
+
+1. 清空所有统计信息
+
+    ```sql
+    clean all query stats;
+    ```
+
+2. 清指定数据库的统计信息

Review Comment:
   ```suggestion
   2. 清空指定数据库的统计信息
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to