简体   繁体   English

Hsqldb 重命名具有相同父项的项目名称的重复项

[英]Hsqldb rename duplicates of item names with same parent

I wrote a LibreOffice / OpenOffice extension that allows access to these Google Drive files.我编写了一个 LibreOffice / OpenOffice 扩展,允许访问这些 Google Drive 文件。

To do so, I use a Hsqldb 2.4 database, script file is accessible at: https://github.com/prrvchr/gDriveOOo/blob/master/gDriveOOo/hsqldb/vnd.google-apps.script为此,我使用了 Hsqldb 2.4 数据库, 可在以下位置访问脚本文件: https : //github.com/prrvchr/gDriveOOo/blob/master/gDriveOOo/hsqldb/vnd.google-apps.script

The LibreOffice / OpenOffice UNO API does not handle duplicate file names (such as under a file system), while Google Drive offers this possibility. LibreOffice / OpenOffice UNO API 不处理重复的文件名(例如在文件系统下),而 Google Drive 提供了这种可能性。

To work around this problem, I created four View ('ChildUri', 'IdentifierUri', 'ItemUri' and 'Uri') allowing me to build a new name of the form: CONCAT (name, ~, position) for the second and following doublon, position being their position in the GROUP BY clause...为了解决这个问题,我创建了四个视图('ChildUri'、'IdentifierUri'、'ItemUri' 和 'Uri'),允许我为表单构建一个新名称:CONCAT(名称,~,位置)作为第二个和在 doublon 之后, position 是他们在 GROUP BY 子句中的位置......

CREATE VIEW PUBLIC."ChildUri" ("Id","Name","Parent") AS SELECT "I"."Id","I"."Name","C"."ItemId" FROM PUBLIC."Items" AS "I" JOIN PUBLIC."Children" AS "C" ON "I"."Id"="C"."ChildId"  WHERE "I"."Trashed"=FALSE

CREATE VIEW PUBLIC."IdentifierUri" ("Idx","Name","Parent") AS SELECT ARRAY_AGG("I"."Id" ORDER BY "I"."DateCreated","I"."Id"),"I"."Name","C"."Parent" FROM PUBLIC."Items" AS "I" JOIN PUBLIC."ChildUri" AS "C" ON "I"."Id"="C"."Id" GROUP BY "I"."Name","C"."Parent"

CREATE VIEW PUBLIC."ItemUri" ("Id","Name","Length","Position","Parent") AS SELECT "C"."Id","I"."Name",CARDINALITY("I"."Idx"),POSITION_ARRAY("C"."Id" IN "I"."Idx"),"I"."Parent" FROM PUBLIC."ChildUri" AS "C" JOIN PUBLIC."IdentifierUri" AS "I" ON "C"."Name"="I"."Name" AND "C"."Parent"="I"."Parent"

CREATE VIEW PUBLIC."Uri" ("Id","Name","Uri","Parent") AS SELECT "I"."Id","I"."Name",CASEWHEN("I"."Position"=1,"I"."Name",INSERT("I"."Name", LENGTH("I"."Name") - POSITION('.' IN REVERSE("I"."Name")) + 1,0,CONCAT('~',"I"."Position"))),"I"."Parent" FROM PUBLIC."ItemUri" AS "I"

It works well, but drastically lacks speed when calling the 'selectChild' procedure, it takes 10 seconds to execute, whereas before only some second.它运行良好,但在调用 'selectChild' 过程时速度非常慢,执行需要 10 秒,而之前只需几秒钟。

CREATE PROCEDURE PUBLIC."selectChild"(IN USERID VARCHAR(100),IN ITEMID VARCHAR(100),IN URL VARCHAR(250),IN MODE SMALLINT,OUT ROWCOUNT SMALLINT) SPECIFIC "selectChild_1" LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA NEW SAVEPOINT LEVEL DYNAMIC RESULT SETS 1 BEGIN ATOMIC DECLARE TMPCOUNT SMALLINT DEFAULT 0;DECLARE RESULT CURSOR WITH RETURN FOR SELECT "Title","Size","DateModified","DateCreated","IsFolder",CASEWHEN("IsFolder",CONCAT(URL,'/',"Id"),CONCAT(URL,'/',"Uri"))"TargetURL",FALSE "IsHidden",FALSE "IsVolume",FALSE "IsRemote",FALSE "IsRemoveable",FALSE "IsFloppy",FALSE "IsCompactDisc" FROM PUBLIC."Child" WHERE "UserId"=USERID AND "Parent"=ITEMID AND("IsFolder" OR "Loaded">=MODE)FOR READ ONLY;CALL "countChild"(USERID,ITEMID,MODE,TMPCOUNT);SET ROWCOUNT=TMPCOUNT;OPEN RESULT;END

I admit that it exceeds my skills, and turns to you for help.我承认这超出了我的能力,向你求助。

Thanks in advance.提前致谢。

fredt, what a pleasure it's you who answers ... Can not find better ...弗雷特,很高兴是你来回答......找不到更好的......

I admit that index management must be dismal.我承认索引管理一定是惨淡的。

So I modify the underlying tables (Users, Identifiers, Capabilities, Children) to add UNIQUE CONSTRAINT and FOREIGN KEY CONSTRAINT.因此,我修改了基础表(用户、标识符、功能、儿童)以添加 UNIQUE CONSTRAINT 和 FOREIGN KEY CONSTRAINT。 I had confused UNIQUE INDEX and UNIQUE CONSTRAINT...我混淆了 UNIQUE INDEX 和 UNIQUE CONSTRAINT ...

CREATE CACHED TABLE PUBLIC."Users"("Id" VARCHAR(100) NOT NULL PRIMARY KEY,"UserName" VARCHAR(100) NOT NULL,"DisplayName" VARCHAR(100),"RootId" VARCHAR(100) NOT NULL,"TimeStamp" TIMESTAMP DEFAULT CURRENT_TIMESTAMP(3) NOT NULL,CONSTRAINT "UniqueUserName" UNIQUE ("UserName"))
CREATE CACHED TABLE PUBLIC."Identifiers"("Id" VARCHAR(100) NOT NULL PRIMARY KEY,"UserId" VARCHAR(100) NOT NULL,"TimeStamp" TIMESTAMP DEFAULT CURRENT_TIMESTAMP(3) NOT NULL,CONSTRAINT "ForeignIdentifiersUsers" FOREIGN KEY ("UserId") REFERENCES "Users"("Id"))
CREATE CACHED TABLE PUBLIC."Children"("ChildId" VARCHAR(100) NOT NULL,"ItemId" VARCHAR(100) NOT NULL,"TimeStamp" TIMESTAMP DEFAULT CURRENT_TIMESTAMP(3) NOT NULL,CONSTRAINT "UniqueChildItem" UNIQUE ("ChildId", "ItemId"),CONSTRAINT "ForeignChildrenItems" FOREIGN KEY ("ItemId") REFERENCES "Items"("Id"))
CREATE CACHED TABLE PUBLIC."Capabilities"("UserId" VARCHAR(100) NOT NULL,"ItemId" VARCHAR(100) NOT NULL,"CanAddChild" BOOLEAN DEFAULT FALSE NOT NULL,"CanRename" BOOLEAN DEFAULT FALSE NOT NULL,"IsReadOnly" BOOLEAN DEFAULT FALSE NOT NULL,"IsVersionable" BOOLEAN DEFAULT FALSE NOT NULL,"Loaded" SMALLINT DEFAULT 0 NOT NULL,"SyncMode" SMALLINT DEFAULT 0 NOT NULL,"TimeStamp" TIMESTAMP DEFAULT CURRENT_TIMESTAMP(3) NOT NULL,CONSTRAINT "ForeignCapabilitiesUsers" FOREIGN KEY ("UserId") REFERENCES "Users"("Id"),CONSTRAINT "ForeignCapabilitiesItems" FOREIGN KEY ("ItemId") REFERENCES "Items"("Id"))

And I also added INDEX on the VIEW Item, Child and the VIEW allowing me to build the new name (ChildUri, IdentifierUri, ItemUri and Uri).我还在 VIEW Item、Child 和 VIEW 上添加了 INDEX,允许我构建新名称(ChildUri、IdentifierUri、ItemUri 和 Uri)。

I did not know that we could put INDEX on VIEW...我不知道我们可以将 INDEX 放在 VIEW 上...

CREATE INDEX "ItemIndex" ON "Item"("UserId", "Id")
CREATE INDEX "ChildUriIndex" ON "ChildUri"("Id","Parent")
CREATE INDEX "IdentifierUriIndex" ON "IdentifierUri"("Idx","Parent")
CREATE INDEX "ItemUriIndex" ON "ItemUri"("Id","Parent")
CREATE INDEX "UriIndex" ON "Uri"("Id","Parent")
CREATE INDEX "ChildIndex" ON "Child"("UserId", "Parent")

I kept the Indexes "TrashedIndex" and "MimeTypeIndex" on the Items table, these columns appearing in WHERE clauses我在 Items 表上保留了索引“TrashedIndex”和“MimeTypeIndex”,这些列出现在 WHERE 子句中

CREATE INDEX "TrashedIndex" ON PUBLIC."Items"("Trashed")
CREATE INDEX "MimeTypeIndex" ON PUBLIC."Items"("MimeType")

The "selectChild" request is now done in a few seconds, but I'm not sure of my indexes ... I think I have redundant or missing, or so I'm very lucky ... “selectChild”请求现在在几秒钟内完成,但我不确定我的索引......我想我有多余的或缺失的,或者我很幸运......

Thanks again.再次感谢。

Edit: After several performance tests, apparently only the CONSTRAINT UNIQUE and FOREIGN KEY at the level of the underlying tables improves the performance, the INDEX on the VIEW does not improve the query, or so imperceptibly without a performance test tool.编辑:经过多次性能测试,显然只有底层表级别的CONSTRAINT UNIQUE和FOREIGN KEY提高了性能,VIEW上的INDEX并没有改善查询,或者在没有性能测试工具的情况下不知不觉地。

You need an index to improve SELECT query speed on a table.您需要一个索引来提高对表的 SELECT 查询速度。 The SELECT in the procedure needs an index such as the following if it is not already a FOREIGN KEY如果过程中的 SELECT 还不是 FOREIGN KEY,则它需要如下索引

CREATE INDEX "ChildIndex" ON "Child"("Parent", "UserId")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM