Skip to content
Snippets Groups Projects
Verified Commit 0820b276 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: String IDs

parent 5226c269
No related branches found
No related tags found
3 merge requests!17Release 6.0,!15External String IDs,!11DRAFT: file system cleanup
Pipeline #41246 failed
...@@ -10,7 +10,7 @@ DROP PROCEDURE IF EXISTS setPassword; ...@@ -10,7 +10,7 @@ DROP PROCEDURE IF EXISTS setPassword;
-- new entity_ids table -- new entity_ids table
DROP TABLE IF EXISTS `entity_ids`; DROP TABLE IF EXISTS `entity_ids`;
CREATE TABLE `entity_ids` ( CREATE TABLE `entity_ids` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id` int(10) unsigned NOT NULL,
`internal_id` int(10) unsigned NOT NULL COMMENT 'Internal ID of an entity. This id is used internally in the *_data tables and elsewhere. This ID is never exposed via the CaosDB API.', `internal_id` int(10) unsigned NOT NULL COMMENT 'Internal ID of an entity. This id is used internally in the *_data tables and elsewhere. This ID is never exposed via the CaosDB API.',
PRIMARY KEY `entity_ids_pk` (`id`), PRIMARY KEY `entity_ids_pk` (`id`),
CONSTRAINT `entity_ids_internal_id` FOREIGN KEY (`internal_id`) REFERENCES `entities` (`id`) CONSTRAINT `entity_ids_internal_id` FOREIGN KEY (`internal_id`) REFERENCES `entities` (`id`)
......
...@@ -38,15 +38,12 @@ parameter entity is a child or inside the rpath. ...@@ -38,15 +38,12 @@ parameter entity is a child or inside the rpath.
Parameters Parameters
========== ==========
EntityID : UNSIGNED InternalEntityID : UNSIGNED
Child entity for which all parental relations should be deleted. Child entity for which all parental relations should be deleted.
*/ */
CREATE PROCEDURE db_5_0.deleteIsa(IN EntityID INT UNSIGNED) CREATE PROCEDURE db_5_0.deleteIsa(IN InternalEntityID INT UNSIGNED)
BEGIN BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL; DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
SELECT max(_iversion) INTO IVersion SELECT max(_iversion) INTO IVersion
......
...@@ -27,7 +27,7 @@ DROP PROCEDURE IF EXISTS db_5_0.insert_single_child_version // ...@@ -27,7 +27,7 @@ DROP PROCEDURE IF EXISTS db_5_0.insert_single_child_version //
* *
* Parameters * Parameters
* ---------- * ----------
* EntityID * InternalEntityID
* The ID of the versioned entity. * The ID of the versioned entity.
* Hash * Hash
* A hash of the entity. This is currently not implemented properly and only * A hash of the entity. This is currently not implemented properly and only
...@@ -43,7 +43,7 @@ DROP PROCEDURE IF EXISTS db_5_0.insert_single_child_version // ...@@ -43,7 +43,7 @@ DROP PROCEDURE IF EXISTS db_5_0.insert_single_child_version //
* or updating an entity). * or updating an entity).
*/ */
CREATE PROCEDURE db_5_0.insert_single_child_version( CREATE PROCEDURE db_5_0.insert_single_child_version(
in EntityID INT UNSIGNED, in InternalEntityID INT UNSIGNED,
in Hash VARBINARY(255), in Hash VARBINARY(255),
in Version VARBINARY(255), in Version VARBINARY(255),
in Parent VARBINARY(255), in Parent VARBINARY(255),
...@@ -52,9 +52,6 @@ CREATE PROCEDURE db_5_0.insert_single_child_version( ...@@ -52,9 +52,6 @@ CREATE PROCEDURE db_5_0.insert_single_child_version(
BEGIN BEGIN
DECLARE newiversion INT UNSIGNED DEFAULT NULL; DECLARE newiversion INT UNSIGNED DEFAULT NULL;
DECLARE newipparent INT UNSIGNED DEFAULT NULL; DECLARE newipparent INT UNSIGNED DEFAULT NULL;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
-- find _ipparent -- find _ipparent
IF Parent IS NOT NULL THEN IF Parent IS NOT NULL THEN
...@@ -117,7 +114,7 @@ DROP FUNCTION IF EXISTS db_5_0.get_iversion // ...@@ -117,7 +114,7 @@ DROP FUNCTION IF EXISTS db_5_0.get_iversion //
* *
* Parameters * Parameters
* ---------- * ----------
* EntityID * InternalEntityID
* The entity's id. * The entity's id.
* Version * Version
* The (official, externally used) version id. * The (official, externally used) version id.
...@@ -127,15 +124,11 @@ DROP FUNCTION IF EXISTS db_5_0.get_iversion // ...@@ -127,15 +124,11 @@ DROP FUNCTION IF EXISTS db_5_0.get_iversion //
* The internal version id. * The internal version id.
*/ */
CREATE FUNCTION db_5_0.get_iversion( CREATE FUNCTION db_5_0.get_iversion(
EntityID INT UNSIGNED, InternalEntityID INT UNSIGNED,
Version VARBINARY(255)) Version VARBINARY(255))
RETURNS INT UNSIGNED RETURNS INT UNSIGNED
READS SQL DATA READS SQL DATA
BEGIN BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
RETURN ( RETURN (
SELECT e._iversion SELECT e._iversion
FROM entity_version AS e FROM entity_version AS e
...@@ -251,7 +244,7 @@ DROP FUNCTION IF EXISTS db_5_0._get_head_iversion // ...@@ -251,7 +244,7 @@ DROP FUNCTION IF EXISTS db_5_0._get_head_iversion //
* *
* Parameters * Parameters
* ---------- * ----------
* EntityID * InternalEntityID
* The entity id. * The entity id.
* *
* Returns * Returns
...@@ -259,14 +252,10 @@ DROP FUNCTION IF EXISTS db_5_0._get_head_iversion // ...@@ -259,14 +252,10 @@ DROP FUNCTION IF EXISTS db_5_0._get_head_iversion //
* The _iversion of the HEAD. * The _iversion of the HEAD.
*/ */
CREATE FUNCTION db_5_0._get_head_iversion( CREATE FUNCTION db_5_0._get_head_iversion(
EntityID INT UNSIGNED) InternalEntityID INT UNSIGNED)
RETURNS INT UNSIGNED RETURNS INT UNSIGNED
READS SQL DATA READS SQL DATA
BEGIN BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
-- This implementation assumes that the history is linear and the highest -- This implementation assumes that the history is linear and the highest
-- _iversion number is always the head. This will not be correct anymore -- _iversion number is always the head. This will not be correct anymore
-- as soon as branches may split and merge. Then, a walk over the primary -- as soon as branches may split and merge. Then, a walk over the primary
...@@ -330,7 +319,7 @@ DROP FUNCTION IF EXISTS db_5_0._get_version // ...@@ -330,7 +319,7 @@ DROP FUNCTION IF EXISTS db_5_0._get_version //
* *
* Parameters * Parameters
* ---------- * ----------
* EntityID * InternalEntityID
* The entity id. * The entity id.
* IVersion * IVersion
* Internal version id (integer). * Internal version id (integer).
...@@ -340,15 +329,11 @@ DROP FUNCTION IF EXISTS db_5_0._get_version // ...@@ -340,15 +329,11 @@ DROP FUNCTION IF EXISTS db_5_0._get_version //
* The version id. * The version id.
*/ */
CREATE FUNCTION db_5_0._get_version( CREATE FUNCTION db_5_0._get_version(
EntityID INT UNSIGNED, InternalEntityID INT UNSIGNED,
IVersion INT UNSIGNED) IVersion INT UNSIGNED)
RETURNS VARBINARY(255) RETURNS VARBINARY(255)
READS SQL DATA READS SQL DATA
BEGIN BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
RETURN ( RETURN (
SELECT version FROM entity_version SELECT version FROM entity_version
WHERE entity_id = InternalEntityID WHERE entity_id = InternalEntityID
...@@ -536,11 +521,7 @@ retrieveQueryTemplateDefBody: BEGIN ...@@ -536,11 +521,7 @@ retrieveQueryTemplateDefBody: BEGIN
END IF; END IF;
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
-- TODO Use get_iversion(EntityID, Version) instead? Or will that be much slower? SET IVersion = get_iversion(InternalEntityID, Version);
SELECT e._iversion INTO IVersion
FROM entity_version as e
WHERE e.entity_id = InternalEntityID
AND e.version = Version;
IF IVersion IS NULL THEN IF IVersion IS NULL THEN
-- RETURN EARLY - Version does not exist. -- RETURN EARLY - Version does not exist.
......
...@@ -44,11 +44,10 @@ ACL : VARBINARY(65525) ...@@ -44,11 +44,10 @@ ACL : VARBINARY(65525)
Select Select
====== ======
A tuple (EntityID, Version) (Version)
*/ */
CREATE PROCEDURE db_5_0.insertEntity(in EntityName VARCHAR(255), in EntityDesc TEXT, in EntityRole VARCHAR(255), in ACL VARBINARY(65525)) CREATE PROCEDURE db_5_0.insertEntity(in EntityID INT UNSIGNED, in EntityName VARCHAR(255), in EntityDesc TEXT, in EntityRole VARCHAR(255), in ACL VARBINARY(65525))
BEGIN BEGIN
DECLARE NewEntityID INT UNSIGNED DEFAULT NULL;
DECLARE NewACLID INT UNSIGNED DEFAULT NULL; DECLARE NewACLID INT UNSIGNED DEFAULT NULL;
DECLARE Hash VARBINARY(255) DEFAULT NULL; DECLARE Hash VARBINARY(255) DEFAULT NULL;
DECLARE Version VARBINARY(255) DEFAULT NULL; DECLARE Version VARBINARY(255) DEFAULT NULL;
...@@ -66,14 +65,13 @@ BEGIN ...@@ -66,14 +65,13 @@ BEGIN
-- ... and return the generated id -- ... and return the generated id
SET InternalEntityID = LAST_INSERT_ID(); SET InternalEntityID = LAST_INSERT_ID();
INSERT INTO entity_ids (internal_id) VALUES (InternalEntityID); INSERT INTO entity_ids (internal_id, id) VALUES (InternalEntityID, EntityID);
SET NewEntityID = LAST_INSERT_ID();
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
-- TODO this is transaction-scoped variable. Is this a good idea? -- TODO this is transaction-scoped variable. Is this a good idea?
SET Transaction = @SRID; SET Transaction = @SRID;
SET Version = SHA1(UUID()); SET Version = SHA1(UUID());
CALL insert_single_child_version(NewEntityID, Hash, Version, Null, Transaction); CALL insert_single_child_version(InternalEntityID, Hash, Version, Null, Transaction);
END IF; END IF;
-- insert the name of the entity into name_data table -- insert the name of the entity into name_data table
...@@ -84,7 +82,7 @@ BEGIN ...@@ -84,7 +82,7 @@ BEGIN
VALUES (0, InternalEntityID, 20, EntityName, "FIX", 0); VALUES (0, InternalEntityID, 20, EntityName, "FIX", 0);
END IF; END IF;
SELECT NewEntityID as EntityID, Version as Version; SELECT Version as Version;
END; END;
// //
......
...@@ -65,38 +65,43 @@ IF targetSet IS NULL OR targetSet = sourceSet THEN ...@@ -65,38 +65,43 @@ IF targetSet IS NULL OR targetSet = sourceSet THEN
"` WHERE ", "` WHERE ",
IF(o IS NULL OR vInt IS NULL, IF(o IS NULL OR vInt IS NULL,
"1=1", "1=1",
CONCAT("NOT id", CONCAT("NOT EXISTS (SELECT 1 FROM entity_ids AS eids WHERE eids.id ",
o, o,
vInt)), vInt,
" AND eids.internal_id = `",
sourceSet,
"`.id)"
)),
IF(aggVal IS NULL, IF(aggVal IS NULL,
"", "",
CONCAT(" AND id!=", CONCAT(" AND `", sourceSet, "`.id!=",
aggVal))); aggVal)));
ELSEIF versioned AND sourceSet = "entities" THEN ELSEIF versioned AND sourceSet = "entities" THEN
-- ################# VERSIONING ##################### -- ################# VERSIONING #####################
SET data = CONCAT( SET data = CONCAT(
"INSERT IGNORE INTO `", "INSERT IGNORE INTO `",
targetSet, targetSet,
'` (id, _iversion) SELECT id, _get_head_iversion(id) FROM `entities` WHERE ', '` (id, _iversion) SELECT e.id, _get_head_iversion(e.id) FROM `entities` AS e JOIN entity_ids AS eids ON (e.id = eids.internal_id) WHERE ',
IF(o IS NULL OR vInt IS NULL, IF(o IS NULL OR vInt IS NULL,
"1=1", "1=1",
CONCAT("id", CONCAT("eids.id ",
o, o,
vInt)), vInt
)),
IF(aggVal IS NULL, IF(aggVal IS NULL,
"", "",
CONCAT(" AND id=", CONCAT(" AND e.id=",
aggVal)), aggVal)),
' UNION SELECT id, _iversion FROM `archive_entities` WHERE ', ' UNION SELECT e.id, _iversion FROM `archive_entities` AS e JOIN entity_ids AS eids ON (e.id = eids.internal_id) WHERE ',
IF(o IS NULL OR vInt IS NULL, IF(o IS NULL OR vInt IS NULL,
"1=1", "1=1",
CONCAT("id", CONCAT("eids.id ",
o, o,
vInt)), vInt
)),
IF(aggVal IS NULL, IF(aggVal IS NULL,
"", "",
CONCAT(" AND id=", CONCAT(" AND e.id=",
aggVal))); aggVal)));
-- ################################################## -- ##################################################
...@@ -108,10 +113,10 @@ ELSE ...@@ -108,10 +113,10 @@ ELSE
'` (id, _iversion) SELECT data.id, data._iversion FROM `', '` (id, _iversion) SELECT data.id, data._iversion FROM `',
'` (id) SELECT data.id FROM `'), '` (id) SELECT data.id FROM `'),
sourceSet, sourceSet,
"` AS data WHERE ", "` AS data JOIN entity_ids AS eids ON (eids.internal_id = data.id) WHERE ",
IF(o IS NULL OR vInt IS NULL, IF(o IS NULL OR vInt IS NULL,
"1=1", "1=1",
CONCAT("data.id", CONCAT("eids.id",
o, o,
vInt)), vInt)),
IF(aggVal IS NULL, IF(aggVal IS NULL,
......
...@@ -25,7 +25,7 @@ DELIMITER // ...@@ -25,7 +25,7 @@ DELIMITER //
CREATE PROCEDURE db_5_0.applyTransactionFilter(in sourceSet VARCHAR(255), targetSet VARCHAR(255), in transaction VARCHAR(255), in operator_u CHAR(2), in realm VARCHAR(255), in userName VARCHAR(255), in ilb BIGINT, in ilb_nanos INT UNSIGNED, in eub BIGINT, in eub_nanos INT UNSIGNED, in operator_t CHAR(2)) CREATE PROCEDURE db_5_0.applyTransactionFilter(in sourceSet VARCHAR(255), targetSet VARCHAR(255), in transaction VARCHAR(255), in operator_u CHAR(2), in realm VARCHAR(255), in userName VARCHAR(255), in ilb BIGINT, in ilb_nanos INT UNSIGNED, in eub BIGINT, in eub_nanos INT UNSIGNED, in operator_t CHAR(2))
BEGIN BEGIN
DECLARE data TEXT default CONCAT('(SELECT entity_id FROM transaction_log AS t WHERE t.transaction=\'', DECLARE data TEXT default CONCAT('(SELECT internal_id AS entity_id FROM transaction_log AS t JOIN entity_ids AS eids ON ( t.entity_id = eids.id ) WHERE t.transaction=\'',
transaction, transaction,
'\'', '\'',
IF(userName IS NOT NULL, IF(userName IS NOT NULL,
......
...@@ -48,7 +48,7 @@ BEGIN ...@@ -48,7 +48,7 @@ BEGIN
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
IF e_id IS NOT NULL THEN IF e_id IS NOT NULL THEN
SET @stmtStr = CONCAT('INSERT IGNORE INTO `', tableName, '` (id) VALUES (', e_id, ')'); SET @stmtStr = CONCAT('INSERT IGNORE INTO `', tableName, '` (id) SELECT internal_id FROM entity_ids WHERE id = ', e_id, '');
PREPARE stmt FROM @stmtStr; PREPARE stmt FROM @stmtStr;
EXECUTE stmt; EXECUTE stmt;
SET ecount = ecount + ROW_COUNT(); SET ecount = ecount + ROW_COUNT();
......
...@@ -77,7 +77,7 @@ retrieveEntityBody: BEGIN ...@@ -77,7 +77,7 @@ retrieveEntityBody: BEGIN
SET IsHead = FALSE; SET IsHead = FALSE;
SET Version = get_head_relative(EntityID, SUBSTR(Version, 6)); SET Version = get_head_relative(EntityID, SUBSTR(Version, 6));
ELSE ELSE
SELECT get_head_version(InternalEntityID) = Version INTO IsHead; SELECT get_head_version(EntityID) = Version INTO IsHead;
END IF; END IF;
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
...@@ -155,10 +155,8 @@ retrieveEntityBody: BEGIN ...@@ -155,10 +155,8 @@ retrieveEntityBody: BEGIN
WHERE file_id = InternalEntityID WHERE file_id = InternalEntityID
LIMIT 1; LIMIT 1;
SELECT eids.id INTO DatatypeID SELECT dt.datatype INTO DatatypeID
FROM data_type as dt FROM data_type as dt
LEFT JOIN entity_ids eids
ON dt.datatype = eids.internal_id
WHERE dt.domain_id=0 WHERE dt.domain_id=0
AND dt.entity_id=0 AND dt.entity_id=0
AND dt.property_id=InternalEntityID AND dt.property_id=InternalEntityID
...@@ -174,7 +172,7 @@ retrieveEntityBody: BEGIN ...@@ -174,7 +172,7 @@ retrieveEntityBody: BEGIN
SELECT SELECT
( SELECT value FROM name_data ( SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_ID = DatatypeID AND entity_id = DatatypeID
AND property_id = 20 LIMIT 1 ) AS Datatype, AND property_id = 20 LIMIT 1 ) AS Datatype,
CollectionName AS Collection, CollectionName AS Collection,
EntityID AS EntityID, EntityID AS EntityID,
......
...@@ -65,7 +65,7 @@ retrieveEntityParentsBody: BEGIN ...@@ -65,7 +65,7 @@ retrieveEntityParentsBody: BEGIN
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN IF Version IS NOT NULL THEN
SELECT get_head_version(InternalEntityID) = Version INTO IsHead; SELECT get_head_version(EntityID) = Version INTO IsHead;
END IF; END IF;
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
......
...@@ -91,7 +91,7 @@ BEGIN ...@@ -91,7 +91,7 @@ BEGIN
WHERE e.entity_id = InternalEntityID WHERE e.entity_id = InternalEntityID
AND e._iversion = OldIVersion; AND e._iversion = OldIVersion;
CALL insert_single_child_version( CALL insert_single_child_version(
EntityID, Hash, Version, InternalEntityID, Hash, Version,
ParentVersion, Transaction); ParentVersion, Transaction);
END IF; END IF;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment