[jOOQ/jOOQ#14371] Slow TableAlias::equals implementation, when argument type is TableImpl

This commit is contained in:
Lukas Eder 2023-03-02 16:05:31 +01:00
parent 9fb447315f
commit 4838334495
2 changed files with 39 additions and 9 deletions

View File

@ -62,7 +62,13 @@ import org.jetbrains.annotations.NotNull;
/**
* @author Lukas Eder
*/
final class TableAlias<R extends Record> extends AbstractTable<R> implements QOM.TableAlias<R>, SimpleCheckQueryPart {
final class TableAlias<R extends Record>
extends
AbstractTable<R>
implements
QOM.TableAlias<R>,
SimpleCheckQueryPart
{
final Alias<Table<R>> alias;
transient FieldsImpl<R> aliasedFields;
@ -223,9 +229,22 @@ final class TableAlias<R extends Record> extends AbstractTable<R> implements QOM
@Override
public boolean equals(Object that) {
if (that instanceof TableAlias)
return getUnqualifiedName().equals(((TableAlias<?>) that).getUnqualifiedName());
else
return super.equals(that);
if (this == that)
return true;
if (that instanceof TableAlias<?> t)
return getUnqualifiedName().equals(t.getUnqualifiedName());
// [#14371] Unqualified TableImpls can be equal to TableAlias
if (that instanceof TableImpl<?> t) {
if (t.$alias() != null)
return getUnqualifiedName().equals(t.$alias());
// [#7172] [#10274] Cannot use getQualifiedName() yet here
else if (t.getSchema() == null)
return getUnqualifiedName().equals(t.getQualifiedName());
}
return super.equals(that);
}
}

View File

@ -530,16 +530,27 @@ implements
// [#2144] TableImpl equality can be decided without executing the
// rather expensive implementation of AbstractQueryPart.equals()
if (that instanceof TableImpl<?> other) {
if (that instanceof TableImpl<?> t) {
return
// [#7172] [#10274] Cannot use getQualifiedName() yet here
StringUtils.equals(
defaultIfNull(getSchema(), DEFAULT_SCHEMA),
defaultIfNull(other.getSchema(), DEFAULT_SCHEMA)
defaultIfNull(t.getSchema(), DEFAULT_SCHEMA)
) &&
StringUtils.equals(getName(), other.getName()) &&
Arrays.equals(parameters, other.parameters);
StringUtils.equals(getName(), t.getName()) &&
Arrays.equals(parameters, t.parameters);
}
// [#14371] Unqualified TableImpls can be equal to TableAlias
else if (that instanceof TableAlias<?> t) {
if ($alias() != null)
return t.getUnqualifiedName().equals($alias());
// [#7172] [#10274] Cannot use getQualifiedName() yet here
else if (getSchema() == null)
return t.getUnqualifiedName().equals(getQualifiedName());
}
return super.equals(that);