-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rule to check for duplicate indexes. Two indexes are duplicates if they have different relation OID and are indexes for the same relation and has *exactly* the same list of keys in the same order. Note that we are not checking if an index is redundant (if one index has a set of key columns that is a prefix of the other). Resolves #42
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2023 Timescale, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Unit tests for index checking rules.""" | ||
|
||
from timescaledb import Table | ||
|
||
from doctor.unittest import PostgreSQLTestCase | ||
from doctor.rules.index import DuplicateIndex | ||
|
||
class TestIndexRules(PostgreSQLTestCase): | ||
"""Test index checking rules.""" | ||
|
||
def setUp(self): | ||
"""Set up unit tests for index checking rules.""" | ||
table = Table("with_duplicate_index", { | ||
"one": "int", | ||
"two": "int", | ||
}) | ||
table.create(self.connection) | ||
|
||
with self.connection.cursor() as cursor: | ||
cursor.execute("CREATE INDEX index_one ON with_duplicate_index(one,two)") | ||
cursor.execute("CREATE INDEX index_two ON with_duplicate_index(one,two)") | ||
self.connection.commit() | ||
|
||
def tearDown(self): | ||
"""Tear down unit tests for index checking rules.""" | ||
with self.connection.cursor() as cursor: | ||
cursor.execute("DROP TABLE with_duplicate_index") | ||
self.connection.commit() | ||
|
||
def test_duplicate(self): | ||
"""Test rule for detecting duplicate index.""" | ||
messages = [] | ||
messages.extend(self.run_rule(DuplicateIndex())) | ||
self.assertIn(DuplicateIndex.message.format(index1="index_one", index2="index_two"), | ||
messages) |