Skip to content

Commit 56f2887

Browse files
huaxingaogatorsmile
authored andcommitted
[SPARK-28788][DOC][SQL] Document ANALYZE TABLE statement in SQL Reference
### What changes were proposed in this pull request? Document ANALYZE TABLE statement in SQL Reference ### Why are the changes needed? To complete SQL reference ### Does this PR introduce any user-facing change? Yes ***Before***: There was no documentation for this. ***After***: ![image](https://user-images.githubusercontent.com/13592258/64046883-f8339480-cb21-11e9-85da-6617d5c96412.png) ![image](https://user-images.githubusercontent.com/13592258/64209526-9a6eb780-ce55-11e9-9004-53c5c5d24567.png) ![image](https://user-images.githubusercontent.com/13592258/64209542-a2c6f280-ce55-11e9-8624-e7349204ec8e.png) ### How was this patch tested? Tested using jykyll build --serve Closes #25524 from huaxingao/spark-28788. Authored-by: Huaxin Gao <huaxing@us.ibm.com> Signed-off-by: Xiao Li <gatorsmile@gmail.com>
1 parent 8980093 commit 56f2887

2 files changed

Lines changed: 80 additions & 9 deletions

File tree

docs/sql-ref-syntax-aux-analyze-table.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,78 @@ license: |
1919
limitations under the License.
2020
---
2121

22-
**This page is under construction**
22+
### Description
23+
24+
The `ANALYZE TABLE` statement collects statistics about the table to be used by the query optimizer to find a better query execution plan.
25+
26+
### Syntax
27+
{% highlight sql %}
28+
ANALYZE TABLE table_name [ PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] ) ]
29+
COMPUTE STATISTICS [ NOSCAN | FOR COLUMNS col [ , ... ] | FOR ALL COLUMNS ]
30+
31+
{% endhighlight %}
32+
33+
### Parameters
34+
<dl>
35+
<dt><code><em>table_name</em></code></dt>
36+
<dd>The name of an existing table.</dd>
37+
</dl>
38+
39+
<dl>
40+
<dt><code><em>PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] )</em></code></dt>
41+
<dd>Specifies one or more partition column and value pairs. The partition value is optional.</dd>
42+
</dl>
43+
44+
<dl>
45+
<dt><code><em>[ NOSCAN | FOR COLUMNS col [ , ... ] | FOR ALL COLUMNS ]</em></code></dt>
46+
<dd>
47+
<ul>
48+
<li> If no analyze option is specified, <code>ANALYZE TABLE</code> collects the table's number of rows and size in bytes. </li>
49+
<li> <b>NOSCAN</b>
50+
<br> Collect only the table's size in bytes ( which does not require scanning the entire table ). </li>
51+
<li> <b>FOR COLUMNS col [ , ... ] <code> | </code> FOR ALL COLUMNS</b>
52+
<br> Collect column statistics for each column specified, or alternatively for every column, as well as table statistics.
53+
</li>
54+
</ul>
55+
</dd>
56+
</dl>
57+
58+
### Examples
59+
{% highlight sql %}
60+
ANALYZE TABLE students COMPUTE STATISTICS NOSCAN;
61+
62+
DESC EXTENDED students;
63+
......
64+
Statistics 2820 bytes
65+
......
66+
67+
ANALYZE TABLE students COMPUTE STATISTICS;
68+
69+
DESC EXTENDED students;
70+
......
71+
Statistics 2820 bytes, 3 rows
72+
......
73+
74+
ANALYZE TABLE students PARTITION (student_id = 111111) COMPUTE STATISTICS;
75+
76+
DESC EXTENDED students PARTITION (student_id = 111111);
77+
......
78+
Partition Statistics 919 bytes, 1 rows
79+
......
80+
81+
ANALYZE TABLE students COMPUTE STATISTICS FOR COLUMNS name;
82+
83+
DESC EXTENDED students name;
84+
=default tbl=students
85+
col_name name
86+
data_type string
87+
comment NULL
88+
min NULL
89+
max NULL
90+
num_nulls 0
91+
distinct_count 3
92+
avg_col_len 11
93+
max_col_len 13
94+
histogram NULL
95+
96+
{% endhighlight %}

docs/sql-ref-syntax-aux-analyze.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
---
22
layout: global
3-
title: Reference
4-
displayTitle: Reference
3+
title: ANALYZE
4+
displayTitle: ANALYZE
55
license: |
66
Licensed to the Apache Software Foundation (ASF) under one or more
77
contributor license agreements. See the NOTICE file distributed with
88
this work for additional information regarding copyright ownership.
99
The ASF licenses this file to You under the Apache License, Version 2.0
1010
(the "License"); you may not use this file except in compliance with
1111
the License. You may obtain a copy of the License at
12-
12+
1313
http://www.apache.org/licenses/LICENSE-2.0
14-
14+
1515
Unless required by applicable law or agreed to in writing, software
1616
distributed under the License is distributed on an "AS IS" BASIS,
1717
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1818
See the License for the specific language governing permissions and
1919
limitations under the License.
2020
---
2121

22-
Spark SQL is a Apache Spark's module for working with structured data.
23-
This guide is a reference for Structured Query Language (SQL) for Apache
24-
Spark. This document describes the SQL constructs supported by Spark in detail
25-
along with usage examples when applicable.
22+
* [ANALYZE TABLE statement](sql-ref-syntax-aux-analyze-table.html)

0 commit comments

Comments
 (0)