Issue #3909: Maintenance taking too much resources since 2.2.222
diff --git a/h2/src/main/org/h2/command/Parser.java b/h2/src/main/org/h2/command/Parser.java
index b899a85325..b53b6c5ae0 100644
--- a/h2/src/main/org/h2/command/Parser.java
+++ b/h2/src/main/org/h2/command/Parser.java
@@ -7123,7 +7123,6 @@ private TableView createCTEView(String cteViewName, String querySQL, ArrayList tableEngineParams) {
data.tableEngineParams = tableEngineParams;
}
- public void setHidden(boolean isHidden) {
- data.isHidden = isHidden;
- }
-
@Override
public int getType() {
return CommandInterface.CREATE_TABLE;
diff --git a/h2/src/main/org/h2/command/ddl/CreateTableData.java b/h2/src/main/org/h2/command/ddl/CreateTableData.java
index f8039cc45f..ebf18f7dbf 100644
--- a/h2/src/main/org/h2/command/ddl/CreateTableData.java
+++ b/h2/src/main/org/h2/command/ddl/CreateTableData.java
@@ -71,8 +71,4 @@ public class CreateTableData {
*/
public ArrayList tableEngineParams;
- /**
- * The table is hidden.
- */
- public boolean isHidden;
}
diff --git a/h2/src/main/org/h2/command/ddl/DropDatabase.java b/h2/src/main/org/h2/command/ddl/DropDatabase.java
index 8321ac6631..915c9cf993 100644
--- a/h2/src/main/org/h2/command/ddl/DropDatabase.java
+++ b/h2/src/main/org/h2/command/ddl/DropDatabase.java
@@ -73,15 +73,13 @@ private void dropAllObjects() {
}
for (Table t : tables) {
if (t.getName() != null &&
- TableType.TABLE == t.getTableType() &&
- !t.isHidden()) {
+ TableType.TABLE == t.getTableType()) {
toRemove.add(t);
}
}
for (Table t : tables) {
if (t.getName() != null &&
- TableType.EXTERNAL_TABLE_ENGINE == t.getTableType() &&
- !t.isHidden()) {
+ TableType.EXTERNAL_TABLE_ENGINE == t.getTableType()) {
toRemove.add(t);
}
}
@@ -124,7 +122,7 @@ private void dropAllObjects() {
addAll(schemas, DbObject.FUNCTION_ALIAS, list);
addAll(schemas, DbObject.DOMAIN, list);
for (SchemaObject obj : list) {
- if (!obj.getSchema().isValid() || obj.isHidden()) {
+ if (!obj.getSchema().isValid()) {
continue;
}
db.removeSchemaObject(session, obj);
diff --git a/h2/src/main/org/h2/command/dml/ScriptCommand.java b/h2/src/main/org/h2/command/dml/ScriptCommand.java
index a4ab0303b6..486b6a3708 100644
--- a/h2/src/main/org/h2/command/dml/ScriptCommand.java
+++ b/h2/src/main/org/h2/command/dml/ScriptCommand.java
@@ -339,11 +339,7 @@ public ResultInterface query(long maxrows) {
if (excludeTable(constraint.getTable())) {
continue;
}
- Type constraintType = constraint.getConstraintType();
- if (constraintType != Type.DOMAIN && constraint.getTable().isHidden()) {
- continue;
- }
- if (constraintType != Constraint.Type.PRIMARY_KEY) {
+ if (constraint.getConstraintType() != Constraint.Type.PRIMARY_KEY) {
constraints.add(constraint);
}
}
diff --git a/h2/src/main/org/h2/constraint/Constraint.java b/h2/src/main/org/h2/constraint/Constraint.java
index b751da1bae..655c39ee2c 100644
--- a/h2/src/main/org/h2/constraint/Constraint.java
+++ b/h2/src/main/org/h2/constraint/Constraint.java
@@ -51,15 +51,35 @@ public enum Type {
* @return standard SQL type name
*/
public String getSqlName() {
- if (this == Constraint.Type.PRIMARY_KEY) {
+ if (this == PRIMARY_KEY) {
return "PRIMARY KEY";
}
- if (this == Constraint.Type.REFERENTIAL) {
+ if (this == REFERENTIAL) {
return "FOREIGN KEY";
}
return name();
}
+ /**
+ * Tests whether this type is a check or domain type or not.
+ *
+ * @return {@code true} if this type is a check or a domain type,
+ * {@code false} otherwise
+ */
+ public boolean isCheck() {
+ return this == CHECK || this == DOMAIN;
+ }
+
+ /**
+ * Tests whether this type is a primary key or unique or not.
+ *
+ * @return {@code true} if this type is a primary key or unique type,
+ * {@code false} otherwise
+ */
+ public boolean isUnique() {
+ return this == PRIMARY_KEY || this == UNIQUE;
+ }
+
}
/**
@@ -193,11 +213,6 @@ public int compareTo(Constraint other) {
return Integer.compare(getConstraintType().ordinal(), other.getConstraintType().ordinal());
}
- @Override
- public boolean isHidden() {
- return table != null && table.isHidden();
- }
-
/**
* Visit all elements in the constraint.
*
diff --git a/h2/src/main/org/h2/constraint/ConstraintCheck.java b/h2/src/main/org/h2/constraint/ConstraintCheck.java
index edac942e15..3fd658f444 100644
--- a/h2/src/main/org/h2/constraint/ConstraintCheck.java
+++ b/h2/src/main/org/h2/constraint/ConstraintCheck.java
@@ -50,9 +50,6 @@ public void setExpression(Expression expr) {
public String getCreateSQLForCopy(Table forTable, String quotedName) {
StringBuilder buff = new StringBuilder("ALTER TABLE ");
forTable.getSQL(buff, DEFAULT_SQL_FLAGS).append(" ADD CONSTRAINT ");
- if (forTable.isHidden()) {
- buff.append("IF NOT EXISTS ");
- }
buff.append(quotedName);
if (comment != null) {
buff.append(" COMMENT ");
diff --git a/h2/src/main/org/h2/constraint/ConstraintReferential.java b/h2/src/main/org/h2/constraint/ConstraintReferential.java
index 4bcba9c9f7..5e6bf0b208 100644
--- a/h2/src/main/org/h2/constraint/ConstraintReferential.java
+++ b/h2/src/main/org/h2/constraint/ConstraintReferential.java
@@ -78,9 +78,6 @@ public String getCreateSQLForCopy(Table forTable, Table forRefTable,
String quotedName, boolean internalIndex) {
StringBuilder builder = new StringBuilder("ALTER TABLE ");
forTable.getSQL(builder, DEFAULT_SQL_FLAGS).append(" ADD CONSTRAINT ");
- if (forTable.isHidden()) {
- builder.append("IF NOT EXISTS ");
- }
builder.append(quotedName);
if (comment != null) {
builder.append(" COMMENT ");
diff --git a/h2/src/main/org/h2/constraint/ConstraintUnique.java b/h2/src/main/org/h2/constraint/ConstraintUnique.java
index fbb51998b5..e7f2bc2da9 100644
--- a/h2/src/main/org/h2/constraint/ConstraintUnique.java
+++ b/h2/src/main/org/h2/constraint/ConstraintUnique.java
@@ -48,9 +48,6 @@ public String getCreateSQLForCopy(Table forTable, String quotedName) {
private String getCreateSQLForCopy(Table forTable, String quotedName, boolean internalIndex) {
StringBuilder builder = new StringBuilder("ALTER TABLE ");
forTable.getSQL(builder, DEFAULT_SQL_FLAGS).append(" ADD CONSTRAINT ");
- if (forTable.isHidden()) {
- builder.append("IF NOT EXISTS ");
- }
builder.append(quotedName);
if (comment != null) {
builder.append(" COMMENT ");
diff --git a/h2/src/main/org/h2/engine/Database.java b/h2/src/main/org/h2/engine/Database.java
index 70359e9c05..fbfb40a63b 100644
--- a/h2/src/main/org/h2/engine/Database.java
+++ b/h2/src/main/org/h2/engine/Database.java
@@ -571,7 +571,6 @@ private CreateTableData createSysTableData() {
data.temporary = false;
data.persistData = persistent;
data.persistIndexes = persistent;
- data.isHidden = true;
data.session = systemSession;
return data;
}
diff --git a/h2/src/main/org/h2/index/Index.java b/h2/src/main/org/h2/index/Index.java
index cfd2477b21..a348ec2791 100644
--- a/h2/src/main/org/h2/index/Index.java
+++ b/h2/src/main/org/h2/index/Index.java
@@ -143,19 +143,11 @@ public void removeChildrenAndResources(SessionLocal session) {
database.removeMeta(session, getId());
}
- @Override
- public final boolean isHidden() {
- return table.isHidden();
- }
-
@Override
public String getCreateSQLForCopy(Table targetTable, String quotedName) {
StringBuilder builder = new StringBuilder("CREATE ");
builder.append(indexType.getSQL(true));
builder.append(' ');
- if (table.isHidden()) {
- builder.append("IF NOT EXISTS ");
- }
builder.append(quotedName);
builder.append(" ON ");
targetTable.getSQL(builder, DEFAULT_SQL_FLAGS);
diff --git a/h2/src/main/org/h2/jdbc/meta/DatabaseMetaLocal.java b/h2/src/main/org/h2/jdbc/meta/DatabaseMetaLocal.java
index e5abc5ad57..aa66909038 100644
--- a/h2/src/main/org/h2/jdbc/meta/DatabaseMetaLocal.java
+++ b/h2/src/main/org/h2/jdbc/meta/DatabaseMetaLocal.java
@@ -667,9 +667,6 @@ public ResultInterface getColumnPrivileges(String catalog, String schema, String
continue;
}
Table t = (Table) object;
- if (t.isHidden()) {
- continue;
- }
String tableName = t.getName();
if (!db.equalsIdentifiers(table, tableName)) {
continue;
@@ -710,9 +707,6 @@ public ResultInterface getTablePrivileges(String catalog, String schemaPattern,
continue;
}
Table table = (Table) object;
- if (table.isHidden()) {
- continue;
- }
String tableName = table.getName();
if (tableLike != null && !tableLike.test(tableName)) {
continue;
@@ -827,7 +821,7 @@ public ResultInterface getBestRowIdentifier(String catalog, String schema, Strin
}
for (Schema s : getSchemas(schema)) {
Table t = s.findTableOrView(session, table);
- if (t == null || t.isHidden()) {
+ if (t == null) {
continue;
}
ArrayList constraints = t.getConstraints();
@@ -893,7 +887,7 @@ public ResultInterface getPrimaryKeys(String catalog, String schema, String tabl
Value catalogValue = getString(db.getShortName());
for (Schema s : getSchemas(schema)) {
Table t = s.findTableOrView(session, table);
- if (t == null || t.isHidden()) {
+ if (t == null) {
continue;
}
ArrayList constraints = t.getConstraints();
@@ -943,7 +937,7 @@ public ResultInterface getImportedKeys(String catalog, String schema, String tab
Value catalogValue = getString(db.getShortName());
for (Schema s : getSchemas(schema)) {
Table t = s.findTableOrView(session, table);
- if (t == null || t.isHidden()) {
+ if (t == null) {
continue;
}
ArrayList constraints = t.getConstraints();
@@ -982,7 +976,7 @@ public ResultInterface getExportedKeys(String catalog, String schema, String tab
Value catalogValue = getString(db.getShortName());
for (Schema s : getSchemas(schema)) {
Table t = s.findTableOrView(session, table);
- if (t == null || t.isHidden()) {
+ if (t == null) {
continue;
}
ArrayList constraints = t.getConstraints();
@@ -1025,7 +1019,7 @@ public ResultInterface getCrossReference(String primaryCatalog, String primarySc
Value catalogValue = getString(db.getShortName());
for (Schema s : getSchemas(foreignSchema)) {
Table t = s.findTableOrView(session, foreignTable);
- if (t == null || t.isHidden()) {
+ if (t == null) {
continue;
}
ArrayList constraints = t.getConstraints();
@@ -1242,7 +1236,7 @@ public ResultInterface getIndexInfo(String catalog, String schema, String table,
Value catalogValue = getString(db.getShortName());
for (Schema s : getSchemas(schema)) {
Table t = s.findTableOrView(session, table);
- if (t == null || t.isHidden()) {
+ if (t == null) {
continue;
}
getIndexInfo(catalogValue, getString(s.getName()), t, unique, approximate, result, db);
diff --git a/h2/src/main/org/h2/mode/FunctionsPostgreSQL.java b/h2/src/main/org/h2/mode/FunctionsPostgreSQL.java
index c939c2e8fc..f6684ca6b0 100644
--- a/h2/src/main/org/h2/mode/FunctionsPostgreSQL.java
+++ b/h2/src/main/org/h2/mode/FunctionsPostgreSQL.java
@@ -328,15 +328,13 @@ private static Value getIndexdef(SessionLocal session, int indexId, Value ordina
for (Schema schema : session.getDatabase().getAllSchemasNoMeta()) {
for (Index index : schema.getAllIndexes()) {
if (index.getId() == indexId) {
- if (!index.getTable().isHidden()) {
- int ordinal;
- if (ordinalPosition == null || (ordinal = ordinalPosition.getInt()) == 0) {
- return ValueVarchar.get(index.getCreateSQL());
- }
- Column[] columns;
- if (ordinal >= 1 && ordinal <= (columns = index.getColumns()).length) {
- return ValueVarchar.get(columns[ordinal - 1].getName());
- }
+ int ordinal;
+ if (ordinalPosition == null || (ordinal = ordinalPosition.getInt()) == 0) {
+ return ValueVarchar.get(index.getCreateSQL());
+ }
+ Column[] columns;
+ if (ordinal >= 1 && ordinal <= (columns = index.getColumns()).length) {
+ return ValueVarchar.get(columns[ordinal - 1].getName());
}
break;
}
diff --git a/h2/src/main/org/h2/mode/PgCatalogTable.java b/h2/src/main/org/h2/mode/PgCatalogTable.java
index 26179e7dce..4be1d7c8f1 100644
--- a/h2/src/main/org/h2/mode/PgCatalogTable.java
+++ b/h2/src/main/org/h2/mode/PgCatalogTable.java
@@ -7,7 +7,6 @@
import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import org.h2.constraint.Constraint;
import org.h2.engine.Constants;
@@ -84,15 +83,15 @@ public final class PgCatalogTable extends MetaTable {
*/
public static final int META_TABLE_TYPE_COUNT = PG_USER + 1;
- private static final Object[][] PG_EXTRA_TYPES = {
- { 18, "char", 1, 0 },
- { 19, "name", 64, 18 },
- { 22, "int2vector", -1, 21 },
- { 24, "regproc", 4, 0 },
+ private static final Object[][] PG_EXTRA_TYPES = { //
+ { 18, "char", 1, 0 }, //
+ { 19, "name", 64, 18 }, //
+ { 22, "int2vector", -1, 21 }, //
+ { 24, "regproc", 4, 0 }, //
{ PgServer.PG_TYPE_INT2_ARRAY, "_int2", -1, PgServer.PG_TYPE_INT2 },
{ PgServer.PG_TYPE_INT4_ARRAY, "_int4", -1, PgServer.PG_TYPE_INT4 },
- { PgServer.PG_TYPE_VARCHAR_ARRAY, "_varchar", -1, PgServer.PG_TYPE_VARCHAR },
- { 2205, "regclass", 4, 0 },
+ { PgServer.PG_TYPE_VARCHAR_ARRAY, "_varchar", -1, PgServer.PG_TYPE_VARCHAR }, //
+ { 2205, "regclass", 4, 0 }, //
};
/**
@@ -352,34 +351,12 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
case PG_ATTRDEF:
break;
case PG_ATTRIBUTE:
- for (Schema schema : database.getAllSchemas()) {
- for (Table table : schema.getAllTablesAndViews(session)) {
- if (!hideTable(table, session)) {
- pgAttribute(session, rows, table);
- }
- }
- }
- for (Table table: session.getLocalTempTables()) {
- if (!hideTable(table, session)) {
- pgAttribute(session, rows, table);
- }
- }
+ getAllTables(session, null, null).forEach(table -> pgAttribute(session, rows, table));
break;
case PG_AUTHID:
break;
case PG_CLASS:
- for (Schema schema : database.getAllSchemas()) {
- for (Table table : schema.getAllTablesAndViews(session)) {
- if (!hideTable(table, session)) {
- pgClass(session, rows, table);
- }
- }
- }
- for (Table table: session.getLocalTempTables()) {
- if (!hideTable(table, session)) {
- pgClass(session, rows, table);
- }
- }
+ getAllTables(session, null, null).forEach(table -> pgClass(session, rows, table));
break;
case PG_CONSTRAINT:
pgConstraint(session, rows);
@@ -605,54 +582,43 @@ private void pgAttribute(SessionLocal session, ArrayList rows, Table table)
private void pgClass(SessionLocal session, ArrayList rows, Table table) {
ArrayList triggers = table.getTriggers();
- addClass(session, rows, table.getId(), table.getName(), table.getSchema().getId(),
- table.isView() ? "v" : "r", false, triggers != null ? triggers.size() : 0);
+ addClass(session, rows, table.getId(), table.getName(), table.getSchema().getId(), table.isView() ? "v" : "r",
+ false, triggers != null ? triggers.size() : 0);
ArrayList indexes = table.getIndexes();
if (indexes != null) {
for (Index index : indexes) {
if (index.getCreateSQL() == null) {
continue;
}
- addClass(session, rows, index.getId(), index.getName(), index.getSchema().getId(), "i", true,
- 0);
+ addClass(session, rows, index.getId(), index.getName(), index.getSchema().getId(), "i", true, 0);
}
}
}
private void pgConstraint(SessionLocal session, ArrayList rows) {
- for (Schema schema : database.getAllSchemasNoMeta()) {
- for (Constraint constraint : schema.getAllConstraints()) {
- Constraint.Type constraintType = constraint.getConstraintType();
- if (constraintType == Constraint.Type.DOMAIN) {
- continue;
- }
- Table table = constraint.getTable();
- if (hideTable(table, session)) {
- continue;
- }
- List conkey = new ArrayList<>();
- for (Column column : constraint.getReferencedColumns(table)) {
- conkey.add(ValueSmallint.get((short) (column.getColumnId() + 1)));
- }
- Table refTable = constraint.getRefTable();
- add(session,
- rows,
- // OID
- ValueInteger.get(constraint.getId()),
- // CONNAME
- constraint.getName(),
- // CONTYPE
- StringUtils.toLowerEnglish(constraintType.getSqlName().substring(0, 1)),
- // CONRELID
- ValueInteger.get(table.getId()),
- // CONFRELID
- ValueInteger.get(refTable != null && refTable != table
- && !hideTable(refTable, session) ? table.getId() : 0),
- // CONKEY
- ValueArray.get(TypeInfo.TYPE_SMALLINT, conkey.toArray(Value.EMPTY_VALUES), null)
- );
- }
- }
+ getAllConstraints(session).filter(constraint -> constraint.getConstraintType() != Constraint.Type.DOMAIN)
+ .forEach(constraint -> {
+ Constraint.Type constraintType = constraint.getConstraintType();
+ Table table = constraint.getTable();
+ ArrayList conkey = new ArrayList<>();
+ for (Column column : constraint.getReferencedColumns(table)) {
+ conkey.add(ValueSmallint.get((short) (column.getColumnId() + 1)));
+ }
+ Table refTable = constraint.getRefTable();
+ add(session, rows,
+ // OID
+ ValueInteger.get(constraint.getId()),
+ // CONNAME
+ constraint.getName(),
+ // CONTYPE
+ StringUtils.toLowerEnglish(constraintType.getSqlName().substring(0, 1)),
+ // CONRELID
+ ValueInteger.get(table.getId()),
+ // CONFRELID
+ ValueInteger.get(refTable != null && refTable != table ? table.getId() : 0),
+ // CONKEY
+ ValueArray.get(TypeInfo.TYPE_SMALLINT, conkey.toArray(Value.EMPTY_VALUES), null));
+ });
}
private void addAttribute(SessionLocal session, ArrayList rows, int id, int relId, Column column,
diff --git a/h2/src/main/org/h2/mvstore/db/MVTable.java b/h2/src/main/org/h2/mvstore/db/MVTable.java
index ffb22aa0d9..8bddafa810 100644
--- a/h2/src/main/org/h2/mvstore/db/MVTable.java
+++ b/h2/src/main/org/h2/mvstore/db/MVTable.java
@@ -137,7 +137,6 @@ public String getEventText() {
public MVTable(CreateTableData data, Store store) {
super(data);
- this.isHidden = data.isHidden;
boolean b = false;
for (Column col : getColumns()) {
if (DataType.isLargeObject(col.getType().getValueType())) {
@@ -367,7 +366,7 @@ public Index addIndex(SessionLocal session, String indexName, int indexId, Index
rebuildIndex(session, index, indexName);
}
index.setTemporary(isTemporary());
- if (index.getCreateSQL() != null) {
+ if (getId() != 0 && index.getCreateSQL() != null) {
index.setComment(indexComment);
if (isSessionTemporary) {
session.addLocalTempTableIndex(index);
diff --git a/h2/src/main/org/h2/schema/SchemaObject.java b/h2/src/main/org/h2/schema/SchemaObject.java
index 86088a6bfb..80dc661632 100644
--- a/h2/src/main/org/h2/schema/SchemaObject.java
+++ b/h2/src/main/org/h2/schema/SchemaObject.java
@@ -47,14 +47,4 @@ public StringBuilder getSQL(StringBuilder builder, int sqlFlags) {
return super.getSQL(builder, sqlFlags);
}
- /**
- * Check whether this is a hidden object that doesn't appear in the meta
- * data and in the script, and is not dropped on DROP ALL OBJECTS.
- *
- * @return true if it is hidden
- */
- public boolean isHidden() {
- return false;
- }
-
}
diff --git a/h2/src/main/org/h2/table/InformationSchemaTable.java b/h2/src/main/org/h2/table/InformationSchemaTable.java
index 1c03a9c418..5d0e41d7b1 100644
--- a/h2/src/main/org/h2/table/InformationSchemaTable.java
+++ b/h2/src/main/org/h2/table/InformationSchemaTable.java
@@ -17,7 +17,6 @@
import org.h2.command.ParserBase;
import org.h2.constraint.Constraint;
import org.h2.constraint.Constraint.Type;
-import org.h2.constraint.ConstraintCheck;
import org.h2.constraint.ConstraintDomain;
import org.h2.constraint.ConstraintReferential;
import org.h2.constraint.ConstraintUnique;
@@ -1006,36 +1005,20 @@ private void informationSchemaCatalogName(SessionLocal session, ArrayList r
private void checkConstraints(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows,
String catalog) {
- for (Schema schema : database.getAllSchemas()) {
- for (Constraint constraint : schema.getAllConstraints()) {
- Type constraintType = constraint.getConstraintType();
- if (constraintType == Constraint.Type.CHECK) {
- ConstraintCheck check = (ConstraintCheck) constraint;
- Table table = check.getTable();
- if (hideTable(table, session)) {
- continue;
- }
- } else if (constraintType != Constraint.Type.DOMAIN) {
- continue;
- }
- String constraintName = constraint.getName();
- if (!checkIndex(session, constraintName, indexFrom, indexTo)) {
- continue;
- }
- checkConstraints(session, rows, catalog, constraint, constraintName);
- }
- }
+ getAllConstraints(session)
+ .filter(constraint -> constraint.getConstraintType().isCheck()
+ && checkIndex(session, constraint.getName(), indexFrom, indexTo))
+ .forEach(constraint -> checkConstraints(session, rows, catalog, constraint));
}
- private void checkConstraints(SessionLocal session, ArrayList rows, String catalog, Constraint constraint,
- String constraintName) {
+ private void checkConstraints(SessionLocal session, ArrayList rows, String catalog, Constraint constraint) {
add(session, rows,
// CONSTRAINT_CATALOG
catalog,
// CONSTRAINT_SCHEMA
constraint.getSchema().getName(),
// CONSTRAINT_NAME
- constraintName,
+ constraint.getName(),
// CHECK_CLAUSE
constraint.getExpression().getSQL(DEFAULT_SQL_FLAGS, Expression.WITHOUT_PARENTHESES)
);
@@ -1072,52 +1055,20 @@ private void collations(SessionLocal session, ArrayList rows, String catalo
private void columns(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows, String catalog) {
String mainSchemaName = database.getMainSchema().getName();
String collation = database.getCompareMode().getName();
- if (indexFrom != null && indexFrom.equals(indexTo)) {
- String tableName = indexFrom.getString();
- if (tableName == null) {
- return;
- }
- for (Schema schema : database.getAllSchemas()) {
- Table table = schema.getTableOrViewByName(session, tableName);
- if (table != null) {
- columns(session, rows, catalog, mainSchemaName, collation, table, table.getName());
- }
- }
- Table table = session.findLocalTempTable(tableName);
- if (table != null) {
- columns(session, rows, catalog, mainSchemaName, collation, table, table.getName());
- }
- } else {
- for (Schema schema : database.getAllSchemas()) {
- for (Table table : schema.getAllTablesAndViews(session)) {
- String tableName = table.getName();
- if (checkIndex(session, tableName, indexFrom, indexTo)) {
- columns(session, rows, catalog, mainSchemaName, collation, table, tableName);
- }
- }
- }
- for (Table table : session.getLocalTempTables()) {
- String tableName = table.getName();
- if (checkIndex(session, tableName, indexFrom, indexTo)) {
- columns(session, rows, catalog, mainSchemaName, collation, table, tableName);
- }
- }
- }
+ getAllTables(session, indexFrom, indexTo)
+ .forEach(table -> columns(session, rows, catalog, mainSchemaName, collation, table));
}
private void columns(SessionLocal session, ArrayList rows, String catalog, String mainSchemaName,
- String collation, Table table, String tableName) {
- if (hideTable(table, session)) {
- return;
- }
+ String collation, Table table) {
Column[] cols = table.getColumns();
for (int i = 0, l = cols.length; i < l;) {
- columns(session, rows, catalog, mainSchemaName, collation, table, tableName, cols[i], ++i);
+ columns(session, rows, catalog, mainSchemaName, collation, table, cols[i], ++i);
}
}
private void columns(SessionLocal session, ArrayList rows, String catalog, String mainSchemaName,
- String collation, Table table, String tableName, Column c, int ordinalPosition) {
+ String collation, Table table, Column c, int ordinalPosition) {
TypeInfo typeInfo = c.getType();
DataTypeInformation dt = DataTypeInformation.valueOf(typeInfo);
String characterSetCatalog, characterSetSchema, characterSetName, collationName;
@@ -1175,7 +1126,7 @@ private void columns(SessionLocal session, ArrayList rows, String catalog,
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// COLUMN_NAME
c.getName(),
// ORDINAL_POSITION
@@ -1278,11 +1229,7 @@ private void columnPrivileges(SessionLocal session, Value indexFrom, Value index
continue;
}
Table table = (Table) object;
- if (hideTable(table, session)) {
- continue;
- }
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
+ if (!checkIndex(session, table.getName(), indexFrom, indexTo)) {
continue;
}
DbObject grantee = r.getGrantee();
@@ -1295,11 +1242,8 @@ private void columnPrivileges(SessionLocal session, Value indexFrom, Value index
private void constraintColumnUsage(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows,
String catalog) {
- for (Schema schema : database.getAllSchemas()) {
- for (Constraint constraint : schema.getAllConstraints()) {
- constraintColumnUsage(session, indexFrom, indexTo, rows, catalog, constraint);
- }
- }
+ getAllConstraints(session)
+ .forEach(constraint -> constraintColumnUsage(session, indexFrom, indexTo, rows, catalog, constraint));
}
private void constraintColumnUsage(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows,
@@ -1311,7 +1255,7 @@ private void constraintColumnUsage(SessionLocal session, Value indexFrom, Value
constraint.getExpression().isEverything(ExpressionVisitor.getColumnsVisitor(columns, null));
for (Column column : columns) {
Table table = column.getTable();
- if (checkIndex(session, table.getName(), indexFrom, indexTo) && !hideTable(table, session)) {
+ if (checkIndex(session, table.getName(), indexFrom, indexTo)) {
addConstraintColumnUsage(session, rows, catalog, constraint, column);
}
}
@@ -1319,7 +1263,7 @@ private void constraintColumnUsage(SessionLocal session, Value indexFrom, Value
}
case REFERENTIAL: {
Table table = constraint.getRefTable();
- if (checkIndex(session, table.getName(), indexFrom, indexTo) && !hideTable(table, session)) {
+ if (checkIndex(session, table.getName(), indexFrom, indexTo)) {
for (Column column : constraint.getReferencedColumns(table)) {
addConstraintColumnUsage(session, rows, catalog, constraint, column);
}
@@ -1329,7 +1273,7 @@ private void constraintColumnUsage(SessionLocal session, Value indexFrom, Value
case PRIMARY_KEY:
case UNIQUE: {
Table table = constraint.getTable();
- if (checkIndex(session, table.getName(), indexFrom, indexTo) && !hideTable(table, session)) {
+ if (checkIndex(session, table.getName(), indexFrom, indexTo)) {
for (Column column : constraint.getReferencedColumns(table)) {
addConstraintColumnUsage(session, rows, catalog, constraint, column);
}
@@ -1530,7 +1474,7 @@ private void elementTypesFields(SessionLocal session, ArrayList rows, Strin
private void elementTypesFieldsForTable(SessionLocal session, ArrayList rows, String catalog, int type,
String mainSchemaName, String collation, String schemaName, Table table) {
- if (hideTable(table, session)) {
+ if (table.isHidden()) {
return;
}
String tableName = table.getName();
@@ -1729,29 +1673,23 @@ private void fields(SessionLocal session, ArrayList rows, String catalog, S
private void keyColumnUsage(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows,
String catalog) {
- for (Schema schema : database.getAllSchemas()) {
- for (Constraint constraint : schema.getAllConstraints()) {
- Constraint.Type constraintType = constraint.getConstraintType();
- IndexColumn[] indexColumns = null;
- if (constraintType == Constraint.Type.UNIQUE || constraintType == Constraint.Type.PRIMARY_KEY) {
- indexColumns = ((ConstraintUnique) constraint).getColumns();
- } else if (constraintType == Constraint.Type.REFERENTIAL) {
- indexColumns = ((ConstraintReferential) constraint).getColumns();
- }
- if (indexColumns == null) {
- continue;
- }
- Table table = constraint.getTable();
- if (hideTable(table, session)) {
- continue;
- }
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
- }
- keyColumnUsage(session, rows, catalog, constraint, constraintType, indexColumns, table, tableName);
+ getAllConstraints(session).forEach(constraint -> {
+ Constraint.Type constraintType = constraint.getConstraintType();
+ IndexColumn[] indexColumns;
+ if (constraintType.isUnique()) {
+ indexColumns = ((ConstraintUnique) constraint).getColumns();
+ } else if (constraintType == Constraint.Type.REFERENTIAL) {
+ indexColumns = ((ConstraintReferential) constraint).getColumns();
+ } else {
+ return;
}
- }
+ Table table = constraint.getTable();
+ String tableName = table.getName();
+ if (!checkIndex(session, tableName, indexFrom, indexTo)) {
+ return;
+ }
+ keyColumnUsage(session, rows, catalog, constraint, constraintType, indexColumns, table, tableName);
+ });
}
private void keyColumnUsage(SessionLocal session, ArrayList rows, String catalog, Constraint constraint,
@@ -1907,25 +1845,15 @@ private void parameters(SessionLocal session, ArrayList rows, String catalo
private void referentialConstraints(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows,
String catalog) {
- for (Schema schema : database.getAllSchemas()) {
- for (Constraint constraint : schema.getAllConstraints()) {
- if (constraint.getConstraintType() != Constraint.Type.REFERENTIAL) {
- continue;
- }
- if (hideTable(constraint.getTable(), session)) {
- continue;
- }
- String constraintName = constraint.getName();
- if (!checkIndex(session, constraintName, indexFrom, indexTo)) {
- continue;
- }
- referentialConstraints(session, rows, catalog, (ConstraintReferential) constraint, constraintName);
- }
- }
+ getAllConstraints(session)
+ .filter(constraint -> constraint.getConstraintType() == Type.REFERENTIAL
+ && checkIndex(session, constraint.getName(), indexFrom, indexTo))
+ .forEach(constraint -> referentialConstraints(session, rows, catalog,
+ (ConstraintReferential) constraint));
}
private void referentialConstraints(SessionLocal session, ArrayList rows, String catalog,
- ConstraintReferential constraint, String constraintName) {
+ ConstraintReferential constraint) {
ConstraintUnique unique = constraint.getReferencedConstraint();
add(session, rows,
// CONSTRAINT_CATALOG
@@ -1933,7 +1861,7 @@ private void referentialConstraints(SessionLocal session, ArrayList rows, S
// CONSTRAINT_SCHEMA
constraint.getSchema().getName(),
// CONSTRAINT_NAME
- constraintName,
+ constraint.getName(),
// UNIQUE_CONSTRAINT_CATALOG
catalog,
// UNIQUE_CONSTRAINT_SCHEMA
@@ -2169,27 +2097,10 @@ private void sequences(SessionLocal session, ArrayList rows, String catalog
}
private void tables(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows, String catalog) {
- for (Schema schema : database.getAllSchemas()) {
- for (Table table : schema.getAllTablesAndViews(session)) {
- String tableName = table.getName();
- if (checkIndex(session, tableName, indexFrom, indexTo)) {
- tables(session, rows, catalog, table, tableName);
- }
- }
- }
- for (Table table : session.getLocalTempTables()) {
- String tableName = table.getName();
- if (checkIndex(session, tableName, indexFrom, indexTo)) {
- tables(session, rows, catalog, table, tableName);
- }
- }
+ getAllTables(session, indexFrom, indexTo).forEach(table -> tables(session, rows, catalog, table));
}
- private void tables(SessionLocal session, ArrayList rows, String catalog, Table table,
- String tableName) {
- if (hideTable(table, session)) {
- return;
- }
+ private void tables(SessionLocal session, ArrayList rows, String catalog, Table table) {
String commitAction, storageType;
if (table.isTemporary()) {
commitAction = table.getOnCommitTruncate() ? "DELETE" : table.getOnCommitDrop() ? "DROP" : "PRESERVE";
@@ -2215,7 +2126,7 @@ private void tables(SessionLocal session, ArrayList rows, String catalog, T
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// TABLE_TYPE
table.getSQLTableType(),
// IS_INSERTABLE_INTO"
@@ -2238,27 +2149,15 @@ private void tables(SessionLocal session, ArrayList rows, String catalog, T
private void tableConstraints(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows,
String catalog) {
- for (Schema schema : database.getAllSchemas()) {
- for (Constraint constraint : schema.getAllConstraints()) {
- Constraint.Type constraintType = constraint.getConstraintType();
- if (constraintType == Constraint.Type.DOMAIN) {
- continue;
- }
- Table table = constraint.getTable();
- if (hideTable(table, session)) {
- continue;
- }
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
- }
- tableConstraints(session, rows, catalog, constraint, constraintType, table, tableName);
- }
- }
+ getAllConstraints(session)
+ .filter(constraint -> constraint.getConstraintType() != Constraint.Type.DOMAIN
+ && checkIndex(session, constraint.getTable().getName(), indexFrom, indexTo))
+ .forEach(constraint -> tableConstraints(session, rows, catalog, constraint));
}
- private void tableConstraints(SessionLocal session, ArrayList rows, String catalog, Constraint constraint,
- Constraint.Type constraintType, Table table, String tableName) {
+ private void tableConstraints(SessionLocal session, ArrayList rows, String catalog, Constraint constraint) {
+ Constraint.Type constraintType = constraint.getConstraintType();
+ Table table = constraint.getTable();
Index index = constraint.getIndex();
boolean enforced;
if (constraintType != Constraint.Type.REFERENTIAL) {
@@ -2281,7 +2180,7 @@ private void tableConstraints(SessionLocal session, ArrayList rows, String
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// IS_DEFERRABLE
"NO",
// INITIALLY_DEFERRED
@@ -2312,11 +2211,7 @@ private void tablePrivileges(SessionLocal session, Value indexFrom, Value indexT
continue;
}
Table table = (Table) object;
- if (hideTable(table, session)) {
- continue;
- }
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
+ if (!checkIndex(session, table.getName(), indexFrom, indexTo)) {
continue;
}
addPrivileges(session, rows, r.getGrantee(), catalog, table, null, r.getRightMask());
@@ -2384,27 +2279,11 @@ private void triggers(SessionLocal session, ArrayList rows, String catalog,
}
private void views(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows, String catalog) {
- for (Schema schema : database.getAllSchemas()) {
- for (Table table : schema.getAllTablesAndViews(session)) {
- if (table.isView()) {
- String tableName = table.getName();
- if (checkIndex(session, tableName, indexFrom, indexTo)) {
- views(session, rows, catalog, table, tableName);
- }
- }
- }
- }
- for (Table table : session.getLocalTempTables()) {
- if (table.isView()) {
- String tableName = table.getName();
- if (checkIndex(session, tableName, indexFrom, indexTo)) {
- views(session, rows, catalog, table, tableName);
- }
- }
- }
+ getAllTables(session, indexFrom, indexTo).filter(Table::isView)
+ .forEach(table -> views(session, rows, catalog, table));
}
- private void views(SessionLocal session, ArrayList rows, String catalog, Table table, String tableName) {
+ private void views(SessionLocal session, ArrayList rows, String catalog, Table table) {
String viewDefinition, status = "VALID";
if (table instanceof TableView) {
TableView view = (TableView) table;
@@ -2430,7 +2309,7 @@ private void views(SessionLocal session, ArrayList rows, String catalog, Ta
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// VIEW_DEFINITION
viewDefinition,
// CHECK_OPTION
@@ -2567,44 +2446,10 @@ private void enumValues(SessionLocal session, ArrayList rows, String catalo
private void indexes(SessionLocal session, Value indexFrom, Value indexTo, ArrayList rows, String catalog,
boolean columns) {
- if (indexFrom != null && indexFrom.equals(indexTo)) {
- String tableName = indexFrom.getString();
- if (tableName == null) {
- return;
- }
- for (Schema schema : database.getAllSchemas()) {
- Table table = schema.getTableOrViewByName(session, tableName);
- if (table != null) {
- indexes(session, rows, catalog, columns, table, table.getName());
- }
- }
- Table table = session.findLocalTempTable(tableName);
- if (table != null) {
- indexes(session, rows, catalog, columns, table, table.getName());
- }
- } else {
- for (Schema schema : database.getAllSchemas()) {
- for (Table table : schema.getAllTablesAndViews(session)) {
- String tableName = table.getName();
- if (checkIndex(session, tableName, indexFrom, indexTo)) {
- indexes(session, rows, catalog, columns, table, tableName);
- }
- }
- }
- for (Table table : session.getLocalTempTables()) {
- String tableName = table.getName();
- if (checkIndex(session, tableName, indexFrom, indexTo)) {
- indexes(session, rows, catalog, columns, table, tableName);
- }
- }
- }
+ getAllTables(session, indexFrom, indexTo).forEach(table -> indexes(session, rows, catalog, columns, table));
}
- private void indexes(SessionLocal session, ArrayList rows, String catalog, boolean columns, Table table,
- String tableName) {
- if (hideTable(table, session)) {
- return;
- }
+ private void indexes(SessionLocal session, ArrayList rows, String catalog, boolean columns, Table table) {
ArrayList indexes = table.getIndexes();
if (indexes == null) {
return;
@@ -2614,15 +2459,14 @@ private void indexes(SessionLocal session, ArrayList rows, String catalog,
continue;
}
if (columns) {
- indexColumns(session, rows, catalog, table, tableName, index);
+ indexColumns(session, rows, catalog, table, index);
} else {
- indexes(session, rows, catalog, table, tableName, index);
+ indexes(session, rows, catalog, table, index);
}
}
}
- private void indexes(SessionLocal session, ArrayList rows, String catalog, Table table, String tableName,
- Index index) {
+ private void indexes(SessionLocal session, ArrayList rows, String catalog, Table table, Index index) {
IndexType indexType = index.getIndexType();
add(session, rows,
// INDEX_CATALOG
@@ -2636,7 +2480,7 @@ private void indexes(SessionLocal session, ArrayList rows, String catalog,
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// INDEX_TYPE_NAME
indexType.getSQL(false),
// NULLS_DISTINCT
@@ -2650,8 +2494,7 @@ private void indexes(SessionLocal session, ArrayList rows, String catalog,
);
}
- private void indexColumns(SessionLocal session, ArrayList rows, String catalog, Table table,
- String tableName, Index index) {
+ private void indexColumns(SessionLocal session, ArrayList rows, String catalog, Table table, Index index) {
IndexColumn[] cols = index.getIndexColumns();
int uniqueColumnCount = index.getUniqueColumnCount();
for (int i = 0, l = cols.length; i < l;) {
@@ -2669,7 +2512,7 @@ private void indexColumns(SessionLocal session, ArrayList rows, String cata
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// COLUMN_NAME
idxCol.column.getName(),
// ORDINAL_POSITION
diff --git a/h2/src/main/org/h2/table/InformationSchemaTableLegacy.java b/h2/src/main/org/h2/table/InformationSchemaTableLegacy.java
index ac7e821c75..c012b71be4 100644
--- a/h2/src/main/org/h2/table/InformationSchemaTableLegacy.java
+++ b/h2/src/main/org/h2/table/InformationSchemaTableLegacy.java
@@ -24,7 +24,6 @@
import org.h2.constraint.Constraint;
import org.h2.constraint.Constraint.Type;
import org.h2.constraint.ConstraintActionType;
-import org.h2.constraint.ConstraintCheck;
import org.h2.constraint.ConstraintDomain;
import org.h2.constraint.ConstraintReferential;
import org.h2.constraint.ConstraintUnique;
@@ -724,30 +723,15 @@ private static String replaceNullWithEmpty(String s) {
@Override
public ArrayList generateRows(SessionLocal session, SearchRow first, SearchRow last) {
- Value indexFrom = null, indexTo = null;
-
- if (indexColumn >= 0) {
- if (first != null) {
- indexFrom = first.getValue(indexColumn);
- }
- if (last != null) {
- indexTo = last.getValue(indexColumn);
- }
- }
+ Value indexFrom = indexColumn >= 0 && first != null ? first.getValue(indexColumn) : null;
+ Value indexTo = indexColumn >= 0 && last != null ? last.getValue(indexColumn) : null;
ArrayList rows = Utils.newSmallArrayList();
String catalog = database.getShortName();
boolean admin = session.getUser().isAdmin();
switch (type) {
case TABLES: {
- for (Table table : getAllTables(session)) {
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
- }
- if (hideTable(table, session)) {
- continue;
- }
+ getAllTables(session, indexFrom, indexTo).forEach(table -> {
String storageType;
if (table.isTemporary()) {
if (table.isGlobalTemporary()) {
@@ -773,7 +757,7 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// TABLE_TYPE
table.getTableType().toString(),
// STORAGE_TYPE
@@ -793,30 +777,11 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
// ROW_COUNT_ESTIMATE
ValueBigint.get(table.getRowCountApproximation(session))
);
- }
+ });
break;
}
case COLUMNS: {
- // reduce the number of tables to scan - makes some metadata queries
- // 10x faster
- final ArrayList tablesToList;
- if (indexFrom != null && indexFrom.equals(indexTo)) {
- String tableName = indexFrom.getString();
- if (tableName == null) {
- break;
- }
- tablesToList = getTablesByName(session, tableName);
- } else {
- tablesToList = getAllTables(session);
- }
- for (Table table : tablesToList) {
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
- }
- if (hideTable(table, session)) {
- continue;
- }
+ getAllTables(session, indexFrom, indexTo).forEach(table -> {
Column[] cols = table.getColumns();
String collation = database.getCompareMode().getName();
for (int j = 0; j < cols.length; j++) {
@@ -853,7 +818,7 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// COLUMN_NAME
c.getName(),
// ORDINAL_POSITION
@@ -920,30 +885,11 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
null
);
}
- }
+ });
break;
}
case INDEXES: {
- // reduce the number of tables to scan - makes some metadata queries
- // 10x faster
- final ArrayList tablesToList;
- if (indexFrom != null && indexFrom.equals(indexTo)) {
- String tableName = indexFrom.getString();
- if (tableName == null) {
- break;
- }
- tablesToList = getTablesByName(session, tableName);
- } else {
- tablesToList = getAllTables(session);
- }
- for (Table table : tablesToList) {
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
- }
- if (hideTable(table, session)) {
- continue;
- }
+ getAllTables(session, indexFrom, indexTo).forEach(table -> {
ArrayList indexes = table.getIndexes();
ArrayList constraints = table.getConstraints();
for (int j = 0; indexes != null && j < indexes.size(); j++) {
@@ -977,7 +923,7 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// NON_UNIQUE
ValueBoolean.get(k >= uniqueColumnCount),
// INDEX_NAME
@@ -1017,7 +963,7 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
);
}
}
- }
+ });
break;
}
case TABLE_TYPES: {
@@ -1539,11 +1485,7 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
continue;
}
Table table = (Table) object;
- if (hideTable(table, session)) {
- continue;
- }
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
+ if (!checkIndex(session, table.getName(), indexFrom, indexTo)) {
continue;
}
addPrivileges(session, rows, r.getGrantee(), catalog, table, null, r.getRightMask());
@@ -1557,11 +1499,7 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
continue;
}
Table table = (Table) object;
- if (hideTable(table, session)) {
- continue;
- }
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
+ if (!checkIndex(session, table.getName(), indexFrom, indexTo)) {
continue;
}
DbObject grantee = r.getGrantee();
@@ -1584,15 +1522,7 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
break;
}
case VIEWS: {
- for (Table table : getAllTables(session)) {
- if (table.getTableType() != TableType.VIEW) {
- continue;
- }
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
- }
- TableView view = (TableView) table;
+ getAllTables(session, indexFrom, indexTo).filter(Table::isView).forEach(table -> {
add(session,
rows,
// TABLE_CATALOG
@@ -1600,7 +1530,7 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
- tableName,
+ table.getName(),
// VIEW_DEFINITION
table.getCreateSQL(),
// CHECK_OPTION
@@ -1608,13 +1538,13 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
// IS_UPDATABLE
"NO",
// STATUS
- view.isInvalid() ? "INVALID" : "VALID",
+ table instanceof TableView && ((TableView) table).isInvalid() ? "INVALID" : "VALID",
// REMARKS
- replaceNullWithEmpty(view.getComment()),
+ replaceNullWithEmpty(table.getComment()),
// ID
- ValueInteger.get(view.getId())
+ ValueInteger.get(table.getId())
);
- }
+ });
break;
}
case IN_DOUBT: {
@@ -1632,129 +1562,112 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
break;
}
case CROSS_REFERENCES: {
- for (SchemaObject obj : getAllSchemaObjects(
- DbObject.CONSTRAINT)) {
- Constraint constraint = (Constraint) obj;
- if (constraint.getConstraintType() != Constraint.Type.REFERENTIAL) {
- continue;
- }
- ConstraintReferential ref = (ConstraintReferential) constraint;
- IndexColumn[] cols = ref.getColumns();
- IndexColumn[] refCols = ref.getRefColumns();
- Table tab = ref.getTable();
- Table refTab = ref.getRefTable();
- String tableName = refTab.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
- }
- ValueSmallint update = ValueSmallint.get(getRefAction(ref.getUpdateAction()));
- ValueSmallint delete = ValueSmallint.get(getRefAction(ref.getDeleteAction()));
- for (int j = 0; j < cols.length; j++) {
- add(session,
- rows,
- // PKTABLE_CATALOG
- catalog,
- // PKTABLE_SCHEMA
- refTab.getSchema().getName(),
- // PKTABLE_NAME
- refTab.getName(),
- // PKCOLUMN_NAME
- refCols[j].column.getName(),
- // FKTABLE_CATALOG
- catalog,
- // FKTABLE_SCHEMA
- tab.getSchema().getName(),
- // FKTABLE_NAME
- tab.getName(),
- // FKCOLUMN_NAME
- cols[j].column.getName(),
- // ORDINAL_POSITION
- ValueSmallint.get((short) (j + 1)),
- // UPDATE_RULE
- update,
- // DELETE_RULE
- delete,
- // FK_NAME
- ref.getName(),
- // PK_NAME
- ref.getReferencedConstraint().getName(),
- // DEFERRABILITY
- ValueSmallint.get((short) DatabaseMetaData.importedKeyNotDeferrable)
- );
- }
- }
+ getAllConstraints(session).filter(constraint -> constraint.getConstraintType() == Type.REFERENTIAL
+ && checkIndex(session, constraint.getName(), indexFrom, indexTo)).forEach(constraint -> {
+ ConstraintReferential ref = (ConstraintReferential) constraint;
+ IndexColumn[] cols = ref.getColumns();
+ IndexColumn[] refCols = ref.getRefColumns();
+ Table tab = ref.getTable();
+ Table refTab = ref.getRefTable();
+ ValueSmallint update = ValueSmallint.get(getRefAction(ref.getUpdateAction()));
+ ValueSmallint delete = ValueSmallint.get(getRefAction(ref.getDeleteAction()));
+ for (int j = 0; j < cols.length; j++) {
+ add(session, rows,
+ // PKTABLE_CATALOG
+ catalog,
+ // PKTABLE_SCHEMA
+ refTab.getSchema().getName(),
+ // PKTABLE_NAME
+ refTab.getName(),
+ // PKCOLUMN_NAME
+ refCols[j].column.getName(),
+ // FKTABLE_CATALOG
+ catalog,
+ // FKTABLE_SCHEMA
+ tab.getSchema().getName(),
+ // FKTABLE_NAME
+ tab.getName(),
+ // FKCOLUMN_NAME
+ cols[j].column.getName(),
+ // ORDINAL_POSITION
+ ValueSmallint.get((short) (j + 1)),
+ // UPDATE_RULE
+ update,
+ // DELETE_RULE
+ delete,
+ // FK_NAME
+ ref.getName(),
+ // PK_NAME
+ ref.getReferencedConstraint().getName(),
+ // DEFERRABILITY
+ ValueSmallint.get((short) DatabaseMetaData.importedKeyNotDeferrable));
+ }
+ });
break;
}
case CONSTRAINTS: {
- for (SchemaObject obj : getAllSchemaObjects(
- DbObject.CONSTRAINT)) {
- Constraint constraint = (Constraint) obj;
- Constraint.Type constraintType = constraint.getConstraintType();
- String checkExpression = null;
- IndexColumn[] indexColumns = null;
- Table table = constraint.getTable();
- if (hideTable(table, session)) {
- continue;
- }
- Index index = constraint.getIndex();
- String uniqueIndexName = null;
- if (index != null) {
- uniqueIndexName = index.getName();
- }
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
- }
- if (constraintType == Constraint.Type.CHECK) {
- checkExpression = constraint.getExpression().getSQL(HasSQL.DEFAULT_SQL_FLAGS);
- } else if (constraintType == Constraint.Type.UNIQUE ||
- constraintType == Constraint.Type.PRIMARY_KEY) {
- indexColumns = ((ConstraintUnique) constraint).getColumns();
- } else if (constraintType == Constraint.Type.REFERENTIAL) {
- indexColumns = ((ConstraintReferential) constraint).getColumns();
- }
- String columnList = null;
- if (indexColumns != null) {
- StringBuilder builder = new StringBuilder();
- for (int i = 0, length = indexColumns.length; i < length; i++) {
- if (i > 0) {
- builder.append(',');
+ getAllConstraints(session)
+ .filter(constraint -> constraint.getConstraintType() != Constraint.Type.DOMAIN
+ && checkIndex(session, constraint.getTable().getName(), indexFrom, indexTo))
+ .forEach(constraint -> {
+ Constraint.Type constraintType = constraint.getConstraintType();
+ String checkExpression = null;
+ IndexColumn[] indexColumns = null;
+ Table table = constraint.getTable();
+ Index index = constraint.getIndex();
+ String uniqueIndexName = null;
+ if (index != null) {
+ uniqueIndexName = index.getName();
}
- builder.append(indexColumns[i].column.getName());
- }
- columnList = builder.toString();
- }
- add(session,
- rows,
- // CONSTRAINT_CATALOG
- catalog,
- // CONSTRAINT_SCHEMA
- constraint.getSchema().getName(),
- // CONSTRAINT_NAME
- constraint.getName(),
- // CONSTRAINT_TYPE
- constraintType == Constraint.Type.PRIMARY_KEY ?
- constraintType.getSqlName() : constraintType.name(),
- // TABLE_CATALOG
- catalog,
- // TABLE_SCHEMA
- table.getSchema().getName(),
- // TABLE_NAME
- tableName,
- // UNIQUE_INDEX_NAME
- uniqueIndexName,
- // CHECK_EXPRESSION
- checkExpression,
- // COLUMN_LIST
- columnList,
- // REMARKS
- replaceNullWithEmpty(constraint.getComment()),
- // SQL
- constraint.getCreateSQL(),
- // ID
- ValueInteger.get(constraint.getId())
- );
- }
+ if (constraintType == Constraint.Type.CHECK) {
+ checkExpression = constraint.getExpression().getSQL(HasSQL.DEFAULT_SQL_FLAGS);
+ } else if (constraintType.isUnique()) {
+ indexColumns = ((ConstraintUnique) constraint).getColumns();
+ } else if (constraintType == Constraint.Type.REFERENTIAL) {
+ indexColumns = ((ConstraintReferential) constraint).getColumns();
+ }
+ String columnList = null;
+ if (indexColumns != null) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0, length = indexColumns.length; i < length; i++) {
+ if (i > 0) {
+ builder.append(',');
+ }
+ builder.append(indexColumns[i].column.getName());
+ }
+ columnList = builder.toString();
+ }
+ add(session,
+ rows,
+ // CONSTRAINT_CATALOG
+ catalog,
+ // CONSTRAINT_SCHEMA
+ constraint.getSchema().getName(),
+ // CONSTRAINT_NAME
+ constraint.getName(),
+ // CONSTRAINT_TYPE
+ constraintType == Constraint.Type.PRIMARY_KEY ?
+ constraintType.getSqlName() : constraintType.name(),
+ // TABLE_CATALOG
+ catalog,
+ // TABLE_SCHEMA
+ table.getSchema().getName(),
+ // TABLE_NAME
+ table.getName(),
+ // UNIQUE_INDEX_NAME
+ uniqueIndexName,
+ // CHECK_EXPRESSION
+ checkExpression,
+ // COLUMN_LIST
+ columnList,
+ // REMARKS
+ replaceNullWithEmpty(constraint.getComment()),
+ // SQL
+ constraint.getCreateSQL(),
+ // ID
+ ValueInteger.get(constraint.getId())
+ );
+ });
break;
}
case CONSTANTS: {
@@ -2053,48 +1966,40 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
break;
}
case TABLE_CONSTRAINTS: {
- for (SchemaObject obj : getAllSchemaObjects(DbObject.CONSTRAINT)) {
- Constraint constraint = (Constraint) obj;
- Constraint.Type constraintType = constraint.getConstraintType();
- if (constraintType == Constraint.Type.DOMAIN) {
- continue;
- }
- Table table = constraint.getTable();
- if (hideTable(table, session)) {
- continue;
- }
- String tableName = table.getName();
- if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
- }
- add(session,
- rows,
- // CONSTRAINT_CATALOG
- catalog,
- // CONSTRAINT_SCHEMA
- constraint.getSchema().getName(),
- // CONSTRAINT_NAME
- constraint.getName(),
- // CONSTRAINT_TYPE
- constraintType.getSqlName(),
- // TABLE_CATALOG
- catalog,
- // TABLE_SCHEMA
- table.getSchema().getName(),
- // TABLE_NAME
- tableName,
- // IS_DEFERRABLE
- "NO",
- // INITIALLY_DEFERRED
- "NO",
- // REMARKS
- replaceNullWithEmpty(constraint.getComment()),
- // SQL
- constraint.getCreateSQL(),
- // ID
- ValueInteger.get(constraint.getId())
- );
- }
+ getAllConstraints(session)
+ .filter(constraint -> constraint.getConstraintType() != Constraint.Type.DOMAIN
+ && checkIndex(session, constraint.getTable().getName(), indexFrom, indexTo))
+ .forEach(constraint -> {
+ Constraint.Type constraintType = constraint.getConstraintType();
+ Table table = constraint.getTable();
+ add(session,
+ rows,
+ // CONSTRAINT_CATALOG
+ catalog,
+ // CONSTRAINT_SCHEMA
+ constraint.getSchema().getName(),
+ // CONSTRAINT_NAME
+ constraint.getName(),
+ // CONSTRAINT_TYPE
+ constraintType.getSqlName(),
+ // TABLE_CATALOG
+ catalog,
+ // TABLE_SCHEMA
+ table.getSchema().getName(),
+ // TABLE_NAME
+ table.getName(),
+ // IS_DEFERRABLE
+ "NO",
+ // INITIALLY_DEFERRED
+ "NO",
+ // REMARKS
+ replaceNullWithEmpty(constraint.getComment()),
+ // SQL
+ constraint.getCreateSQL(),
+ // ID
+ ValueInteger.get(constraint.getId())
+ );
+ });
break;
}
case DOMAIN_CONSTRAINTS: {
@@ -2133,25 +2038,20 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
break;
}
case KEY_COLUMN_USAGE: {
- for (SchemaObject obj : getAllSchemaObjects(DbObject.CONSTRAINT)) {
- Constraint constraint = (Constraint) obj;
+ getAllConstraints(session).forEach(constraint -> {
Constraint.Type constraintType = constraint.getConstraintType();
- IndexColumn[] indexColumns = null;
- if (constraintType == Constraint.Type.UNIQUE || constraintType == Constraint.Type.PRIMARY_KEY) {
+ IndexColumn[] indexColumns;
+ if (constraintType.isUnique()) {
indexColumns = ((ConstraintUnique) constraint).getColumns();
} else if (constraintType == Constraint.Type.REFERENTIAL) {
indexColumns = ((ConstraintReferential) constraint).getColumns();
- }
- if (indexColumns == null) {
- continue;
+ } else {
+ return;
}
Table table = constraint.getTable();
- if (hideTable(table, session)) {
- continue;
- }
String tableName = table.getName();
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
- continue;
+ return;
}
ConstraintUnique referenced;
if (constraintType == Constraint.Type.REFERENTIAL) {
@@ -2202,82 +2102,63 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
index != null ? index.getName() : null
);
}
- }
+ });
break;
}
case REFERENTIAL_CONSTRAINTS: {
- for (SchemaObject obj : getAllSchemaObjects(DbObject.CONSTRAINT)) {
- if (((Constraint) obj).getConstraintType() != Constraint.Type.REFERENTIAL) {
- continue;
- }
- ConstraintReferential constraint = (ConstraintReferential) obj;
- Table table = constraint.getTable();
- if (hideTable(table, session)) {
- continue;
- }
- ConstraintUnique unique = constraint.getReferencedConstraint();
- add(session,
- rows,
- // CONSTRAINT_CATALOG
- catalog,
- // CONSTRAINT_SCHEMA
- constraint.getSchema().getName(),
- // CONSTRAINT_NAME
- constraint.getName(),
- // UNIQUE_CONSTRAINT_CATALOG
- catalog,
- // UNIQUE_CONSTRAINT_SCHEMA
- unique.getSchema().getName(),
- // UNIQUE_CONSTRAINT_NAME
- unique.getName(),
- // MATCH_OPTION
- "NONE",
- // UPDATE_RULE
- constraint.getUpdateAction().getSqlName(),
- // DELETE_RULE
- constraint.getDeleteAction().getSqlName()
- );
- }
+ getAllConstraints(session).filter(constraint -> constraint.getConstraintType() == Type.REFERENTIAL
+ && checkIndex(session, constraint.getName(), indexFrom, indexTo)).forEach(c -> {
+ ConstraintReferential constraint = (ConstraintReferential) c;
+ ConstraintUnique unique = constraint.getReferencedConstraint();
+ add(session,
+ rows,
+ // CONSTRAINT_CATALOG
+ catalog,
+ // CONSTRAINT_SCHEMA
+ constraint.getSchema().getName(),
+ // CONSTRAINT_NAME
+ constraint.getName(),
+ // UNIQUE_CONSTRAINT_CATALOG
+ catalog,
+ // UNIQUE_CONSTRAINT_SCHEMA
+ unique.getSchema().getName(),
+ // UNIQUE_CONSTRAINT_NAME
+ unique.getName(),
+ // MATCH_OPTION
+ "NONE",
+ // UPDATE_RULE
+ constraint.getUpdateAction().getSqlName(),
+ // DELETE_RULE
+ constraint.getDeleteAction().getSqlName()
+ );
+ });
break;
}
case CHECK_CONSTRAINTS: {
- for (SchemaObject obj : getAllSchemaObjects(DbObject.CONSTRAINT)) {
- Constraint constraint = (Constraint) obj;
- Type constraintType = constraint.getConstraintType();
- if (constraintType == Constraint.Type.CHECK) {
- ConstraintCheck check = (ConstraintCheck) obj;
- Table table = check.getTable();
- if (hideTable(table, session)) {
- continue;
- }
- } else if (constraintType != Constraint.Type.DOMAIN) {
- continue;
- }
- add(session,
- rows,
- // CONSTRAINT_CATALOG
- catalog,
- // CONSTRAINT_SCHEMA
- obj.getSchema().getName(),
- // CONSTRAINT_NAME
- obj.getName(),
- // CHECK_CLAUSE
- constraint.getExpression().getSQL(DEFAULT_SQL_FLAGS, Expression.WITHOUT_PARENTHESES)
- );
- }
+ getAllConstraints(session).filter(constraint -> constraint.getConstraintType().isCheck()
+ && checkIndex(session, constraint.getName(), indexFrom, indexTo)).forEach(constraint -> {
+ add(session, rows,
+ // CONSTRAINT_CATALOG
+ catalog,
+ // CONSTRAINT_SCHEMA
+ constraint.getSchema().getName(),
+ // CONSTRAINT_NAME
+ constraint.getName(),
+ // CHECK_CLAUSE
+ constraint.getExpression().getSQL(DEFAULT_SQL_FLAGS, Expression.WITHOUT_PARENTHESES));
+ });
break;
}
case CONSTRAINT_COLUMN_USAGE: {
- for (SchemaObject obj : getAllSchemaObjects(DbObject.CONSTRAINT)) {
- Constraint constraint = (Constraint) obj;
+ getAllConstraints(session).forEach(constraint -> {
switch (constraint.getConstraintType()) {
case CHECK:
case DOMAIN: {
HashSet columns = new HashSet<>();
constraint.getExpression().isEverything(ExpressionVisitor.getColumnsVisitor(columns, null));
- for (Column column: columns) {
+ for (Column column : columns) {
Table table = column.getTable();
- if (checkIndex(session, table.getName(), indexFrom, indexTo) && !hideTable(table, session)) {
+ if (checkIndex(session, table.getName(), indexFrom, indexTo)) {
addConstraintColumnUsage(session, rows, catalog, constraint, column);
}
}
@@ -2285,7 +2166,7 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
}
case REFERENTIAL: {
Table table = constraint.getRefTable();
- if (checkIndex(session, table.getName(), indexFrom, indexTo) && !hideTable(table, session)) {
+ if (checkIndex(session, table.getName(), indexFrom, indexTo)) {
for (Column column : constraint.getReferencedColumns(table)) {
addConstraintColumnUsage(session, rows, catalog, constraint, column);
}
@@ -2295,14 +2176,14 @@ public ArrayList generateRows(SessionLocal session, SearchRow first, Search
case PRIMARY_KEY:
case UNIQUE: {
Table table = constraint.getTable();
- if (checkIndex(session, table.getName(), indexFrom, indexTo) && !hideTable(table, session)) {
+ if (checkIndex(session, table.getName(), indexFrom, indexTo)) {
for (Column column : constraint.getReferencedColumns(table)) {
addConstraintColumnUsage(session, rows, catalog, constraint, column);
}
}
}
}
- }
+ });
break;
}
default:
@@ -2423,38 +2304,6 @@ private ArrayList getAllSchemaObjects(int type) {
return list;
}
- /**
- * Get all tables of this database, including local temporary tables for the
- * session.
- *
- * @param session the session
- * @return the array of tables
- */
- private ArrayList getAllTables(SessionLocal session) {
- ArrayList tables = new ArrayList<>();
- for (Schema schema : database.getAllSchemas()) {
- tables.addAll(schema.getAllTablesAndViews(session));
- }
- tables.addAll(session.getLocalTempTables());
- return tables;
- }
-
- private ArrayList getTablesByName(SessionLocal session, String tableName) {
- // we expect that at most one table matches, at least in most cases
- ArrayList tables = new ArrayList<>(1);
- for (Schema schema : database.getAllSchemas()) {
- Table table = schema.getTableOrViewByName(session, tableName);
- if (table != null) {
- tables.add(table);
- }
- }
- Table table = session.findLocalTempTable(tableName);
- if (table != null) {
- tables.add(table);
- }
- return tables;
- }
-
@Override
public long getMaxDataModificationId() {
switch (type) {
diff --git a/h2/src/main/org/h2/table/MetaTable.java b/h2/src/main/org/h2/table/MetaTable.java
index 93503cbf42..ff9c538436 100644
--- a/h2/src/main/org/h2/table/MetaTable.java
+++ b/h2/src/main/org/h2/table/MetaTable.java
@@ -6,7 +6,9 @@
package org.h2.table;
import java.util.ArrayList;
+import java.util.stream.Stream;
+import org.h2.constraint.Constraint;
import org.h2.engine.SessionLocal;
import org.h2.index.Index;
import org.h2.index.IndexType;
@@ -143,15 +145,48 @@ protected final boolean checkIndex(SessionLocal session, String value, Value ind
}
/**
- * Check whether to hide the table. Tables are never hidden in the system
+ * Get all tables of this database, including local temporary tables for the
* session.
*
- * @param table the table
- * @param session the session
- * @return whether the table is hidden
+ * @param session
+ * the session
+ * @param indexFrom
+ * first value or {@code null}
+ * @param indexTo
+ * last value or {@code null}
+ * @return the stream of tables
+ */
+ protected final Stream getAllTables(SessionLocal session, Value indexFrom, Value indexTo) {
+ if (indexFrom != null && indexFrom.equals(indexTo)) {
+ String tableName = indexFrom.getString();
+ if (tableName == null) {
+ return Stream.empty();
+ }
+ return Stream
+ .concat(database.getAllSchemas().stream()
+ .map(schema -> schema.getTableOrViewByName(session, tableName)),
+ Stream.ofNullable(session.findLocalTempTable(tableName)))
+ .filter(table -> table != null && !table.isHidden());
+ } else {
+ return Stream
+ .concat(database.getAllSchemas().stream()
+ .flatMap(schema -> schema.getAllTablesAndViews(session).stream()),
+ session.getLocalTempTables().stream())
+ .filter(table -> !table.isHidden() && checkIndex(session, table.getName(), indexFrom, indexTo));
+ }
+ }
+
+ /**
+ * Get all constraints of this database, including constraints of local
+ * temporary tables for the session.
+ *
+ * @param session
+ * the session
+ * @return the stream of constraints
*/
- protected final boolean hideTable(Table table, SessionLocal session) {
- return table.isHidden() && session != database.getSystemSession();
+ protected final Stream getAllConstraints(SessionLocal session) {
+ return Stream.concat(database.getAllSchemas().stream().flatMap(schema -> schema.getAllConstraints().stream()),
+ session.getLocalTempTableConstraints().values().stream());
}
/**
diff --git a/h2/src/main/org/h2/table/Table.java b/h2/src/main/org/h2/table/Table.java
index c3102a58f2..c3e8fb3f69 100644
--- a/h2/src/main/org/h2/table/Table.java
+++ b/h2/src/main/org/h2/table/Table.java
@@ -84,12 +84,6 @@ public abstract class Table extends SchemaObject {
*/
protected CompareMode compareMode;
- /**
- * Protected tables are not listed in the meta data and are excluded when
- * using the SCRIPT command.
- */
- protected boolean isHidden;
-
private final HashMap columnMap;
private final boolean persistIndexes;
private final boolean persistData;
@@ -1418,13 +1412,14 @@ public void checkWritingAllowed() {
database.checkWritingAllowed();
}
- @Override
+ /**
+ * Check whether this is a hidden object that doesn't appear in the meta
+ * data and in the script.
+ *
+ * @return true if it is hidden
+ */
public boolean isHidden() {
- return isHidden;
- }
-
- public void setHidden(boolean hidden) {
- this.isHidden = hidden;
+ return false;
}
/**
diff --git a/h2/src/main/org/h2/table/TableBase.java b/h2/src/main/org/h2/table/TableBase.java
index 7bafe43938..0f9b9691c1 100644
--- a/h2/src/main/org/h2/table/TableBase.java
+++ b/h2/src/main/org/h2/table/TableBase.java
@@ -110,9 +110,6 @@ private String getCreateSQL(boolean forMeta) {
buff.append("MEMORY ");
}
buff.append("TABLE ");
- if (isHidden) {
- buff.append("IF NOT EXISTS ");
- }
getSQL(buff, DEFAULT_SQL_FLAGS);
if (comment != null) {
buff.append(" COMMENT ");
@@ -145,9 +142,6 @@ private String getCreateSQL(boolean forMeta) {
if (!isPersistIndexes() && !isPersistData()) {
buff.append("\nNOT PERSISTENT");
}
- if (isHidden) {
- buff.append("\nHIDDEN");
- }
return buff.toString();
}
diff --git a/h2/src/main/org/h2/table/TableView.java b/h2/src/main/org/h2/table/TableView.java
index ed4e6ff5fa..7a4804e04c 100644
--- a/h2/src/main/org/h2/table/TableView.java
+++ b/h2/src/main/org/h2/table/TableView.java
@@ -49,6 +49,11 @@ public TableView(Schema schema, int id, String name, String querySQL,
init(querySQL, params, columnTemplates, session, allowRecursive, literalsChecked, isTableExpression);
}
+ @Override
+ public boolean isHidden() {
+ return isTableExpression;
+ }
+
/**
* Try to replace the SQL statement of the view and re-compile this and all
* dependent views.
diff --git a/h2/src/test/org/h2/test/scripts/information_schema.sql b/h2/src/test/org/h2/test/scripts/information_schema.sql
index 4f546f9171..b93204c042 100644
--- a/h2/src/test/org/h2/test/scripts/information_schema.sql
+++ b/h2/src/test/org/h2/test/scripts/information_schema.sql
@@ -191,3 +191,15 @@ SELECT TABLE_NAME, ROW_COUNT_ESTIMATE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE
EXPLAIN SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLLATIONS;
>> SELECT COUNT(*) FROM "INFORMATION_SCHEMA"."COLLATIONS" /* meta */ /* direct lookup */
+
+CREATE LOCAL TEMPORARY TABLE T1(ID BIGINT PRIMARY KEY);
+> ok
+
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = 'T1';
+>> 1
+
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = 'T1';
+>> 1
+
+DROP TABLE T1;
+> ok