maropu commented on a change in pull request #30648: URL: https://github.com/apache/spark/pull/30648#discussion_r539073924
########## File path: docs/sql-ref-syntax-aux-analyze-tables.md ########## @@ -0,0 +1,90 @@ +--- +layout: global +title: ANALYZE TABLES +displayTitle: ANALYZE TABLES +license: | + 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. +--- + +### Description + +The `ANALYZE TABLES` statement collects statistics about all the tables in a database to be used by the query optimizer to find a better query execution plan. + +### Syntax + +```sql +ANALYZE TABLES [ { FROM | IN } database_name ] COMPUTE STATISTICS [ NOSCAN ] +``` + +### Parameters + +* **{ FROM `|` IN } database_name** + + Specifies the name of the database to be analyzed. Without a database name, `ANALYZE` collects all tables in the current database that the current user has permission to analyze. + +* **[ NOSCAN ]** + + Collects only the table's size in bytes ( which does not require scanning the entire table ). + +### Examples + +```sql +CREATE DATABASE school_db; +USE school_db; + +CREATE TABLE teachers (name STRING, teacher_id INT); +INSERT INTO teachers VALUES ('Tom', 1), ('Jerry', 2); + +CREATE TABLE students (name STRING, student_id INT); +INSERT INTO students VALUES ('Mark', 111111), ('John', 222222); + +ANALYZE TABLES IN school_db COMPUTE STATISTICS NOSCAN; + +SHOW TABLE EXTENDED IN school_db LIKE '*'; ++------------+------------+--------------+----------------------------------------------------+ +| database | tableName | isTemporary | information | ++------------+------------+--------------+----------------------------------------------------+ +| school_db | students | false | Database: school_db +Table: students +... +Statistics: 24 bytes +... + +| school_db | teachers | false | Database: school_db +Table: teachers +... +Statistics: 14 bytes +... ++------------+------------+--------------+----------------------------------------------------+ + +ANALYZE TABLES COMPUTE STATISTICS; + +SHOW TABLE EXTENDED IN school_db LIKE '*'; ++------------+------------+--------------+----------------------------------------------------+ +| database | tableName | isTemporary | information | ++------------+------------+--------------+----------------------------------------------------+ +| school_db | students | false | Database: school_db +Table: students +... +Statistics: 24 bytes, 2 rows +... +| school_db | teachers | false | Database: school_db +Table: teachers +... +Statistics: 14 bytes, 2 rows +... ++------------+------------+--------------+----------------------------------------------------+ +``` Review comment: Could you add a link to the `ANALYZE TABLE` page in the `Related Statements` section? Also, I think its better to add a link to this doc page in the `ANALYZE TABLE` page, too. ########## File path: docs/sql-ref-syntax-aux-analyze-tables.md ########## @@ -0,0 +1,90 @@ +--- +layout: global +title: ANALYZE TABLES +displayTitle: ANALYZE TABLES +license: | + 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. +--- + +### Description + +The `ANALYZE TABLES` statement collects statistics about all the tables in a database to be used by the query optimizer to find a better query execution plan. Review comment: cc: @huaxingao ########## File path: docs/sql-ref-syntax-aux-analyze-tables.md ########## @@ -0,0 +1,90 @@ +--- +layout: global +title: ANALYZE TABLES +displayTitle: ANALYZE TABLES +license: | + 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. +--- + +### Description + +The `ANALYZE TABLES` statement collects statistics about all the tables in a database to be used by the query optimizer to find a better query execution plan. + +### Syntax + +```sql +ANALYZE TABLES [ { FROM | IN } database_name ] COMPUTE STATISTICS [ NOSCAN ] +``` + +### Parameters + +* **{ FROM `|` IN } database_name** + + Specifies the name of the database to be analyzed. Without a database name, `ANALYZE` collects all tables in the current database that the current user has permission to analyze. + +* **[ NOSCAN ]** + + Collects only the table's size in bytes ( which does not require scanning the entire table ). + +### Examples + +```sql +CREATE DATABASE school_db; +USE school_db; + +CREATE TABLE teachers (name STRING, teacher_id INT); +INSERT INTO teachers VALUES ('Tom', 1), ('Jerry', 2); + +CREATE TABLE students (name STRING, student_id INT); +INSERT INTO students VALUES ('Mark', 111111), ('John', 222222); + +ANALYZE TABLES IN school_db COMPUTE STATISTICS NOSCAN; + +SHOW TABLE EXTENDED IN school_db LIKE '*'; ++------------+------------+--------------+----------------------------------------------------+ +| database | tableName | isTemporary | information | ++------------+------------+--------------+----------------------------------------------------+ +| school_db | students | false | Database: school_db +Table: students Review comment: Formatting this like the `SHOW TABLE EXTENDED` page looks better: https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-table.html#examples ########## File path: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ########## @@ -134,6 +134,8 @@ statement (AS? query)? #replaceTable | ANALYZE TABLE multipartIdentifier partitionSpec? COMPUTE STATISTICS (identifier | FOR COLUMNS identifierSeq | FOR ALL COLUMNS)? #analyze + | ANALYZE TABLES ((FROM | IN) multipartIdentifier)? COMPUTE STATISTICS + (identifier)? #analyzeTables Review comment: sgtm ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
