From 33cb2a4d75d2da6d860b61663b824e1a2a7c37ae Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Thu, 20 Aug 2009 13:03:29 +0000 Subject: [PATCH] Better indexing for string properties to support path-based lookups - Normal prefix-index has been shortened to 32 chars (from 64) - Added a fully indexed 'string_end' column of 16 characters - iBatis queries are optimized to pull short strings from the index - Long paths and NodeRefs are well-indexed using this approach git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15833 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- ...escoPostCreate-3.2-PropertyValueTables.sql | 6 ++- .../propval-common-SqlMap.xml | 33 +++++++++++--- .../propval/AbstractPropertyValueDAOImpl.java | 44 ++++++++++--------- .../propval/PropertyStringValueEntity.java | 28 ++++++++++++ .../propval/ibatis/PropertyValueDAOImpl.java | 21 +++++---- 5 files changed, 91 insertions(+), 41 deletions(-) diff --git a/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-PropertyValueTables.sql b/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-PropertyValueTables.sql index 4fd6c58260..f09c67d2d7 100644 --- a/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-PropertyValueTables.sql +++ b/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-PropertyValueTables.sql @@ -45,8 +45,10 @@ CREATE TABLE alf_prop_double_value CREATE TABLE alf_prop_string_value ( id BIGINT NOT NULL AUTO_INCREMENT, - string_value text NOT NULL, - INDEX idx_alf_prop_str_val (string_value(64)), + string_value TEXT NOT NULL, + string_end VARCHAR(16) NOT NULL, + INDEX idx_alf_prop_str_start (string_value(32)), + INDEX idx_alf_prop_str_end (string_end), PRIMARY KEY (id) ) ENGINE=InnoDB; diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml index ce63a42484..4b40761679 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml @@ -44,6 +44,7 @@ + @@ -91,8 +92,8 @@ - insert into alf_prop_string_value (string_value) - values (#stringValue#) + insert into alf_prop_string_value (string_value, string_end) + values (#stringValue#, #stringEnd#) @@ -170,23 +171,41 @@ - select - * + string_value from alf_prop_string_value where id = #id# - + diff --git a/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java b/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java index 5ded453e98..d405c7584e 100644 --- a/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java @@ -423,18 +423,6 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO */ private class PropertyStringValueCallbackDAO extends EntityLookupCallbackDAOAdaptor> { - private final Pair convertEntityToPair(PropertyStringValueEntity entity) - { - if (entity == null) - { - return null; - } - else - { - return entity.getEntityPair(); - } - } - public Pair getValueKey(String value) { return CrcHelper.getStringCrcPair(value, 128, true, true); @@ -442,26 +430,40 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO public Pair createValue(String value) { - PropertyStringValueEntity entity = createStringValue(value); - return convertEntityToPair(entity); + Long key = createStringValue(value); + return new Pair(key, value); } public Pair findByKey(Long key) { - PropertyStringValueEntity entity = findStringValueById(key); - return convertEntityToPair(entity); + String value = findStringValueById(key); + if (value == null) + { + return null; + } + else + { + return new Pair(key, value); + } } public Pair findByValue(String value) { - PropertyStringValueEntity entity = findStringValueByValue(value); - return convertEntityToPair(entity); + Long key = findStringValueByValue(value); + if (key == null) + { + return null; + } + else + { + return new Pair(key, value); + } } } - protected abstract PropertyStringValueEntity findStringValueById(Long id); - protected abstract PropertyStringValueEntity findStringValueByValue(String value); - protected abstract PropertyStringValueEntity createStringValue(String value); + protected abstract String findStringValueById(Long id); + protected abstract Long findStringValueByValue(String value); + protected abstract Long createStringValue(String value); //================================ // 'alf_prop_double_value' accessors diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java b/source/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java index d8e12c72e6..a96b49d3ab 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java @@ -37,6 +37,7 @@ public class PropertyStringValueEntity { private Long id; private String stringValue; + private String stringEnd; public PropertyStringValueEntity() { @@ -81,6 +82,23 @@ public class PropertyStringValueEntity { return new Pair(id, stringValue); } + + /** + * Set the string and string-end values + */ + public void setValue(String value) + { + this.stringValue = value; + int len = stringValue.length(); + if (len > 16) + { + stringEnd = stringValue.substring(len - 16); + } + else + { + stringEnd = stringValue; + } + } public Long getId() { @@ -101,4 +119,14 @@ public class PropertyStringValueEntity { this.stringValue = stringValue; } + + public String getStringEnd() + { + return stringEnd; + } + + public void setStringEnd(String stringEnd) + { + this.stringEnd = stringEnd; + } } diff --git a/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java b/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java index 76050a4c73..1f287e8a1b 100644 --- a/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java @@ -157,34 +157,34 @@ public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl //================================ @Override - protected PropertyStringValueEntity findStringValueById(Long id) + protected String findStringValueById(Long id) { PropertyStringValueEntity entity = new PropertyStringValueEntity(); entity.setId(id); - entity = (PropertyStringValueEntity) template.queryForObject( + String value = (String) template.queryForObject( SELECT_PROPERTY_STRING_VALUE_BY_ID, entity); // Done - return entity; + return value; } @SuppressWarnings("unchecked") @Override - protected PropertyStringValueEntity findStringValueByValue(String value) + protected Long findStringValueByValue(String value) { PropertyStringValueEntity entity = new PropertyStringValueEntity(); - entity.setStringValue(value); + entity.setValue(value); List results = (List) template.queryForList( SELECT_PROPERTY_STRING_VALUE_BY_VALUE, entity); - // There double be several matches (if the database is case-insensitive), so find the first + // There could be several matches (if the database is case-insensitive), so find the first // value that matches exactly. for (PropertyStringValueEntity resultEntity : results) { if (value.equals(resultEntity.getStringValue())) { // Found a match - return resultEntity; + return resultEntity.getId(); } } // No real match @@ -192,14 +192,13 @@ public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl } @Override - protected PropertyStringValueEntity createStringValue(String value) + protected Long createStringValue(String value) { PropertyStringValueEntity entity = new PropertyStringValueEntity(); - entity.setStringValue(value); + entity.setValue(value); Long id = (Long) template.insert(INSERT_PROPERTY_STRING_VALUE, entity); - entity.setId(id); // Done - return entity; + return id; } //================================