Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions sql-migrations/all/2024-07-16-00-33-13-create-statistics.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
CREATE STATISTICS IF NOT EXISTS test_stat_expr
( dependencies,mcv) ON employee_id, lower(employee_name)
FROM employee ;
CREATE STATISTICS IF NOT EXISTS test_stat
( dependencies,ndistinct,mcv) ON employee_id, employee_name
FROM employee ;

CREATE STATISTICS IF NOT EXISTS test_stat_with_expr
( dependencies,ndistinct,mcv) ON id, (lower(popular_name)), popular_name, (id*42)
FROM animals;

-- This file has CRLF line endings, just another test
--
CREATE STATISTICS IF NOT EXISTS test_stat_expr
( dependencies,mcv) ON employee_id, lower(employee_name)
FROM employee ;
CREATE STATISTICS IF NOT EXISTS test_stat
( dependencies,ndistinct,mcv) ON employee_id, employee_name
FROM employee ;

CREATE STATISTICS IF NOT EXISTS test_stat_with_expr
( dependencies,ndistinct,mcv) ON id, (lower(popular_name)), popular_name, (id*42)
FROM animals;

6 changes: 5 additions & 1 deletion src/Codd/AppCommands/AddMigration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,12 @@ addMigration dbInfo@Codd.CoddSettings {onDiskReps, migsConnString = defaultConnI
(pgMajorVer, _) <- queryServerMajorAndFullVersion conn
(pgMajorVer,) <$> readRepresentationsFromDbWithSettings dbInfo conn
)
addedMigRequiresCoddSchema <- liftIO $ checkCoddSchemaFunctionsHaveBeenCalled listenConn
-- Different connections means different sockets, which means we have to fetch
-- some query results _before_ `checkCoddSchemaFunctionsHaveBeenCalled`, because
-- that checks if a notification was received non-blocking, and that can return
-- no notifications unless we fetch something on "listenConn" first.
newlyStartedJobs <- getAddedJobsStillRunning listenConn maxBackgroundJobIdBefore
addedMigRequiresCoddSchema <- liftIO $ checkCoddSchemaFunctionsHaveBeenCalled listenConn
closeFileStream migStream
pure (pgVerAndSchemas, addedMigRequiresCoddSchema, newlyStartedJobs)
persistRepsToDisk pgMajorVer databaseSchemas onDiskRepsDir
Expand Down
4 changes: 2 additions & 2 deletions test/DbDependentSpecs/BackgroundJobsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ spec = do
lastRunAt startedCoddJob `shouldNotBe` Nothing
completedOrAbortedAt startedCoddJob `shouldBe` Nothing
finalizedAt startedCoddJob `shouldBe` Nothing
(allEmployees :: [(String, String)], finalizedCoddJob :: JobInfo, scheduledCronJobs :: [String]) <-
(allEmployees :: [(String, String)], finalizedCoddJob :: JobInfo, scheduledCronJobs :: [DB.Only String]) <-
applyMigrationsNoCheck
testDbInfo {txnIsolationLvl = txnIsolationLvl}
(Just [finalizeExperienceMigration])
Expand Down Expand Up @@ -274,7 +274,7 @@ spec = do
-- it to conflict with itself.
-- The call to applyMigrationsNoCheck below deadlocks unless codd's schema has carefully designed locks
-- in its functions.
(allEmployees :: [(String, String)], finalizedCoddJob :: JobInfo, scheduledCronJobs :: [String]) <-
(allEmployees :: [(String, String)], finalizedCoddJob :: JobInfo, scheduledCronJobs :: [DB.Only String]) <-
applyMigrationsNoCheck
testDbInfo {txnIsolationLvl = txnIsolationLvl}
(Just [finalizeExperienceMigration])
Expand Down
Loading