Mercurial > hg > orthanc-databases
changeset 503:a164d8aebe0e
merge improve-mysql-delete -> default
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Fri, 03 May 2024 16:23:36 +0200 |
parents | bf4b9c7cf338 (current diff) d0dd95ff0662 (diff) |
children | fe1897618c08 |
files | MySQL/CMakeLists.txt MySQL/NEWS MySQL/Plugins/MySQLIndex.cpp TODO |
diffstat | 5 files changed, 69 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/MySQL/CMakeLists.txt Fri May 03 16:22:02 2024 +0200 +++ b/MySQL/CMakeLists.txt Fri May 03 16:23:36 2024 +0200 @@ -90,6 +90,7 @@ MYSQL_PREPARE_INDEX ${CMAKE_SOURCE_DIR}/Plugins/PrepareIndex.sql MYSQL_GET_LAST_CHANGE_INDEX ${CMAKE_SOURCE_DIR}/Plugins/GetLastChangeIndex.sql MYSQL_CREATE_INSTANCE ${CMAKE_SOURCE_DIR}/Plugins/CreateInstance.sql + MYSQL_DELETE_RESOURCES ${CMAKE_SOURCE_DIR}/Plugins/DeleteResources.sql ) if (EXISTS ${ORTHANC_SDK_ROOT}/orthanc/OrthancDatabasePlugin.proto)
--- a/MySQL/NEWS Fri May 03 16:22:02 2024 +0200 +++ b/MySQL/NEWS Fri May 03 16:23:36 2024 +0200 @@ -7,7 +7,8 @@ Optimal Orthanc runtime: 1.12.0+ * Fix check of Orthanc runtime version - +* Introduced a procedure to delete resources + (to be tested: https://discourse.orthanc-server.org/t/image-insert-are-too-slow-databse-performance-too-poor-when-using-mysql-mariadb/3820/19) Release 5.1 (2023-06-27) ========================
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MySQL/Plugins/DeleteResources.sql Fri May 03 16:23:36 2024 +0200 @@ -0,0 +1,23 @@ +DROP PROCEDURE IF EXISTS DeleteResources; + +CREATE PROCEDURE DeleteResources( + IN p_id BIGINT +) +BEGIN + DECLARE v_internalId BIGINT@ + DECLARE done INT DEFAULT FALSE@ + DECLARE cur1 CURSOR FOR + SELECT internalId FROM DeletedResources@ + DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE@ + set done=FALSE@ + + OPEN cur1@ + REPEAT + FETCH cur1 INTO v_internalId@ + IF NOT done THEN + DELETE FROM Resources WHERE internalId=v_internalId@ + END IF@ + UNTIL done END REPEAT@ + CLOSE cur1@ + +END; \ No newline at end of file
--- a/MySQL/Plugins/MySQLIndex.cpp Fri May 03 16:22:02 2024 +0200 +++ b/MySQL/Plugins/MySQLIndex.cpp Fri May 03 16:23:36 2024 +0200 @@ -317,7 +317,27 @@ t.Commit(); } - if (revision != 7) + if (revision == 7) + { + DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); + + // Install the "CreateInstance" extension + std::string query; + + Orthanc::EmbeddedResources::GetFileResource + (query, Orthanc::EmbeddedResources::MYSQL_DELETE_RESOURCES); + + // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here + db.ExecuteMultiLines(query, true); + + revision = 8; + SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); + + t.Commit(); + } + + + if (revision != 8) { LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision; throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); @@ -471,11 +491,25 @@ lookupResourcesToDelete.Execute(args); } + // { + // DatabaseManager::CachedStatement deleteHierarchy( + // STATEMENT_FROM_HERE, manager, + // "DELETE FROM Resources WHERE internalId IN (SELECT internalId FROM DeletedResources)"); + // deleteHierarchy.Execute(); + // } + + { - DatabaseManager::CachedStatement deleteHierarchy( + DatabaseManager::CachedStatement deleteResources( STATEMENT_FROM_HERE, manager, - "DELETE FROM Resources WHERE internalId IN (SELECT internalId FROM DeletedResources)"); - deleteHierarchy.Execute(); + "CALL DeleteResources(${id})"); + + deleteResources.SetParameterType("id", ValueType_Integer64); + + Dictionary args; + args.SetIntegerValue("id", id); + + deleteResources.Execute(args); } SignalDeletedResources(output, manager);
--- a/TODO Fri May 03 16:22:02 2024 +0200 +++ b/TODO Fri May 03 16:23:36 2024 +0200 @@ -10,6 +10,11 @@ * Performance of joins in LookupResources: Create cached statement for LookupResources, that are grouped to search up to, say, 10 tags, instead of recompiling for each request +* Do not log "DatabaseCannotSerialize" errors in the plugin but only + in Orthanc after all retries have been made. +* Try to avoid the use of temporary tables: + https://discourse.orthanc-server.org/t/image-insert-are-too-slow-databse-performance-too-poor/3820 + * Implement "large queries" for: - updating all metadata of a resource at once