提交 e653e4e6 authored 作者: Noel Grandin's avatar Noel Grandin

#426: Support ANALYZE TABLE statement

上级 3c94053d
......@@ -415,9 +415,11 @@ ALTER VIEW ADDRESS_VIEW RECOMPILE
"
"Commands (DDL)","ANALYZE","
ANALYZE [ SAMPLE_SIZE rowCountInt ]
ANALYZE [ TABLE tableName ] [ SAMPLE_SIZE rowCountInt ]
","
Updates the selectivity statistics of all tables. The selectivity is used by the
Updates the selectivity statistics of tables.
If no table name is given, all tables are analyzed.
The selectivity is used by the
cost based optimizer to select the best index for a given query. If no sample
size is set, up to 10000 rows per table are read. The value 0 means all rows are
read. The selectivity can be set manually using ALTER TABLE ALTER COLUMN
......
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #426: Support ANALYZE TABLE statement
</li>
<li>Issue #472: Support CREATE SEQUENCE ... ORDER as a NOOP for Oracle compatibility
</li>
</ul>
......
......@@ -550,6 +550,11 @@ public class Parser {
private Prepared parseAnalyze() {
Analyze command = new Analyze(session);
if (readIf("TABLE")) {
Table table = readTableOrView();
command.setTable(table);
command.setTop(readPositiveInt());
}
if (readIf("SAMPLE_SIZE")) {
command.setTop(readPositiveInt());
}
......
......@@ -22,8 +22,8 @@ import org.h2.value.ValueInt;
import org.h2.value.ValueNull;
/**
* This class represents the statement
* ANALYZE
* This class represents the statements
* ANALYZE and ANALYZE TABLE
*/
public class Analyze extends DefineCommand {
......@@ -31,19 +31,31 @@ public class Analyze extends DefineCommand {
* The sample size.
*/
private int sampleRows;
/**
* used in ANALYZE TABLE...
*/
private Table table;
public Analyze(Session session) {
super(session);
sampleRows = session.getDatabase().getSettings().analyzeSample;
}
public void setTable(Table table) {
this.table = table;
}
@Override
public int update() {
session.commit(true);
session.getUser().checkAdmin();
Database db = session.getDatabase();
for (Table table : db.getAllTablesAndViews(false)) {
if (table != null) {
analyzeTable(session, table, sampleRows, true);
} else {
for (Table table : db.getAllTablesAndViews(false)) {
analyzeTable(session, table, sampleRows, true);
}
}
return 0;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论