Bug #7081 JDBC getIndexInfo() bug or misread?
Submitted: 7 Dec 2004 18:29 Modified: 7 Dec 2004 19:26
Reporter: Mark Matthews Email Updates:
Status: Closed Impact on me:
Category:Connector / J Severity:S2 (Serious)
Version:3.0.16 OS:
Assigned to: Mark Matthews CPU Architecture:Any

[7 Dec 2004 18:29] Mark Matthews
It appears that when the unique argument to
getIndexInfo is set to "true", that index of column
containing non-unique values is also returned. I need
to be able to determine programmatically, which
columns only allow unique values.

The exact method used is:

public ResultSet getIndexInfo(String catalog,
                              String schema,
                              String table,
                              boolean unique,
                              boolean approximate)
                       throws SQLException

The Sun JDBC API documentation says:

unique - when true, return only indices for unique
values; when false, return indices regardless of
whether unique or not

Is returning an index for a column with non-unique
values when unique is set to "true" the correct
behaviour or a bug?

Using version 4.0.18-nt of MySQL.


How to repeat:
public void testNonUniqueBug() throws Exception {
    	try {
    		this.stmt.executeUpdate("DROP TABLE IF EXISTS testNonUniqueBug");
    		this.stmt.executeUpdate("CREATE TABLE testNonUniqueBug(field1 INT, INDEX(field1))");
    		DatabaseMetaData dbmd = this.conn.getMetaData();
    		this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null, "testNonUniqueBug", true, false);
    		assertTrue(!this.rs.next()); // there should be no rows that meet this requirement
    		this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null, "testNonUniqueBug", false, false);
    		assertTrue(this.rs.next()); // there should be one row that meets this requirement
    	} finally {
    		this.stmt.executeUpdate("DROP TABLE IF EXISTS testNonUniqueBug");
[7 Dec 2004 19:26] Mark Matthews
This is fixed in our source repository, and will be available in 3.0.17, and has already been merged into 3.1.x and 3.2.x.

You can check out a nightly build after 00:00 GMT this evening from http://downloads.mysql.com/snapshots.php if you want to test before the release of 3.0.17.

Thanks for your bug report.