Skip to content

Commit

Permalink
Fix the bug in getIndexInfo for mysql (#14750)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavbhole authored Aug 4, 2023
1 parent 3335040 commit d31c04c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -864,13 +864,7 @@ public Void withHandle(Handle handle) throws Exception
{
DatabaseMetaData databaseMetaData = handle.getConnection().getMetaData();
// Fetch the index for given table
ResultSet resultSet = databaseMetaData.getIndexInfo(
null,
null,
StringUtils.toUpperCase(tableName),
false,
false
);
ResultSet resultSet = getIndexInfo(databaseMetaData, tableName);
while (resultSet.next()) {
String indexName = resultSet.getString("INDEX_NAME");
if (org.apache.commons.lang.StringUtils.isNotBlank(indexName)) {
Expand All @@ -887,6 +881,24 @@ public Void withHandle(Handle handle) throws Exception
return ImmutableSet.copyOf(res);
}

/**
* Get the ResultSet for indexInfo for given table
*
* @param databaseMetaData DatabaseMetaData
* @param tableName Name of table
* @return ResultSet with index info
*/
public ResultSet getIndexInfo(DatabaseMetaData databaseMetaData, String tableName) throws SQLException
{
return databaseMetaData.getIndexInfo(
null,
null,
tableName, // tableName is case-sensitive in mysql default setting
false,
false
);
}

/**
* create index on the table with retry if not already exist, to be called after createTable
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ public Void withHandle(Handle handle)
);
}

/**
* Get the ResultSet for indexInfo for given table
*
* @param databaseMetaData DatabaseMetaData
* @param tableName Name of table
* @return ResultSet with index info
*/
@Override
public ResultSet getIndexInfo(DatabaseMetaData databaseMetaData, String tableName) throws SQLException
{
return databaseMetaData.getIndexInfo(
null,
null,
StringUtils.toUpperCase(tableName), // tableName needs to be uppercase in derby default setting
false,
false
);
}
@LifecycleStart
public void start()
{
Expand Down

0 comments on commit d31c04c

Please sign in to comment.