提交 5c5fde9e authored 作者: Noel Grandin's avatar Noel Grandin

Performance improvement for metadata queries that join against the COLUMNS metadata table.

上级 8273fd69
...@@ -21,6 +21,8 @@ Change Log ...@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Performance improvement for metadata queries that join against the COLUMNS metadata table.
</li>
<li>An ArrayIndexOutOfBoundsException was thrown in some cases <li>An ArrayIndexOutOfBoundsException was thrown in some cases
when opening an old version 1.3 database, or an 1.4 database with when opening an old version 1.3 database, or an 1.4 database with
both "mv_store=false" and the system property "h2.storeLocalTime" set to false. both "mv_store=false" and the system property "h2.storeLocalTime" set to false.
......
...@@ -17,7 +17,6 @@ import java.util.ArrayList; ...@@ -17,7 +17,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import org.h2.command.Command; import org.h2.command.Command;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
import org.h2.constraint.ConstraintCheck; import org.h2.constraint.ConstraintCheck;
...@@ -128,7 +127,7 @@ public class MetaTable extends Table { ...@@ -128,7 +127,7 @@ public class MetaTable extends Table {
this.type = type; this.type = type;
Column[] cols; Column[] cols;
String indexColumnName = null; String indexColumnName = null;
switch (type) { switch(type) {
case TABLES: case TABLES:
setObjectName("TABLES"); setObjectName("TABLES");
cols = createColumns( cols = createColumns(
...@@ -815,7 +814,16 @@ public class MetaTable extends Table { ...@@ -815,7 +814,16 @@ public class MetaTable extends Table {
break; break;
} }
case INDEXES: { case INDEXES: {
for (Table table : getAllTables(session)) { // reduce the number of tables to scan - makes some metadata queries
// 10x faster
final ArrayList<Table> tablesToList;
if (indexFrom != null && indexTo != null && indexFrom.equals(indexTo)) {
String tableName = identifier(indexFrom.getString());
tablesToList = getTablesByName(session, tableName);
} else {
tablesToList = getAllTables(session);
}
for (Table table : tablesToList) {
String tableName = identifier(table.getName()); String tableName = identifier(table.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) { if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue; continue;
...@@ -1854,7 +1862,7 @@ public class MetaTable extends Table { ...@@ -1854,7 +1862,7 @@ public class MetaTable extends Table {
} }
private static int getRefAction(int action) { private static int getRefAction(int action) {
switch (action) { switch(action) {
case ConstraintReferential.CASCADE: case ConstraintReferential.CASCADE:
return DatabaseMetaData.importedKeyCascade; return DatabaseMetaData.importedKeyCascade;
case ConstraintReferential.RESTRICT: case ConstraintReferential.RESTRICT:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论