private static boolean indexesAreDups ( Index idx1 , Index idx2 ) { // same attributes? if ( idx1 . getType ( ) != idx2 . getType ( ) ) { return false ; } if ( idx1 . getCountable ( ) != idx2 . getCountable ( ) ) { return false ; } if ( idx1 . getUnique ( ) != idx2 . getUnique ( ) ) { return false ; } if ( idx1 . getAssumeunique ( ) != idx2 . getAssumeunique ( ) ) { return false ; } // same column count? if ( idx1 . getColumns ( ) . size ( ) != idx2 . getColumns ( ) . size ( ) ) { return false ; } //TODO: For index types like HASH that support only random access vs. scanned ranges, indexes on different // permutations of the same list of columns/expressions could be considered dupes. This code skips that edge // case optimization in favor of using a simpler more exact permutation-sensitive algorithm for all indexes. if ( ! ( idx1 . getExpressionsjson ( ) . equals ( idx2 . getExpressionsjson ( ) ) ) ) { return false ; } // Simple column indexes have identical empty expression strings so need to be distinguished other ways. // More complex expression indexes that have the same expression strings always have the same set of (base) // columns referenced in the same order, but we fall through and check them, anyway. // sort in index order the columns of idx1, each identified by its index in the base table int [ ] idx1baseTableOrder = new int [ idx1 . getColumns ( ) . size ( ) ] ; for ( ColumnRef cref : idx1 . getColumns ( ) ) { int index = cref . getIndex ( ) ; int baseTableIndex = cref . getColumn ( ) . getIndex ( ) ; idx1baseTableOrder [ index ] = baseTableIndex ; } // sort in index order the columns of idx2, each identified by its index in the base table int [ ] idx2baseTableOrder = new int [ idx2 . getColumns ( ) . size ( ) ] ; for ( ColumnRef cref : idx2 . getColumns ( ) ) { int index = cref . getIndex ( ) ; int baseTableIndex = cref . getColumn ( ) . getIndex ( ) ; idx2baseTableOrder [ index ] = baseTableIndex ; } // Duplicate indexes have identical columns in identical order. if ( ! Arrays . equals ( idx1baseTableOrder , idx2baseTableOrder ) ) { return false ; } // Check the predicates if ( idx1 . getPredicatejson ( ) . length ( ) > 0 ) { return idx1 . getPredicatejson ( ) . equals ( idx2 . getPredicatejson ( ) ) ; } if ( idx2 . getPredicatejson ( ) . length ( ) > 0 ) { return idx2 . getPredicatejson ( ) . equals ( idx1 . getPredicatejson ( ) ) ; } return true ; }
Return true if the two indexes are identical with a different name .