diff --git a/jOOQ-meta/src/main/java/org/jooq/meta/mysql/MySQLDatabase.java b/jOOQ-meta/src/main/java/org/jooq/meta/mysql/MySQLDatabase.java index 15d415f166..beadfb8b90 100644 --- a/jOOQ-meta/src/main/java/org/jooq/meta/mysql/MySQLDatabase.java +++ b/jOOQ-meta/src/main/java/org/jooq/meta/mysql/MySQLDatabase.java @@ -41,8 +41,6 @@ package org.jooq.meta.mysql; import static org.jooq.impl.DSL.falseCondition; import static org.jooq.impl.DSL.inline; import static org.jooq.impl.DSL.noCondition; -import static org.jooq.impl.DSL.row; -import static org.jooq.impl.DSL.select; import static org.jooq.meta.mysql.information_schema.Tables.CHECK_CONSTRAINTS; import static org.jooq.meta.mysql.information_schema.Tables.COLUMNS; import static org.jooq.meta.mysql.information_schema.Tables.KEY_COLUMN_USAGE; @@ -91,6 +89,7 @@ import org.jooq.meta.SchemaDefinition; import org.jooq.meta.SequenceDefinition; import org.jooq.meta.TableDefinition; import org.jooq.meta.UDTDefinition; +import org.jooq.meta.mariadb.MariaDBDatabase; import org.jooq.meta.mysql.information_schema.tables.CheckConstraints; import org.jooq.meta.mysql.information_schema.tables.Columns; import org.jooq.meta.mysql.information_schema.tables.KeyColumnUsage; @@ -116,6 +115,15 @@ public class MySQLDatabase extends AbstractDatabase { protected List getIndexes0() throws SQLException { List result = new ArrayList<>(); + // Workaround for MemSQL bug + // https://www.memsql.com/forum/t/wrong-query-result-on-information-schema-query/1423/2 + Table from = getIncludeSystemIndexes() + ? STATISTICS + : STATISTICS.leftJoin(TABLE_CONSTRAINTS) + .on(Statistics.INDEX_SCHEMA.eq(TableConstraints.CONSTRAINT_SCHEMA)) + .and(Statistics.TABLE_NAME.eq(TableConstraints.TABLE_NAME)) + .and(Statistics.INDEX_NAME.eq(TableConstraints.CONSTRAINT_NAME)); + // Same implementation as in H2Database and HSQLDBDatabase Map> indexes = create() // [#2059] In MemSQL primary key indexes are typically duplicated @@ -127,7 +135,7 @@ public class MySQLDatabase extends AbstractDatabase { Statistics.NON_UNIQUE, Statistics.COLUMN_NAME, Statistics.SEQ_IN_INDEX) - .from(STATISTICS) + .from(from) // [#5213] Duplicate schema value to work around MySQL issue https://bugs.mysql.com/bug.php?id=86022 .where(Statistics.TABLE_SCHEMA.in(getInputSchemata()).or( getInputSchemata().size() == 1 @@ -135,10 +143,7 @@ public class MySQLDatabase extends AbstractDatabase { : falseCondition())) .and(getIncludeSystemIndexes() ? noCondition() - : row(Statistics.INDEX_SCHEMA, Statistics.INDEX_NAME).notIn( - select(TableConstraints.CONSTRAINT_SCHEMA, TableConstraints.CONSTRAINT_NAME) - .from(TABLE_CONSTRAINTS) - ) + : TableConstraints.CONSTRAINT_NAME.isNull() ) .orderBy( Statistics.TABLE_SCHEMA, @@ -352,11 +357,20 @@ public class MySQLDatabase extends AbstractDatabase { ) .from(TABLE_CONSTRAINTS) .join(CHECK_CONSTRAINTS) - .using( - TableConstraints.CONSTRAINT_CATALOG, - TableConstraints.CONSTRAINT_SCHEMA, - TableConstraints.TABLE_NAME, - TableConstraints.CONSTRAINT_NAME) + .using(this instanceof MariaDBDatabase + ? new Field[] { + TableConstraints.CONSTRAINT_CATALOG, + TableConstraints.CONSTRAINT_SCHEMA, + // MariaDB has this column, but not MySQL + TableConstraints.TABLE_NAME, + TableConstraints.CONSTRAINT_NAME + } + : new Field[] { + TableConstraints.CONSTRAINT_CATALOG, + TableConstraints.CONSTRAINT_SCHEMA, + TableConstraints.CONSTRAINT_NAME + } + ) .where(TableConstraints.TABLE_SCHEMA.in(getInputSchemata())) .orderBy( TableConstraints.TABLE_SCHEMA,