core icon indicating copy to clipboard operation
core copied to clipboard

FixTask00020DeleteOrphanedIdentifiers - Performance Improvements

Open gabbydotCMS opened this issue 10 years ago • 2 comments

In a client's DB with over:

  • 30K records in the table identifier
  • 93K records in the table contentlet
  • 6K records in the table htmlpage
  • 56K records in the table file_asset
  • 1K records in the table links
  • 900 records in the table containers
  • 4K records in the table template

Just the select (using NOT IN) to detect orphan identifiers took about one hour to run:

select * from identifier where (assettype='contentlet' and id not in(select identifier from contentlet )) OR (assettype='htmlpage' and id not in(select identifier from htmlpage)) OR (assettype='fileasset' and id not in(select identifier from fileasset)) OR (assettype='links' and id not in(select identifier from links)) OR (assettype='containers' and id not in(select identifier from containers)) OR (assettype='template' and id not in(select identifier from template)) Total query runtime: 3743319 ms. 5 rows retrieved.

When changing "NOT IN" by "NOT EXISTS", the same query took only about 7 minutes:

select * from identifier i where (i.assettype='contentlet' and not exists (select * from contentlet c where c.identifier=i.id)) OR (i.assettype='htmlpage' and not exists (select * from htmlpage h where h.identifier=i.id)) OR (i.assettype='fileasset' and not exists (select * from fileasset fa where fa.identifier=i.id)) OR (i.assettype='links' and not exists (select * from links l where l.identifier=i.id)) OR (i.assettype='containers' and not exists (select * from containers cont where cont.identifier=i.id)) OR (i.assettype='template' and not exists (select * from template t where t.identifier=i.id)) Total query runtime: 441651 ms. 5 rows retrieved.

Further more, when dealing with each type of asset separately, all the queries took about 4 seconds to execute:

select * from identifier i where (i.asset_type='contentlet' and not exists (select * from contentlet c where c.identifier=i.id));

select * from identifier i where (i.asset_type='htmlpage' and not exists (select * from htmlpage h where h.identifier=i.id));

select * from identifier i where (i.assettype='fileasset' and not exists (select * from file_asset fa where fa.identifier=i.id));

select * from identifier i where (i.asset_type='links' and not exists (select * from links l where l.identifier=i.id));

select * from identifier i where (i.asset_type='containers' and not exists (select * from containers cont where cont.identifier=i.id));

select * from identifier i where (i.asset_type='template' and not exists (select * from template t where t.identifier=i.id)); query result with 1 row discarded.

query result with 4 rows discarded.

Total query runtime: 3526 ms.

gabbydotCMS avatar Jun 17 '16 14:06 gabbydotCMS

The following queries can be used to insert bad data that will allow every select and delete executed by the fixTask to be tested:

INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-contentlet-001', '/', 'ft20-test-contentlet-001.contentlet', 'contentlet'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-contentlet-002', '/', 'ft20-test-contentlet-002.contentlet', 'contentlet'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-contentlet-003', '/', 'ft20-test-contentlet-003.contentlet', 'contentlet'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-container-001', '/', 'ft20-test-container-001.container', 'containers'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-container-002', '/', 'ft20-test-container-002.container', 'containers'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-container-003', '/', 'ft20-test-container-003.container', 'containers'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-links-001', '/', 'ft20-test-links-001', 'links'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-links-002', '/', 'ft20-test-links-002', 'links'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-links-003', '/', 'ft20-test-links-003', 'links'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-template-001', '/', 'ft20-test-template-001', 'template'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-template-002', '/', 'ft20-test-template-002', 'template'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-template-003', '/', 'ft20-test-template-003', 'template'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-file_asset-001', '/', 'ft20-test-file_asset-001', 'file_asset'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-file_asset-002', '/', 'ft20-test-file_asset-002', 'file_asset'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-file_asset-003', '/', 'ft20-test-file_asset-003', 'file_asset'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-htmlpage-001', '/', 'ft20-test-htmlpage-001.html', 'htmlpage'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-htmlpage-002', '/', 'ft20-test-htmlpage-002.html', 'htmlpage'); INSERT INTO identifier(host_inode, id, parent_path, asset_name, asset_type) VALUES ('SYSTEM_HOST', 'ft20-test-htmlpage-003', '/', 'ft20-test-htmlpage-003.html', 'htmlpage'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-contentlet-001', 'ft20-test-contentlet-002', 'ft-test-relation-contentlet'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-contentlet-002', 'ft20-test-contentlet-003', 'ft-test-relation-contentlet'); -- Not sure if the following entries can actually exists INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-container-001', 'ft20-test-container-002', 'ft-test-relation-container'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-container-002', 'ft20-test-container-003', 'ft-test-relation-container'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-links-001', 'ft20-test-links-002', 'ft-test-relation-links'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-links-002', 'ft20-test-links-003', 'ft-test-relation-links'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-template-001', 'ft20-test-template-002', 'ft-test-relation-template'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-template-002', 'ft20-test-template-003', 'ft-test-relation-template'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-file_asset-001', 'ft20-test-file_asset-002', 'ft-test-relation-file_asset'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-file_asset-002', 'ft20-test-file_asset-003', 'ft-test-relation-file_asset'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-htmlpage-001', 'ft20-test-htmlpage-002', 'ft-test-relation-htmlpage'); INSERT INTO tree(child, parent, relation_type) VALUES ('ft20-test-htmlpage-002', 'ft20-test-htmlpage-003', 'ft-test-relation-htmlpage');

gabbydotCMS avatar Jun 18 '16 21:06 gabbydotCMS

Fix is working. Orphaned identifiers are deleted after running Fix Assets Inconsistencies in backend Tested locally in: master-3.6 // Win7 Pro SP1 // SQLServer 2012 // Chrome master-3.6 // Mac OS 10.10 // MySQL 5.6.23 // Firefox master-3.6 // Ubuntu 14.04.1 // Postgres 9.3 // Chrome master-3.6 // Mac OS 10.10 // Oracle 12c // Firefox

shaydotcms avatar Aug 05 '16 17:08 shaydotcms