Skip to content

Commit

Permalink
Creation of Indexes with zero size
Browse files Browse the repository at this point in the history
  • Loading branch information
mfvanek committed Dec 7, 2024
1 parent ead152f commit afcf90c
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void onDatabaseWithThem(final String schemaName) {
.hasSize(1)
.containsExactly(
DuplicatedIndexes.of(
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("accounts_account_number_key"), 0L),
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"), 0L)))
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("accounts_account_number_key")),
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"))))
.allMatch(d -> d.getTotalSize() >= 16_384L);

assertThat(check)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ void onDatabaseWithThem(final String schemaName) {
.hasSize(2)
.containsExactly(
DuplicatedIndexes.of(
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted"), 0L),
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"), 0L)
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted")),
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"))
),
DuplicatedIndexes.of(
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L),
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L)))
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")),
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"))))
.allMatch(d -> d.getTotalSize() >= 106_496L);

assertThat(check)
Expand All @@ -75,8 +75,8 @@ void shouldFindHashIndex(final String schemaName) {
.hasSize(1)
.containsExactly(
DuplicatedIndexes.of(
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L),
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L)))
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")),
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"))))
.allMatch(d -> d.getTotalSize() >= 106_496L);

assertThat(check)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ void onDatabaseWithThem(final String schemaName) {
.executing(ctx)
.hasSize(6)
.containsExactlyInAnyOrder(
UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted"), 0L, 0))
UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")),
UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name")),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number")),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted")),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted")),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted")))
.allMatch(i -> i.getIndexSizeInBytes() > 0L)
.allMatch(i -> i.getIndexScans() == 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,18 @@ public static IndexWithSize of(@Nonnull final String tableName,
final long indexSizeInBytes) {
return new IndexWithSize(tableName, indexName, indexSizeInBytes);
}

/**
* Constructs an {@code IndexWithSize} object with zero size.
*
* @param tableName table name; should be non-blank.
* @param indexName index name; should be non-blank.
* @return {@code IndexWithSize}
* @since 0.14.3
*/
@Nonnull
public static IndexWithSize of(@Nonnull final String tableName,
@Nonnull final String indexName) {
return new IndexWithSize(tableName, indexName, 0L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,24 @@ public String toString() {
* @throws NullPointerException if {@code tableName} or {@code indexName} is null
* @throws IllegalArgumentException if {@code indexScans} is negative
*/
@Nonnull
public static UnusedIndex of(@Nonnull final String tableName,
@Nonnull final String indexName,
final long indexSizeInBytes,
final long indexScans) {
return new UnusedIndex(tableName, indexName, indexSizeInBytes, indexScans);
}

/**
* Creates a new {@code UnusedIndex} instance with zero size.
*
* @param tableName the name of the table associated with the index, must be non-null
* @param indexName the name of the index, must be non-null
* @return a new {@code UnusedIndex} instance
*/
@Nonnull
public static UnusedIndex of(@Nonnull final String tableName,
@Nonnull final String indexName) {
return new UnusedIndex(tableName, indexName, 0L, 0L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ public static Table of(@Nonnull final String tableName, final long tableSizeInBy

/**
* Constructs a {@code Table} object with zero size.
*
* @param tableName table name; should be non-blank.
* @return {@code Table}
* @since 0.14.3
*/
@Nonnull
public static Table of(@Nonnull final String tableName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IndexWithSizeTest {

@Test
void indexWithZeroSize() {
final IndexWithSize index = IndexWithSize.of("t", "i", 0L);
final IndexWithSize index = IndexWithSize.of("t", "i");
assertThat(index.getIndexName())
.isEqualTo("i")
.isEqualTo(index.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ void getIndexScans() {
void testToString() {
assertThat(UnusedIndex.of("t", "i", 1L, 2L))
.hasToString("UnusedIndex{tableName='t', indexName='i', " + "indexSizeInBytes=1, indexScans=2}");

assertThat(UnusedIndex.of("t", "i"))
.hasToString("UnusedIndex{tableName='t', indexName='i', " + "indexSizeInBytes=0, indexScans=0}");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void onDatabaseWithThem(final String schemaName) {
.hasSize(1)
.containsExactly(
DuplicatedIndexes.of(
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("accounts_account_number_key"), 0L),
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"), 0L)))
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("accounts_account_number_key")),
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"))))
.allMatch(d -> d.getTotalSize() >= 16_384L);

assertThat(check)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ void onDatabaseWithThem(final String schemaName) {
.hasSize(2)
.containsExactly(
DuplicatedIndexes.of(
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted"), 0L),
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"), 0L)
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted")),
IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"))
),
DuplicatedIndexes.of(
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L),
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L)))
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")),
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"))))
.allMatch(d -> d.getTotalSize() >= 106_496L);

assertThat(check)
Expand All @@ -74,8 +74,8 @@ void shouldFindHashIndex(final String schemaName) {
.hasSize(1)
.containsExactly(
DuplicatedIndexes.of(
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L),
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L)))
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")),
IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"))))
.allMatch(d -> d.getTotalSize() >= 106_496L);

assertThat(check)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ void onDatabaseWithThem(final String schemaName) {
.executing(ctx)
.hasSize(6)
.containsExactlyInAnyOrder(
UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted"), 0L, 0),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted"), 0L, 0))
UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")),
UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name")),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number")),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted")),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted")),
UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted")))
.allMatch(i -> i.getIndexSizeInBytes() > 0L)
.allMatch(i -> i.getIndexScans() == 0);

Expand Down

0 comments on commit afcf90c

Please sign in to comment.