You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/08/11 03:02:10 UTC

[GitHub] [incubator-doris] EmmyMiao87 opened a new pull request #6420: [WIP] Add statistics struct and Support manually inject statistics

EmmyMiao87 opened a new pull request #6420:
URL: https://github.com/apache/incubator-doris/pull/6420


   ## Proposed changes
   
   This PR mainly developed the data structure used by statistical information
   and the function of manually modifying the statistical information.
   We use a statistics package alone to store statistical information,
   and use the 'statistics manager' as a unified entry for statistical information.
   For detailed data structure and explanation, please refer to the comments on the class.
   
   Manually modify statistics include: Manually modify table statistics and column statistics.
   The syntax is explained in the issue #6370.
   
   ## Types of changes
   
   What types of changes does your code introduce to Doris?
   _Put an `x` in the boxes that apply_
   
   - [ ] Bugfix (non-breaking change which fixes an issue)
   - [x] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [ ] Documentation Update (if none of the other choices apply)
   - [ ] Code refactor (Modify the code structure, format the code, etc...)
   - [ ] Optimization. Including functional usability improvements and performance improvements.
   - [ ] Dependency. Such as changes related to third-party components.
   - [ ] Other.
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [x] I have created an issue on (Fix #ISSUE) and described the bug/feature there in detail
   - [x] Compiling and unit tests pass locally with my changes
   - [ ] I have added tests that prove my fix is effective or that my feature works
   - [ ] If these changes need document changes, I have updated the document
   - [ ] Any dependent changes have been merged
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...
   


-- 
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-unsubscribe@doris.apache.org

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



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


[GitHub] [incubator-doris] EmmyMiao87 commented on a change in pull request #6420: [WIP] Add statistics struct and Support manually inject statistics

Posted by GitBox <gi...@apache.org>.
EmmyMiao87 commented on a change in pull request #6420:
URL: https://github.com/apache/incubator-doris/pull/6420#discussion_r687380762



##########
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:
       All classes in statistical information are currently designed to be completely decoupled from other meta-information.




-- 
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-unsubscribe@doris.apache.org

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



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


[GitHub] [incubator-doris] EmmyMiao87 commented on a change in pull request #6420: [WIP] Add statistics struct and Support manually inject statistics

Posted by GitBox <gi...@apache.org>.
EmmyMiao87 commented on a change in pull request #6420:
URL: https://github.com/apache/incubator-doris/pull/6420#discussion_r687381335



##########
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:
       DONE




-- 
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-unsubscribe@doris.apache.org

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



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


[GitHub] [incubator-doris] github-actions[bot] commented on pull request #6420: Add statistics struct and Support manually inject statistics

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #6420:
URL: https://github.com/apache/incubator-doris/pull/6420#issuecomment-899188834


   PR approved by at least one committer and no changes requested.


-- 
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-unsubscribe@doris.apache.org

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



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


[GitHub] [incubator-doris] morningman commented on a change in pull request #6420: [WIP] Add statistics struct and Support manually inject statistics

Posted by GitBox <gi...@apache.org>.
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-unsubscribe@doris.apache.org

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



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


[GitHub] [incubator-doris] github-actions[bot] commented on pull request #6420: [WIP] Add statistics struct and Support manually inject statistics

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #6420:
URL: https://github.com/apache/incubator-doris/pull/6420#issuecomment-897360342






-- 
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-unsubscribe@doris.apache.org

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



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


[GitHub] [incubator-doris] EmmyMiao87 commented on a change in pull request #6420: [WIP] Add statistics struct and Support manually inject statistics

Posted by GitBox <gi...@apache.org>.
EmmyMiao87 commented on a change in pull request #6420:
URL: https://github.com/apache/incubator-doris/pull/6420#discussion_r687386051



##########
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:
       done

##########
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:
       use concurrent map instead




-- 
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-unsubscribe@doris.apache.org

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



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


[GitHub] [incubator-doris] EmmyMiao87 merged pull request #6420: Add statistics struct and Support manually inject statistics

Posted by GitBox <gi...@apache.org>.
EmmyMiao87 merged pull request #6420:
URL: https://github.com/apache/incubator-doris/pull/6420


   


-- 
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-unsubscribe@doris.apache.org

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



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