@@ -21,7 +21,7 @@ license: |
2121
2222### Description
2323
24- 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.
24+ The ` ANALYZE TABLES ` statement collects statistics about all the tables in a specified database to be used by the query optimizer to find a better query execution plan.
2525
2626### Syntax
2727
@@ -37,7 +37,7 @@ ANALYZE TABLES [ { FROM | IN } database_name ] COMPUTE STATISTICS [ NOSCAN ]
3737
3838* ** [ NOSCAN ] **
3939
40- Collects only the table's size in bytes ( which does not require scanning the entire table ).
40+ Collects only the table's size in bytes (which does not require scanning the entire table).
4141
4242### Examples
4343
@@ -48,100 +48,61 @@ USE school_db;
4848CREATE TABLE teachers (name STRING, teacher_id INT );
4949INSERT INTO teachers VALUES (' Tom' , 1 ), (' Jerry' , 2 );
5050
51- CREATE TABLE students (name STRING, student_id INT );
52- INSERT INTO students VALUES (' Mark' , 111111 ), (' John' , 222222 );
51+ CREATE TABLE students (name STRING, student_id INT , age SHORT );
52+ INSERT INTO students VALUES (' Mark' , 111111 , 10 ), (' John' , 222222 , 11 );
5353
5454ANALYZE TABLES IN school_db COMPUTE STATISTICS NOSCAN;
5555
56- SHOW TABLE EXTENDED IN school_db LIKE ' *' ;
57- + -- ----------+------------+--------------+----------------------------------------------------+
58- | database | tableName | isTemporary | information |
59- + -- ----------+------------+--------------+----------------------------------------------------+
60- |school_db |students |false |Database: school_db
61- Table: students
62- Owner: root
63- Created Time : Wed Dec 09 14 :23 :25 CST 2020
64- Last Access: UNKNOWN
65- Created By: Spark 3 .2 .0 - SNAPSHOT
66- Type: MANAGED
67- Provider: hive
68- Table Properties: [transient_lastDdlTime= 1607495032 ]
69- Statistics: 24 bytes
70- Location: file:/ opt/ spark1/ spark/ spark- warehouse/ school_db .db / students
71- Serde Library: org .apache .hadoop .hive .serde2 .lazy .LazySimpleSerDe
72- InputFormat: org .apache .hadoop .mapred .TextInputFormat
73- OutputFormat: org .apache .hadoop .hive .ql .io .HiveIgnoreKeyTextOutputFormat
74- Storage Properties: [serialization .format = 1 ]
75- Partition Provider: Catalog
76- Schema: root
77- |-- name: string (nullable = true)
78- |-- student_id: integer (nullable = true) |
79- |school_db |teachers |false |Database: school_db
80- Table: teachers
81- Owner: root
82- Created Time : Wed Dec 09 14 :24 :15 CST 2020
83- Last Access: UNKNOWN
84- Created By: Spark 3 .2 .0 - SNAPSHOT
85- Type: MANAGED
86- Provider: hive
87- Table Properties: [transient_lastDdlTime= 1607495059 ]
88- Statistics: 14 bytes
89- Location: file:/ opt/ spark1/ spark/ spark- warehouse/ school_db .db / teachers
90- Serde Library: org .apache .hadoop .hive .serde2 .lazy .LazySimpleSerDe
91- InputFormat: org .apache .hadoop .mapred .TextInputFormat
92- OutputFormat: org .apache .hadoop .hive .ql .io .HiveIgnoreKeyTextOutputFormat
93- Storage Properties: [serialization .format = 1 ]
94- Partition Provider: Catalog
95- Schema: root
96- |-- name: string (nullable = true)
97- |-- teacher_id: integer (nullable = true) |
98- + -- ----------+------------+--------------+----------------------------------------------------+
56+ DESC EXTENDED teachers;
57+ + -- ------------------+--------------------+-------+
58+ | col_name| data_type|comment|
59+ + -- ------------------+--------------------+-------+
60+ | name| string| null |
61+ | teacher_id| int | null |
62+ | ...| ...| ...|
63+ | Provider| parquet| |
64+ | Statistics| 1382 bytes| |
65+ | ...| ...| ...|
66+ + -- ------------------+--------------------+-------+
67+
68+ DESC EXTENDED students;
69+ + -- ------------------+--------------------+-------+
70+ | col_name| data_type|comment|
71+ + -- ------------------+--------------------+-------+
72+ | name| string| null |
73+ | student_id| int | null |
74+ | age| smallint | null |
75+ | ...| ...| ...|
76+ | Statistics| 1828 bytes| |
77+ | ...| ...| ...|
78+ + -- ------------------+--------------------+-------+
9979
10080ANALYZE TABLES COMPUTE STATISTICS;
10181
102- SHOW TABLE EXTENDED IN school_db LIKE ' *' ;
103- + -- ----------+------------+--------------+----------------------------------------------------+
104- | database | tableName | isTemporary | information |
105- + -- ----------+------------+--------------+----------------------------------------------------+
106- |school_db |students |false |Database: school_db
107- Table: students
108- Owner: root
109- Created Time : Wed Dec 09 14 :23 :25 CST 2020
110- Last Access: UNKNOWN
111- Created By: Spark 3 .2 .0 - SNAPSHOT
112- Type: MANAGED
113- Provider: hive
114- Table Properties: [transient_lastDdlTime= 1607495311 ]
115- Statistics: 24 bytes, 2 rows
116- Location: file:/ opt/ spark1/ spark/ spark- warehouse/ school_db .db / students
117- Serde Library: org .apache .hadoop .hive .serde2 .lazy .LazySimpleSerDe
118- InputFormat: org .apache .hadoop .mapred .TextInputFormat
119- OutputFormat: org .apache .hadoop .hive .ql .io .HiveIgnoreKeyTextOutputFormat
120- Storage Properties: [serialization .format = 1 ]
121- Partition Provider: Catalog
122- Schema: root
123- |-- name: string (nullable = true)
124- |-- student_id: integer (nullable = true) |
125- |school_db |teachers |false |Database: school_db
126- Table: teachers
127- Owner: root
128- Created Time : Wed Dec 09 14 :24 :15 CST 2020
129- Last Access: UNKNOWN
130- Created By: Spark 3 .2 .0 - SNAPSHOT
131- Type: MANAGED
132- Provider: hive
133- Table Properties: [transient_lastDdlTime= 1607495312 ]
134- Statistics: 14 bytes, 2 rows
135- Location: file:/ opt/ spark1/ spark/ spark- warehouse/ school_db .db / teachers
136- Serde Library: org .apache .hadoop .hive .serde2 .lazy .LazySimpleSerDe
137- InputFormat: org .apache .hadoop .mapred .TextInputFormat
138- OutputFormat: org .apache .hadoop .hive .ql .io .HiveIgnoreKeyTextOutputFormat
139- Storage Properties: [serialization .format = 1 ]
140- Partition Provider: Catalog
141- Schema: root
142- |-- name: string (nullable = true)
143- |-- teacher_id: integer (nullable = true) |
144- + -- ----------+------------+--------------+----------------------------------------------------+
82+ DESC EXTENDED teachers;
83+ + -- ------------------+--------------------+-------+
84+ | col_name| data_type|comment|
85+ + -- ------------------+--------------------+-------+
86+ | name| string| null |
87+ | teacher_id| int | null |
88+ | ...| ...| ...|
89+ | Provider| parquet| |
90+ | Statistics| 1382 bytes, 2 rows| |
91+ | ...| ...| ...|
92+ + -- ------------------+--------------------+-------+
93+
94+ DESC EXTENDED students;
95+ + -- ------------------+--------------------+-------+
96+ | col_name| data_type|comment|
97+ + -- ------------------+--------------------+-------+
98+ | name| string| null |
99+ | student_id| int | null |
100+ | age| smallint | null |
101+ | ...| ...| ...|
102+ | Provider| parquet| |
103+ | Statistics| 1828 bytes, 2 rows| |
104+ | ...| ...| ...|
105+ + -- ------------------+--------------------+-------+
145106```
146107
147108### Related Statements
0 commit comments