Skip to content
Snippets Groups Projects
Commit 9c02cdd3 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

select useful"

parent e5df395e
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,7 @@ DELIMITER // ...@@ -40,7 +40,7 @@ DELIMITER //
CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* (?) Name of the table that the POV will be applied to. This can be a temporary table. */ CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* (?) Name of the table that the POV will be applied to. This can be a temporary table. */
in targetSet VARCHAR(255), /* (?) Name of the result table of this POV. */ in targetSet VARCHAR(255), /* (?) Name of the result table of this POV. */
in propertiesTable VARCHAR(255), in propertiesTable VARCHAR(255),
in refIdsTable VARCHAR(255), in refIdsTable VARCHAR(255), /* (?) Name of a tmp table that contains all ids of children of the value interpreted as entity */
in o CHAR(4), /* The operator for this operation. can be one of: in o CHAR(4), /* The operator for this operation. can be one of:
0 check for "equals NULL" 0 check for "equals NULL"
!0 check for "not NULL" !0 check for "not NULL"
...@@ -81,6 +81,19 @@ POV_LABEL: BEGIN ...@@ -81,6 +81,19 @@ POV_LABEL: BEGIN
DECLARE keepTabl VARCHAR(255) DEFAULT NULL; DECLARE keepTabl VARCHAR(255) DEFAULT NULL;
DECLARE existence_op VARCHAR(255) DEFAULT "EXISTS"; DECLARE existence_op VARCHAR(255) DEFAULT "EXISTS";
select NOW(6) into @time;
SET @tmpquery = CONCAT('SELECT * FROM `', refIdsTable, '` into outfile "/tmp/stuff', now(0),'"');
PREPARE stmt FROM @tmpquery;
EXECUTE stmt;
SET @tmpquery2 = CONCAT('insert into povtimes (SELECT now(0), count(*), 0 FROM `', propertiesTable , '`)');
PREPARE stmt2 FROM @tmpquery2;
EXECUTE stmt2;
insert into povtimes (select now(0), "Beginning", timediff(NOW(6),@time) as time_passed);
#-- ######### HINT ##############
#-- first the appropriate statement is created which in the end prepared and executed
#-- #############################
IF o = '->' THEN IF o = '->' THEN
#-- special case: pure reference property #-- special case: pure reference property
call applyRefPOV(sourceSet,targetSet, propertiesTable, refIdsTable, versioned); call applyRefPOV(sourceSet,targetSet, propertiesTable, refIdsTable, versioned);
...@@ -229,6 +242,8 @@ POV_LABEL: BEGIN ...@@ -229,6 +242,8 @@ POV_LABEL: BEGIN
IF o = "!=" AND refIdsTable IS NOT NULL THEN IF o = "!=" AND refIdsTable IS NOT NULL THEN
SET existence_op = "NOT EXISTS"; SET existence_op = "NOT EXISTS";
END IF; END IF;
/* select all entities that reference the entity or a child of the
* value interpreted as ID*/
SET sRefData = IF(vText IS NULL, SET sRefData = IF(vText IS NULL,
' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data`', ' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data`',
IF(refIdsTable IS NULL, IF(refIdsTable IS NULL,
...@@ -243,6 +258,9 @@ POV_LABEL: BEGIN ...@@ -243,6 +258,9 @@ POV_LABEL: BEGIN
END IF; END IF;
insert into povtimes (select now(0), "data string assembled", timediff(NOW(6),@time) as time_passed);
#-- create array of statement parts (and replace null with empty string) (?)
SET data = CONCAT('(',sTextData, SET data = CONCAT('(',sTextData,
IF(sNameData IS NULL, '', sNameData), IF(sNameData IS NULL, '', sNameData),
IF(sEnumData IS NULL, '', sEnumData), IF(sEnumData IS NULL, '', sEnumData),
...@@ -257,8 +275,10 @@ POV_LABEL: BEGIN ...@@ -257,8 +275,10 @@ POV_LABEL: BEGIN
call createTmpTable(keepTabl, versioned); call createTmpTable(keepTabl, versioned);
insert into povtimes (select now(0), "created tmptable ", timediff(NOW(6),@time) as time_passed);
IF versioned THEN IF versioned THEN
#-- generate statement from statement parts #-- generate statement from statement parts
#-- (versioned section)
SET @stmtPOVkeepTblStr = CONCAT( SET @stmtPOVkeepTblStr = CONCAT(
'INSERT IGNORE INTO `', keepTabl, '` (id, _iversion) SELECT entity_id AS id, _iversion FROM ', data, 'INSERT IGNORE INTO `', keepTabl, '` (id, _iversion) SELECT entity_id AS id, _iversion FROM ', data,
' as data', IF(propertiesTable IS NULL, '', CONCAT( ' as data', IF(propertiesTable IS NULL, '', CONCAT(
...@@ -299,7 +319,15 @@ POV_LABEL: BEGIN ...@@ -299,7 +319,15 @@ POV_LABEL: BEGIN
DEALLOCATE PREPARE stmtPOVkeepTbl; DEALLOCATE PREPARE stmtPOVkeepTbl;
ELSE ELSE
#-- generate statement from statement parts #-- generate statement from statement parts
SET @stmtPOVkeepTblStr = CONCAT('INSERT IGNORE INTO `', keepTabl, '` (id) SELECT DISTINCT entity_id AS id FROM ', data, ' as data', IF(propertiesTable IS NULL, '', CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable, '` AS prop WHERE prop.id = data.property_id AND (prop.id2=data.entity_id OR prop.id2=0))'))); #-- (unversioned section)
SET @stmtPOVkeepTblStr = CONCAT('INSERT IGNORE INTO `', keepTabl, '` (id)
SELECT DISTINCT entity_id AS id FROM ', data, ' as data',
IF(propertiesTable IS NULL,
'',
/* restrict to properties with one of the appropriate ids
* and where the domain (???) equals the entity*/
CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable, '` AS prop
WHERE prop.id = data.property_id AND (prop.id2=data.entity_id OR prop.id2=0))')));
SET @stmtPOVStr = CONCAT( SET @stmtPOVStr = CONCAT(
IF(targetSet IS NULL, IF(targetSet IS NULL,
...@@ -320,19 +348,23 @@ POV_LABEL: BEGIN ...@@ -320,19 +348,23 @@ POV_LABEL: BEGIN
#-- prepare and execute #-- prepare and execute
PREPARE stmt3 FROM @stmtPOVStr; PREPARE stmt3 FROM @stmtPOVStr;
PREPARE stmtPOVkeepTbl FROM @stmtPOVkeepTblStr; PREPARE stmtPOVkeepTbl FROM @stmtPOVkeepTblStr;
insert into povtimes (select now(0), "statements prepared ", timediff(NOW(6),@time) as time_passed);
IF vText IS NULL THEN IF vText IS NULL THEN
EXECUTE stmtPOVkeepTbl; EXECUTE stmtPOVkeepTbl;
ELSE ELSE
SET @vText = vText; SET @vText = vText;
EXECUTE stmtPOVkeepTbl USING @vText, @vText, @vText; EXECUTE stmtPOVkeepTbl USING @vText, @vText, @vText;
END IF; END IF;
insert into povtimes (select now(0), "first execute ", timediff(NOW(6),@time) as time_passed);
EXECUTE stmt3; EXECUTE stmt3;
insert into povtimes (select now(0), "second execute ", timediff(NOW(6),@time) as time_passed);
DEALLOCATE PREPARE stmt3; DEALLOCATE PREPARE stmt3;
DEALLOCATE PREPARE stmtPOVkeepTbl; DEALLOCATE PREPARE stmtPOVkeepTbl;
END IF; END IF;
SELECT @stmtPOVkeepTblStr as applyPOVStmt1, @stmtPOVStr as applyPOVStmt2, keepTabl as applyPOVIntermediateResultSet; SELECT @stmtPOVkeepTblStr as applyPOVStmt1, @stmtPOVStr as applyPOVStmt2, keepTabl as applyPOVIntermediateResultSet;
insert into povtimes (select now(0), "end ", timediff(NOW(6),@time) as time_passed);
END; END;
// //
......
...@@ -61,6 +61,7 @@ BEGIN ...@@ -61,6 +61,7 @@ BEGIN
call createTmpTable2(propertiesTable); call createTmpTable2(propertiesTable);
-- fill in all properties named "PropertyName" -- fill in all properties named "PropertyName"
-- what are overwrites needed for?
SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;'); SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;');
PREPARE stmt FROM @initPOVPropertiesTableStmt1; PREPARE stmt FROM @initPOVPropertiesTableStmt1;
SET @PropertyName = PropertyName; SET @PropertyName = PropertyName;
......
...@@ -24,6 +24,13 @@ ...@@ -24,6 +24,13 @@
DROP PROCEDURE IF EXISTS db_5_0.initSubEntity; DROP PROCEDURE IF EXISTS db_5_0.initSubEntity;
DELIMITER // DELIMITER //
/*
* This procedures composes a table with the ids of all entities with the given
* name and all their children (!!)
* and if provided adds the supplied entity id.
*
* The table name has to be provided.
*/
/* /*
* Initialize a new temporary table by loading an entity and all of its children * Initialize a new temporary table by loading an entity and all of its children
...@@ -45,6 +52,7 @@ BEGIN ...@@ -45,6 +52,7 @@ BEGIN
DECLARE ecount INT DEFAULT 0; DECLARE ecount INT DEFAULT 0;
DECLARE op VARCHAR(255) DEFAULT '='; DECLARE op VARCHAR(255) DEFAULT '=';
IF LOCATE("%", ename) > 0 THEN IF LOCATE("%", ename) > 0 THEN
SET op = "LIKE"; SET op = "LIKE";
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