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

Performance improvement for metadata queries that join against the

COLUMNS metatable
上级 d3bd6b1d
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Performance improvement for metadata queries that join against the COLUMNS metatable
</li>
<li>MVStore: power failure could corrupt the store, if writes were re-ordered.
</li>
<li>For compatibility with other databases, support for (double and float)
......
......@@ -1511,6 +1511,17 @@ public class Database implements DataHandler {
return list;
}
public ArrayList<Table> getTableOrViewByName(String name) {
ArrayList<Table> list = New.arrayList();
for (Schema schema : schemas.values()) {
Table table = schema.getTableOrViewByName(name);
if (table != null) {
list.add(table);
}
}
return list;
}
public ArrayList<Schema> getAllSchemas() {
initMetaTables();
return New.arrayList(schemas.values());
......
......@@ -538,6 +538,13 @@ public class Schema extends DbObjectBase {
}
}
public Table getTableOrViewByName(String name) {
synchronized (database) {
return tablesAndViews.get(name);
}
}
/**
* Remove an object from this schema.
*
......
......@@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import org.h2.command.Command;
import org.h2.constraint.Constraint;
import org.h2.constraint.ConstraintCheck;
......@@ -615,6 +616,16 @@ public class MetaTable extends Table {
return tables;
}
private ArrayList<Table> getTablesByName(Session session, String tableName) {
ArrayList<Table> tables = database.getTableOrViewByName(tableName);
for (Table temp : session.getLocalTempTables()) {
if (temp.getName().equals(tableName)) {
tables.add(temp);
}
}
return tables;
}
private boolean checkIndex(Session session, String value, Value indexFrom,
Value indexTo) {
if (value == null || (indexFrom == null && indexTo == null)) {
......@@ -727,7 +738,15 @@ public class MetaTable extends Table {
break;
}
case COLUMNS: {
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());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论