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

WIP: String IDs

parent 5226c269
Branches
Tags
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;
-- new entity_ids table
DROP TABLE IF EXISTS `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.',
PRIMARY KEY `entity_ids_pk` (`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.
Parameters
==========
EntityID : UNSIGNED
InternalEntityID : UNSIGNED
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
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
SELECT max(_iversion) INTO IVersion
......
......@@ -27,7 +27,7 @@ DROP PROCEDURE IF EXISTS db_5_0.insert_single_child_version //
*
* Parameters
* ----------
* EntityID
* InternalEntityID
* The ID of the versioned entity.
* Hash
* 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 //
* or updating an entity).
*/
CREATE PROCEDURE db_5_0.insert_single_child_version(
in EntityID INT UNSIGNED,
in InternalEntityID INT UNSIGNED,
in Hash VARBINARY(255),
in Version VARBINARY(255),
in Parent VARBINARY(255),
......@@ -52,9 +52,6 @@ CREATE PROCEDURE db_5_0.insert_single_child_version(
BEGIN
DECLARE newiversion 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
IF Parent IS NOT NULL THEN
......@@ -117,7 +114,7 @@ DROP FUNCTION IF EXISTS db_5_0.get_iversion //
*
* Parameters
* ----------
* EntityID
* InternalEntityID
* The entity's id.
* Version
* The (official, externally used) version id.
......@@ -127,15 +124,11 @@ DROP FUNCTION IF EXISTS db_5_0.get_iversion //
* The internal version id.
*/
CREATE FUNCTION db_5_0.get_iversion(
EntityID INT UNSIGNED,
InternalEntityID INT UNSIGNED,
Version VARBINARY(255))
RETURNS INT UNSIGNED
READS SQL DATA
BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
RETURN (
SELECT e._iversion
FROM entity_version AS e
......@@ -251,7 +244,7 @@ DROP FUNCTION IF EXISTS db_5_0._get_head_iversion //
*
* Parameters
* ----------
* EntityID
* InternalEntityID
* The entity id.
*
* Returns
......@@ -259,14 +252,10 @@ DROP FUNCTION IF EXISTS db_5_0._get_head_iversion //
* The _iversion of the HEAD.
*/
CREATE FUNCTION db_5_0._get_head_iversion(
EntityID INT UNSIGNED)
InternalEntityID INT UNSIGNED)
RETURNS INT UNSIGNED
READS SQL DATA
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
-- _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
......@@ -330,7 +319,7 @@ DROP FUNCTION IF EXISTS db_5_0._get_version //
*
* Parameters
* ----------
* EntityID
* InternalEntityID
* The entity id.
* IVersion
* Internal version id (integer).
......@@ -340,15 +329,11 @@ DROP FUNCTION IF EXISTS db_5_0._get_version //
* The version id.
*/
CREATE FUNCTION db_5_0._get_version(
EntityID INT UNSIGNED,
InternalEntityID INT UNSIGNED,
IVersion INT UNSIGNED)
RETURNS VARBINARY(255)
READS SQL DATA
BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
RETURN (
SELECT version FROM entity_version
WHERE entity_id = InternalEntityID
......@@ -536,11 +521,7 @@ retrieveQueryTemplateDefBody: BEGIN
END IF;
IF IsHead IS FALSE THEN
-- TODO Use get_iversion(EntityID, Version) instead? Or will that be much slower?
SELECT e._iversion INTO IVersion
FROM entity_version as e
WHERE e.entity_id = InternalEntityID
AND e.version = Version;
SET IVersion = get_iversion(InternalEntityID, Version);
IF IVersion IS NULL THEN
-- RETURN EARLY - Version does not exist.
......
......@@ -44,11 +44,10 @@ ACL : VARBINARY(65525)
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
DECLARE NewEntityID INT UNSIGNED DEFAULT NULL;
DECLARE NewACLID INT UNSIGNED DEFAULT NULL;
DECLARE Hash VARBINARY(255) DEFAULT NULL;
DECLARE Version VARBINARY(255) DEFAULT NULL;
......@@ -66,14 +65,13 @@ BEGIN
-- ... and return the generated id
SET InternalEntityID = LAST_INSERT_ID();
INSERT INTO entity_ids (internal_id) VALUES (InternalEntityID);
SET NewEntityID = LAST_INSERT_ID();
INSERT INTO entity_ids (internal_id, id) VALUES (InternalEntityID, EntityID);
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
-- TODO this is transaction-scoped variable. Is this a good idea?
SET Transaction = @SRID;
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;
-- insert the name of the entity into name_data table
......@@ -84,7 +82,7 @@ BEGIN
VALUES (0, InternalEntityID, 20, EntityName, "FIX", 0);
END IF;
SELECT NewEntityID as EntityID, Version as Version;
SELECT Version as Version;
END;
//
......
......@@ -65,38 +65,43 @@ IF targetSet IS NULL OR targetSet = sourceSet THEN
"` WHERE ",
IF(o IS NULL OR vInt IS NULL,
"1=1",
CONCAT("NOT id",
CONCAT("NOT EXISTS (SELECT 1 FROM entity_ids AS eids WHERE eids.id ",
o,
vInt)),
vInt,
" AND eids.internal_id = `",
sourceSet,
"`.id)"
)),
IF(aggVal IS NULL,
"",
CONCAT(" AND id!=",
CONCAT(" AND `", sourceSet, "`.id!=",
aggVal)));
ELSEIF versioned AND sourceSet = "entities" THEN
-- ################# VERSIONING #####################
SET data = CONCAT(
"INSERT IGNORE INTO `",
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,
"1=1",
CONCAT("id",
CONCAT("eids.id ",
o,
vInt)),
vInt
)),
IF(aggVal IS NULL,
"",
CONCAT(" AND id=",
CONCAT(" AND e.id=",
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,
"1=1",
CONCAT("id",
CONCAT("eids.id ",
o,
vInt)),
vInt
)),
IF(aggVal IS NULL,
"",
CONCAT(" AND id=",
CONCAT(" AND e.id=",
aggVal)));
-- ##################################################
......@@ -108,10 +113,10 @@ ELSE
'` (id, _iversion) SELECT data.id, data._iversion FROM `',
'` (id) SELECT data.id FROM `'),
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,
"1=1",
CONCAT("data.id",
CONCAT("eids.id",
o,
vInt)),
IF(aggVal IS NULL,
......
......@@ -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))
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,
'\'',
IF(userName IS NOT NULL,
......
......@@ -48,7 +48,7 @@ BEGIN
DEALLOCATE PREPARE stmt;
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;
EXECUTE stmt;
SET ecount = ecount + ROW_COUNT();
......
......@@ -77,7 +77,7 @@ retrieveEntityBody: BEGIN
SET IsHead = FALSE;
SET Version = get_head_relative(EntityID, SUBSTR(Version, 6));
ELSE
SELECT get_head_version(InternalEntityID) = Version INTO IsHead;
SELECT get_head_version(EntityID) = Version INTO IsHead;
END IF;
IF IsHead IS FALSE THEN
......@@ -155,10 +155,8 @@ retrieveEntityBody: BEGIN
WHERE file_id = InternalEntityID
LIMIT 1;
SELECT eids.id INTO DatatypeID
SELECT dt.datatype INTO DatatypeID
FROM data_type as dt
LEFT JOIN entity_ids eids
ON dt.datatype = eids.internal_id
WHERE dt.domain_id=0
AND dt.entity_id=0
AND dt.property_id=InternalEntityID
......@@ -174,7 +172,7 @@ retrieveEntityBody: BEGIN
SELECT
( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_ID = DatatypeID
AND entity_id = DatatypeID
AND property_id = 20 LIMIT 1 ) AS Datatype,
CollectionName AS Collection,
EntityID AS EntityID,
......
......@@ -65,7 +65,7 @@ retrieveEntityParentsBody: BEGIN
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") 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;
IF IsHead IS FALSE THEN
......
......@@ -91,7 +91,7 @@ BEGIN
WHERE e.entity_id = InternalEntityID
AND e._iversion = OldIVersion;
CALL insert_single_child_version(
EntityID, Hash, Version,
InternalEntityID, Hash, Version,
ParentVersion, Transaction);
END IF;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment