Skip to content

Commit

Permalink
Merge pull request #3974 from katzyn/local_temporary
Browse files Browse the repository at this point in the history
Return information about local temporary tables where expected
  • Loading branch information
katzyn committed Jan 21, 2024
2 parents 6f234b7 + 1d02abe commit 7e780f6
Show file tree
Hide file tree
Showing 29 changed files with 418 additions and 772 deletions.
4 changes: 4 additions & 0 deletions h2/src/docsrc/html/changelog.html
Expand Up @@ -21,6 +21,10 @@ <h1>Change Log</h1>

<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #3972: Constraints of local temporary tables aren't listed in INFORMATION_SCHEMA
</li>
<li>PR #3973: Fix Tool.showUsage() for GUIConsole
</li>
<li>Issue #3968: Add possibility to get index size on disk
</li>
<li>Issue #3909: Maintenance taking too much resources since 2.2.222
Expand Down
5 changes: 0 additions & 5 deletions h2/src/main/org/h2/command/Parser.java
Expand Up @@ -7123,7 +7123,6 @@ private TableView createCTEView(String cteViewName, String querySQL, ArrayList<P
}
view.setTableExpression(true);
view.setTemporary(isTemporary);
view.setHidden(true);
view.setOnCommitDrop(false);
if (!isTemporary) {
database.addSchemaObject(session, view);
Expand Down Expand Up @@ -8464,7 +8463,6 @@ private Prepared parseAlterTableRename(Schema schema, String tableName, boolean
command.setTableName(tableName);
command.setNewTableName(newName);
command.setIfTableExists(ifTableExists);
command.setHidden(readIf("HIDDEN"));
return command;
}
}
Expand Down Expand Up @@ -8977,9 +8975,6 @@ private CreateTable parseCreateTable(boolean temp, boolean globalTemp,
} else if (!persistIndexes && readIf(NOT, "PERSISTENT")) {
command.setPersistData(false);
}
if (readIf("HIDDEN")) {
command.setHidden(true);
}
if (readIf(AS)) {
readIf("SORTED");
command.setQuery(parseQuery());
Expand Down
3 changes: 1 addition & 2 deletions h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
Expand Up @@ -387,8 +387,7 @@ private static ConstraintUnique getUniqueConstraint(Table t, IndexColumn[] cols)
if (constraints != null) {
for (Constraint constraint : constraints) {
if (constraint.getTable() == t) {
Constraint.Type constraintType = constraint.getConstraintType();
if (constraintType == Constraint.Type.PRIMARY_KEY || constraintType == Constraint.Type.UNIQUE) {
if (constraint.getConstraintType().isUnique()) {
if (canUseIndex(constraint.getIndex(), t, cols, NullsDistinct.DISTINCT)) {
return (ConstraintUnique) constraint;
}
Expand Down
1 change: 0 additions & 1 deletion h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
Expand Up @@ -453,7 +453,6 @@ private Table cloneTableStructure(Table table, Column[] columns, Database db,
data.temporary = table.isTemporary();
data.persistData = table.isPersistData();
data.persistIndexes = table.isPersistIndexes();
data.isHidden = table.isHidden();
data.session = session;
Table newTable = getSchema().createTable(data);
newTable.setComment(table.getComment());
Expand Down
Expand Up @@ -55,7 +55,7 @@ public long update(Table table) {
if (refTable != table) {
session.getUser().checkTableRight(refTable, Right.SCHEMA_OWNER);
}
if (constraintType == Type.PRIMARY_KEY || constraintType == Type.UNIQUE) {
if (constraintType.isUnique()) {
for (Constraint c : constraint.getTable().getConstraints()) {
if (c.getReferencedConstraint() == constraint) {
if (dropAction == ConstraintActionType.RESTRICT) {
Expand Down
13 changes: 0 additions & 13 deletions h2/src/main/org/h2/command/ddl/AlterTableRename.java
Expand Up @@ -20,7 +20,6 @@
public class AlterTableRename extends AlterTable {

private String newTableName;
private boolean hidden;

public AlterTableRename(SessionLocal session, Schema schema) {
super(session, schema);
Expand All @@ -34,14 +33,6 @@ public void setNewTableName(String name) {
public long update(Table table) {
Database db = getDatabase();
Table t = getSchema().findTableOrView(session, newTableName);
if (t != null && hidden && newTableName.equals(table.getName())) {
if (!t.isHidden()) {
t.setHidden(hidden);
table.setHidden(true);
db.updateMeta(session, table);
}
return 0;
}
if (t != null || newTableName.equals(table.getName())) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, newTableName);
}
Expand All @@ -57,8 +48,4 @@ public int getType() {
return CommandInterface.ALTER_TABLE_RENAME;
}

public void setHidden(boolean hidden) {
this.hidden = hidden;
}

}
1 change: 0 additions & 1 deletion h2/src/main/org/h2/command/ddl/Analyze.java
Expand Up @@ -171,7 +171,6 @@ public long update() {
public static void analyzeTable(SessionLocal session, Table table, int sample, boolean manual) {
if (!table.isValid()
|| table.getTableType() != TableType.TABLE //
|| table.isHidden() //
|| session == null //
|| !manual && (session.getDatabase().isSysTableLocked() || table.hasSelectTrigger()) //
|| table.isTemporary() && !table.isGlobalTemporary() //
Expand Down
4 changes: 0 additions & 4 deletions h2/src/main/org/h2/command/ddl/CreateTable.java
Expand Up @@ -266,10 +266,6 @@ public void setTableEngineParams(ArrayList<String> tableEngineParams) {
data.tableEngineParams = tableEngineParams;
}

public void setHidden(boolean isHidden) {
data.isHidden = isHidden;
}

@Override
public int getType() {
return CommandInterface.CREATE_TABLE;
Expand Down
4 changes: 0 additions & 4 deletions h2/src/main/org/h2/command/ddl/CreateTableData.java
Expand Up @@ -71,8 +71,4 @@ public class CreateTableData {
*/
public ArrayList<String> tableEngineParams;

/**
* The table is hidden.
*/
public boolean isHidden;
}
8 changes: 3 additions & 5 deletions h2/src/main/org/h2/command/ddl/DropDatabase.java
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions h2/src/main/org/h2/command/dml/ScriptCommand.java
Expand Up @@ -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);
}
}
Expand Down
29 changes: 22 additions & 7 deletions h2/src/main/org/h2/constraint/Constraint.java
Expand Up @@ -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;
}

}

/**
Expand Down Expand Up @@ -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.
*
Expand Down
3 changes: 0 additions & 3 deletions h2/src/main/org/h2/constraint/ConstraintCheck.java
Expand Up @@ -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 ");
Expand Down
3 changes: 0 additions & 3 deletions h2/src/main/org/h2/constraint/ConstraintReferential.java
Expand Up @@ -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 ");
Expand Down
3 changes: 0 additions & 3 deletions h2/src/main/org/h2/constraint/ConstraintUnique.java
Expand Up @@ -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 ");
Expand Down
1 change: 0 additions & 1 deletion h2/src/main/org/h2/engine/Database.java
Expand Up @@ -571,7 +571,6 @@ private CreateTableData createSysTableData() {
data.temporary = false;
data.persistData = persistent;
data.persistIndexes = persistent;
data.isHidden = true;
data.session = systemSession;
return data;
}
Expand Down
8 changes: 0 additions & 8 deletions h2/src/main/org/h2/index/Index.java
Expand Up @@ -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);
Expand Down
18 changes: 6 additions & 12 deletions h2/src/main/org/h2/jdbc/meta/DatabaseMetaLocal.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Constraint> constraints = t.getConstraints();
Expand Down Expand Up @@ -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<Constraint> constraints = t.getConstraints();
Expand Down Expand Up @@ -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<Constraint> constraints = t.getConstraints();
Expand Down Expand Up @@ -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<Constraint> constraints = t.getConstraints();
Expand Down Expand Up @@ -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<Constraint> constraints = t.getConstraints();
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 7 additions & 9 deletions h2/src/main/org/h2/mode/FunctionsPostgreSQL.java
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7e780f6

Please sign in to comment.