Skip to content

Commit 5c198c1

Browse files
wezellclaude
andcommitted
perf(identifier): replace structure joins with identifier.base_type lookups
Now that identifier.base_type is populated (see data-model PR), remove unnecessary joins to the structure table in hot-path queries that only needed structure.structuretype for base-type filtering. - BrowserAPIImpl: remove structure from base clause; structuretype → base_type; content-type-ID filters use subqueries into the small structure table - FileAssetFactoryImpl: drop structure join; structuretype=4 → base_type=FILEASSET - HTMLPageAssetAPIImpl: drop structure join from all 4 modified-page queries; structuretype=HTMLPAGE → ii.base_type=HTMLPAGE - PermissionBitFactoryImpl: drop structure join from 5 child-htmlpage / child-content permission queries - AbstractIntegrityChecker: drop structure join from CSV export and both conflict-detection queries Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 84b80f7 commit 5c198c1

5 files changed

Lines changed: 31 additions & 35 deletions

File tree

dotCMS/src/main/java/com/dotcms/browser/BrowserAPIImpl.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,10 +1621,12 @@ static class SelectQuery {
16211621
*/
16221622
private String buildSelectBaseQuery(final BrowserQuery browserQuery, final String workingLiveInode) {
16231623

1624-
final String baseClause = " from contentlet_version_info cvi, identifier id, structure struc, contentlet c "
1625-
+ " where cvi.identifier = id.id and struc.velocity_var_name = id.asset_subtype and "
1626-
+ " c.inode = cvi." + workingLiveInode + " and cvi.variant_id='"
1627-
+ DEFAULT_VARIANT.name() + "' ";
1624+
// structure join removed — base_type on identifier replaces struc.structuretype,
1625+
// and content-type-ID filters use subqueries into the (small) structure table.
1626+
final String baseClause = " from contentlet_version_info cvi, identifier id, contentlet c "
1627+
+ " where cvi.identifier = id.id"
1628+
+ " and c.inode = cvi." + workingLiveInode
1629+
+ " and cvi.variant_id='" + DEFAULT_VARIANT.name() + "' ";
16281630

16291631
final StringBuilder baseQuery = new StringBuilder(
16301632
"select cvi." + workingLiveInode + " as inode " + baseClause);
@@ -1634,21 +1636,24 @@ private String buildSelectBaseQuery(final BrowserQuery browserQuery, final Strin
16341636
final List<String> baseTypes =
16351637
browserQuery.baseTypes.stream().map(t -> String.valueOf(t.getType()))
16361638
.collect(Collectors.toList());
1637-
baseQuery.append(" and struc.structuretype in (").append(String.join(" , ", baseTypes))
1639+
baseQuery.append(" and id.base_type in (").append(String.join(" , ", baseTypes))
16381640
.append(") ");
16391641
}
16401642

16411643
if (!browserQuery.contentTypeIds.isEmpty()) {
1642-
baseQuery.append(" and struc.inode in (").append(browserQuery.contentTypeIds.stream()
1643-
.map(id -> "'" + id + "'")
1644-
.collect(Collectors.joining(" , "))).append(") ");
1644+
baseQuery.append(" and id.asset_subtype in (select velocity_var_name from structure where inode in (")
1645+
.append(browserQuery.contentTypeIds.stream()
1646+
.map(id -> "'" + id + "'")
1647+
.collect(Collectors.joining(" , ")))
1648+
.append(")) ");
16451649
}
16461650

16471651
if (!browserQuery.excludedContentTypeIds.isEmpty()) {
1648-
baseQuery.append(" and struc.inode not in (")
1652+
baseQuery.append(" and id.asset_subtype not in (select velocity_var_name from structure where inode in (")
16491653
.append(browserQuery.excludedContentTypeIds.stream()
16501654
.map(id -> "'" + id + "'")
1651-
.collect(Collectors.joining(" , "))).append(") ");
1655+
.collect(Collectors.joining(" , ")))
1656+
.append(")) ");
16521657
}
16531658

16541659
return baseQuery.toString();

dotCMS/src/main/java/com/dotcms/integritycheckers/AbstractIntegrityChecker.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ protected File generateContentletsCSVFile(final String outputFile, final int str
147147
.append("cvi.working_inode, cvi.live_inode, i.parent_path, i.asset_name, i.host_inode, c.language_id ")
148148
.append("FROM contentlet_version_info cvi ")
149149
.append("INNER JOIN contentlet c ON (c.identifier = cvi.identifier AND c.language_id = cvi.lang) ")
150-
.append("INNER JOIN structure s ON (s.inode = c.structure_inode AND s.structuretype = ")
151-
.append(structureTypeId).append(") ")
152-
.append("INNER JOIN identifier i ON (i.id = c.identifier)").toString();
150+
.append("INNER JOIN identifier i ON (i.id = c.identifier) ")
151+
.append("WHERE i.base_type = ").append(structureTypeId).toString();
153152

154153
final Connection conn = DbConnectionFactory.getConnection();
155154
try (final PreparedStatement statement = conn.prepareStatement(query)) {
@@ -272,8 +271,7 @@ protected void processContentletIntegrityByStructureType(final String endpointId
272271
.append("FROM identifier li ")
273272
.append("INNER JOIN contentlet lc ON (lc.identifier = li.id and li.asset_type = 'contentlet') ")
274273
.append("INNER JOIN contentlet_version_info lcvi ON (lc.identifier = lcvi.identifier) ")
275-
.append("INNER JOIN structure ls ON (lc.structure_inode = ls.inode and ls.structuretype = ")
276-
.append(structureType).append(") ").append("INNER JOIN ").append(tempTableName)
274+
.append("AND li.base_type = ").append(structureType).append(" INNER JOIN ").append(tempTableName)
277275
.append(" t ON (li.full_path_lc = t.full_path_lc ")
278276
.append("AND li.host_inode = host_identifier AND lc.identifier <> t.identifier ")
279277
.append("AND lc.language_id = t.language_id)").toString();
@@ -306,9 +304,7 @@ protected void processContentletIntegrityByStructureType(final String endpointId
306304
.append("FROM identifier li ")
307305
.append("INNER JOIN contentlet lc ON (lc.identifier = li.id and li.asset_type = 'contentlet') ")
308306
.append("INNER JOIN contentlet_version_info lcvi ON (lc.identifier = lcvi.identifier and lc.language_id = lcvi.lang) ")
309-
.append("INNER JOIN structure ls ON (lc.structure_inode = ls.inode and ls.structuretype = ")
310-
.append(structureType)
311-
.append(") INNER JOIN ")
307+
.append("AND li.base_type = ").append(structureType).append(" INNER JOIN ")
312308
.append(tempTableName)
313309
.append(" t ON (li.full_path_lc = t.full_path_lc ")
314310
.append("AND li.host_inode = host_identifier AND lc.identifier <> t.identifier AND lc.language_id = t.language_id )")

dotCMS/src/main/java/com/dotmarketing/business/PermissionBitFactoryImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public class PermissionBitFactoryImpl extends PermissionFactory {
322322
" UNION ALL" +
323323
" SELECT distinct li.id FROM identifier li" +
324324
" INNER JOIN contentlet lc ON (lc.identifier = li.id and li.asset_type = 'contentlet')" +
325-
" INNER JOIN structure ls ON (lc.structure_inode = ls.inode and ls.structuretype = " + BaseContentType.HTMLPAGE.getType() + ")" +
325+
" AND li.base_type = " + BaseContentType.HTMLPAGE.getType() +
326326
" AND li.host_inode = ? and li.parent_path like ?";
327327

328328
private static final String SELECT_CHILD_HTMLPAGE_ON_PERMISSIONS_SQL =
@@ -332,8 +332,8 @@ public class PermissionBitFactoryImpl extends PermissionFactory {
332332
" UNION ALL" +
333333
" SELECT distinct li.id FROM identifier li" +
334334
" INNER JOIN contentlet lc ON (lc.identifier = li.id and li.asset_type = 'contentlet')" +
335-
" INNER JOIN structure ls ON (lc.structure_inode = ls.inode and ls.structuretype = " + BaseContentType.HTMLPAGE.getType() + ")" +
336335
" JOIN permission_reference ON permission_type = '" + IHTMLPage.class.getCanonicalName() + "' and asset_id = li.id" +
336+
" AND li.base_type = " + BaseContentType.HTMLPAGE.getType() +
337337
" AND li.host_inode = ? and li.parent_path like ?";
338338

339339
/*
@@ -349,8 +349,8 @@ public class PermissionBitFactoryImpl extends PermissionFactory {
349349
" UNION ALL" +
350350
" SELECT distinct li.id from identifier li" +
351351
" INNER JOIN contentlet lc ON (lc.identifier = li.id and li.asset_type = 'contentlet')" +
352-
" INNER JOIN structure ls ON (lc.structure_inode = ls.inode and ls.structuretype = " + BaseContentType.HTMLPAGE.getType() + ")" +
353352
" JOIN permission lp ON (lp.inode_id = li.id) " +
353+
" AND li.base_type = " + BaseContentType.HTMLPAGE.getType() +
354354
" AND li.host_inode = ? and li.parent_path like ?" +
355355
" AND lp.permission_type = '" + PermissionAPI.INDIVIDUAL_PERMISSION_TYPE + "'";
356356

@@ -490,9 +490,8 @@ public class PermissionBitFactoryImpl extends PermissionFactory {
490490
"select distinct li.id from identifier li" +
491491
" join permission lp on (lp.inode_id = li.id) " +
492492
" INNER JOIN contentlet lc ON (lc.identifier = li.id and li.asset_type = 'contentlet')" +
493-
" INNER JOIN structure ls ON (lc.structure_inode = ls.inode)" +
494493
" where li.asset_type='contentlet' and lp.permission_type = '" + PermissionAPI.INDIVIDUAL_PERMISSION_TYPE + "' " +
495-
" AND ls.structuretype <> " + BaseContentType.HTMLPAGE.getType() +
494+
" AND li.base_type <> " + BaseContentType.HTMLPAGE.getType() +
496495
" and li.id <> li.host_inode and li.host_inode = ? " +
497496
" and li.parent_path like ?";
498497

@@ -2910,7 +2909,7 @@ public String getInsertHTMLPageReferencesSQL() {
29102909
" UNION ALL" +
29112910
" SELECT distinct li.id as li_id FROM identifier li" +
29122911
" INNER JOIN contentlet lc ON (lc.identifier = li.id and li.asset_type = 'contentlet')" +
2913-
" INNER JOIN structure ls ON (lc.structure_inode = ls.inode and ls.structuretype = " + BaseContentType.HTMLPAGE.getType() + ")" +
2912+
" AND li.base_type = " + BaseContentType.HTMLPAGE.getType() + " " +
29142913
" AND li.host_inode = ? and li.parent_path like ?" +
29152914
" and" +
29162915
" li.id not in (" +

dotCMS/src/main/java/com/dotmarketing/portlets/fileassets/business/FileAssetFactoryImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.dotmarketing.portlets.fileassets.business;
22

3+
import com.dotcms.contenttype.model.type.BaseContentType;
34
import com.dotmarketing.business.APILocator;
45
import com.dotmarketing.business.PermissionAPI;
56
import com.dotmarketing.common.db.DotConnect;
@@ -20,13 +21,12 @@ public class FileAssetFactoryImpl implements FileAssetFactory {
2021

2122
private final String FIND_FILE_ASSETS_BY_FOLDER_QUERY =
2223
"SELECT contentlet.inode as mynode " +
23-
"FROM identifier, contentlet_version_info, contentlet, structure " +
24+
"FROM identifier, contentlet_version_info, contentlet " +
2425
"WHERE identifier.parent_path = ? and " +
2526
"identifier.host_inode = ? and " +
2627
"contentlet_version_info.identifier = identifier.id and " +
2728
"contentlet_version_info.%s_inode = contentlet.inode and " +
28-
"contentlet.structure_inode = structure.inode and " +
29-
"structure.structuretype =4";
29+
"identifier.base_type = " + BaseContentType.FILEASSET.getType();
3030

3131
public FileAssetFactoryImpl() {
3232
permissionAPI = APILocator.getPermissionAPI();

dotCMS/src/main/java/com/dotmarketing/portlets/htmlpageasset/business/HTMLPageAssetAPIImpl.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,8 @@ public List<String> findUpdatedHTMLPageIdsByURI(Host host, String pattern,boolea
606606
bob.append("SELECT ii.id as pident ")
607607
.append("from identifier ii ")
608608
.append("join contentlet cc on (cc.identifier = ii.id) ")
609-
.append("join structure st on (cc.structure_inode=st.inode) ")
610609
.append("join template_version_info tvi on (cc.").append(tf.getFieldContentlet()).append(" = tvi.identifier) ")
611-
.append("where st.structuretype=").append(Structure.STRUCTURE_TYPE_HTMLPAGE)
610+
.append("where ii.base_type=").append(Structure.STRUCTURE_TYPE_HTMLPAGE)
612611
.append(" and tvi.version_ts >= ? and tvi.version_ts <= ? ")
613612
.append(" and ii.host_inode=? ")
614613
.append(" and ").append(concat).append(include?" LIKE ?":" NOT LIKE ?");
@@ -629,10 +628,9 @@ public List<String> findUpdatedHTMLPageIdsByURI(Host host, String pattern,boolea
629628
bob.append("SELECT ii.id as pident ")
630629
.append("from identifier ii " )
631630
.append("join contentlet cc on (ii.id=cc.identifier) ")
632-
.append("join structure st on (cc.structure_inode=st.inode) ")
633631
.append("join template_containers tc on (cc.").append(tf.getFieldContentlet()).append(" = tc.template_id) ")
634632
.append("join container_version_info cvi on (tc.container_id = cvi.identifier) ")
635-
.append("where st.structuretype=").append(Structure.STRUCTURE_TYPE_HTMLPAGE)
633+
.append("where ii.base_type=").append(Structure.STRUCTURE_TYPE_HTMLPAGE)
636634
.append(" and cvi.version_ts >= ? and cvi.version_ts <= ? ")
637635
.append(" and ii.host_inode=? ")
638636
.append(" and ").append(concat).append(include?" LIKE ?":" NOT LIKE ?");
@@ -653,10 +651,9 @@ public List<String> findUpdatedHTMLPageIdsByURI(Host host, String pattern,boolea
653651
bob.append("SELECT ii.id as pident ")
654652
.append("from contentlet_version_info hvi join identifier ii on (hvi.identifier=ii.id) " )
655653
.append("join contentlet cc on (ii.id=cc.identifier) ")
656-
.append("join structure st on (cc.structure_inode=st.inode) ")
657654
.append("join multi_tree mt on (hvi.identifier = mt.parent1) ")
658655
.append("join contentlet_version_info cvi on (mt.child = cvi.identifier) ")
659-
.append("where st.structuretype=").append(Structure.STRUCTURE_TYPE_HTMLPAGE)
656+
.append("where ii.base_type=").append(Structure.STRUCTURE_TYPE_HTMLPAGE)
660657
.append(" and cvi.version_ts >= ? and cvi.version_ts <= ? ")
661658
.append(" and ii.host_inode=? ")
662659
.append(" and ").append(concat).append(include?" LIKE ?":" NOT LIKE ?");
@@ -678,8 +675,7 @@ public List<String> findUpdatedHTMLPageIdsByURI(Host host, String pattern,boolea
678675
bob.append("SELECT ii.id as pident from contentlet cc ")
679676
.append("join identifier ii on (ii.id=cc.identifier) ")
680677
.append("join contentlet_version_info vi on (vi.identifier=ii.id) ")
681-
.append("join structure st on (cc.structure_inode=st.inode) ")
682-
.append("where st.structuretype=").append(Structure.STRUCTURE_TYPE_HTMLPAGE)
678+
.append("where ii.base_type=").append(Structure.STRUCTURE_TYPE_HTMLPAGE)
683679
.append(" and vi.version_ts >= ? and vi.version_ts <= ? ")
684680
.append(" and ii.host_inode=? ")
685681
.append(" and ").append(concat).append(include?" LIKE ?":" NOT LIKE ?");

0 commit comments

Comments
 (0)