-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix overlapping index checking #117
Conversation
Raveline
commented
Oct 9, 2024
- Ensure we check only overlap on the current table and not the whole schema each time we check a table;
- Exclude local indexes;
- Make sure PK are not taken into account;
- Fix test (it was passing for the wrong reasons);
- Ensure we check only overlap on the current table - Exclude local indexes - Make sure PK are not taken into account
, " indisunique" | ||
, " AND other_indisunique" | ||
, " AND colindex = colotherindex" | ||
, ");" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marco44 : OK for you ? (Could you please confirm l. 227 and l. 205 seem ok ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok to me
, " indisunique" | ||
, " AND other_indisunique" | ||
, " AND colindex = colotherindex" | ||
, ");" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok to me
@@ -190,8 +190,8 @@ objectHasMore otype ptype extra = | |||
arrListTable :: RawSQL () -> Text | |||
arrListTable tableName = " ->" <+> unRawSQL tableName <> ": " | |||
|
|||
checkOverlappingIndexesQuery :: SQL | |||
checkOverlappingIndexesQuery = | |||
checkOverlappingIndexesQuery :: SQL -> SQL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkOverlappingIndexesQuery :: SQL -> SQL | |
checkOverlappingIndexesQuery :: RawSQL () -> SQL |
@@ -508,7 +508,7 @@ checkDBStructure options tables = fmap mconcat . forM tables $ \(table, version) | |||
runQuery_ $ sqlGetForeignKeys table | |||
fkeys <- fetchMany fetchForeignKey | |||
triggers <- getDBTriggers tblName | |||
checkedOverlaps <- checkOverlappingIndexes | |||
checkedOverlaps <- checkOverlappingIndexes (mkSQL . T.pack $ tblNameString table) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkedOverlaps <- checkOverlappingIndexes (mkSQL . T.pack $ tblNameString table) | |
checkedOverlaps <- checkOverlappingIndexes (tblName table) |
And pass RawSQL ()
around and inside checkOverlappingIndexesQuery
you can use raw
function to convert from RawSQL ()
to SQL
. AFAIR this is the general theme of how using RawSQL in constructing SQLs throughout the library is done, so let's be consistent.
@@ -201,7 +201,8 @@ checkOverlappingIndexesQuery = | |||
, " , ((regexp_match(pg_get_indexdef(indexrelid)" | |||
, " , 'WHERE (.*)$')))[1] AS preddef" | |||
, " FROM pg_index" | |||
, " WHERE indexprs IS NULL)" | |||
, " WHERE indexprs IS NULL" | |||
, " AND indrelid = '" <> tableName <> "'::regclass)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
, " AND indrelid = '" <> tableName <> "'::regclass)" | |
, " AND indrelid = '" <> raw tableName <> "'::regclass)" |
@@ -714,8 +714,8 @@ checkDBStructure options tables = fmap mconcat . forM tables $ \(table, version) | |||
\expected output into source code.)" | |||
] | |||
|
|||
checkOverlappingIndexes :: MonadDB m => m ValidationResult | |||
checkOverlappingIndexes = | |||
checkOverlappingIndexes :: MonadDB m => SQL -> m ValidationResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkOverlappingIndexes :: MonadDB m => SQL -> m ValidationResult | |
checkOverlappingIndexes :: MonadDB m => RawSQL () -> m ValidationResult |
This has been tested against https://github.com/scrive/kontrakcja/pull/7335 with no problems. Are we ok to merge @arybczak ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge, thanks 👍