morningman commented on a change in pull request #6420:
URL: https://github.com/apache/incubator-doris/pull/6420#discussion_r687379066



##########
File path: fe/fe-core/src/main/cup/sql_parser.cup
##########
@@ -263,7 +263,7 @@ terminal String KW_ADD, KW_ADMIN, KW_AFTER, KW_AGGREGATE, 
KW_ALIAS, KW_ALL, KW_A
     KW_RIGHT, KW_ROLE, KW_ROLES, KW_ROLLBACK, KW_ROLLUP, KW_ROUTINE, KW_ROW, 
KW_ROWS,
     KW_S3, KW_SCHEMA, KW_SCHEMAS, KW_SECOND, KW_SELECT, KW_SEMI, 
KW_SERIALIZABLE, KW_SESSION, KW_SET, KW_SETS, KW_SET_VAR, KW_SHOW, KW_SIGNED,
     KW_SKEW,
-    KW_SMALLINT, KW_SNAPSHOT, KW_SONAME, KW_SPLIT, KW_START, KW_STATUS, 
KW_STOP, KW_STORAGE, KW_STREAM, KW_STRING, KW_STRUCT,
+    KW_SMALLINT, KW_SNAPSHOT, KW_SONAME, KW_SPLIT, KW_START, KW_STATUS, 
KW_STATS, KW_STOP, KW_STORAGE, KW_STREAM, KW_STRING, KW_STRUCT,

Review comment:
       Add KW_STATS to `keywords`?

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/statistics/OlapTableStats.java
##########
@@ -0,0 +1,46 @@
+// 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.statistics;
+
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+
+/**
+ * There are the statistics of OlapTable.
+ * The @OlapTableStats are mainly used to provide input for the Optimizer's 
cost model.
+ *
+ * There are three kinds of statistics of OlapTable.
+ * @rowCount: The row count of OlapTable. There are two ways to obtain value:
+ *            1. The sum row count of @TabletStats which maybe an inaccurate 
value.
+ *            2. count(*) of OlapTable which is an accurate value.
+ * @dataSize: The data size of OlapTable. This is an inaccurate value,
+ *             which is obtained by summing the @dataSize of @TabletStats.
+ * @idToTabletStats: <@Long tabletId, @TabletStats tabletStats>
+ *     Each tablet in the OlapTable will have corresponding @TabletStats.
+ *     Those @TabletStats are recorded in @idToTabletStats form of MAP.
+ *     This facilitates the optimizer to quickly find the corresponding
+ *     @TabletStats based on the tablet id.
+ *     At the same time, both @rowCount and @dataSize can also be obtained
+ *     from the sum of all @TabletStats.
+ *
+ */
+public class OlapTableStats extends TableStats {
+
+    private Map<Long, TabletStats> idToTabletStats = Maps.newHashMap();

Review comment:
       How about put this to TabletInvertedIndex?

##########
File path: fe/fe-core/src/main/cup/sql_parser.cup
##########
@@ -827,6 +828,20 @@ alter_stmt ::=
     {:
         RESULT = new AlterRoutineLoadStmt(jobLabel, jobProperties, 
datasourceProperties);
     :}
+    | KW_ALTER KW_TABLE table_name:tbl KW_SET KW_STATS LPAREN 
key_value_map:map RPAREN

Review comment:
       Could you please add this new statement in #6277 ?
   I think they should be under `Database Administration Statements`(same as 
MySQL)

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsManager.java
##########
@@ -0,0 +1,70 @@
+// 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.statistics;
+
+import org.apache.doris.analysis.AlterColumnStatsStmt;
+import org.apache.doris.analysis.AlterTableStatsStmt;
+import org.apache.doris.analysis.TableName;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+
+public class StatisticsManager {
+    private Statistics statistics;
+
+    public StatisticsManager() {
+        statistics = new Statistics();
+    }
+
+    public void alterTableStatistics(AlterTableStatsStmt stmt)
+            throws DdlException, AnalysisException {
+        Table table = validateTableName(stmt.getTableName());
+        statistics.updateTableStats(table.getId(), stmt.getProperties());
+    }
+
+    public void alterColumnStatistics(AlterColumnStatsStmt stmt) throws 
DdlException, AnalysisException {
+        Table table = validateTableName(stmt.getTableName());
+        String columnName = stmt.getColumnName();
+        Column column = table.getColumn(columnName);
+        if (column == null) {
+            ErrorReport.reportDdlException(ErrorCode.ERR_BAD_FIELD_ERROR, 
columnName);
+        }
+        // match type and column value
+        statistics.updateColumnStats(table.getId(), columnName, 
column.getType(), stmt.getProperties());

Review comment:
       No need lock?




-- 
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