Skip to content

Commit

Permalink
auto index on relationship sets even though the value hasn't changed
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Mar 11, 2019
1 parent 5bb9152 commit 835f7ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Expand Up @@ -565,9 +565,10 @@ public Value relationshipSetProperty( long relationship, int propertyKey, Value
}
else
{
// We need to auto-index even if not actually changing the value.
autoIndexing.relationships().propertyChanged( this, relationship, propertyKey, existingValue, value );
if ( propertyHasChanged( existingValue, value ) )
{
autoIndexing.relationships().propertyChanged( this, relationship, propertyKey, existingValue, value );

ktx.txState().relationshipDoReplaceProperty( relationship, propertyKey, existingValue, value );
}
Expand Down
Expand Up @@ -42,7 +42,7 @@ public class AutoIndexAcceptanceTest
public DatabaseRule db = new EnterpriseDatabaseRule();

@Test
public void shouldAutoIndexOnSetEvenIfValueNotChanged() throws IOException
public void shouldAutoIndexOnNodeSetEvenIfValueNotChanged() throws IOException
{
// Given
try ( Transaction tx = db.beginTx() )
Expand All @@ -55,10 +55,30 @@ public void shouldAutoIndexOnSetEvenIfValueNotChanged() throws IOException
GraphDatabaseSettings.node_keys_indexable.name(), "name" );

// When, set with same value as it had before
assertThat( asList( db.execute( "MATCH (p) WITH p, p.name as name SET p.name = name RETURN count(p)" ) ), hasSize(1));
assertThat( asList( db.execute( "MATCH (p) WITH p, p.name AS name SET p.name = name RETURN count(p)" ) ), hasSize(1));

// Then, we should be able to find it in the index
assertThat( asList( db.execute( "START i=node:node_auto_index('name:test') return i limit 1" ) ), hasSize(1));
assertThat( asList( db.execute( "START i=node:node_auto_index('name:test') RETURN i" ) ), hasSize(1));
}

@Test
public void shouldAutoIndexOnRelationshipSetEvenIfValueNotChanged() throws IOException
{
// Given
try ( Transaction tx = db.beginTx() )
{
db.execute( "CREATE ()-[:R {name:'test'}]->(), ()-[:R {name:'test2'}]->()" );
tx.success();
}
db.restartDatabase(
GraphDatabaseSettings.relationship_auto_indexing.name(), "true",
GraphDatabaseSettings.relationship_keys_indexable.name(), "name" );

// When, set with same value as it had before
assertThat( asList( db.execute( "MATCH ()-[r]->() WITH r, r.name AS name SET r.name = name RETURN count(r)" ) ), hasSize(1));

// Then, we should be able to find it in the index
assertThat( asList( db.execute( "START i=relationship:relationship_auto_index('name:test') RETURN i" ) ), hasSize(1));

}
}

0 comments on commit 835f7ef

Please sign in to comment.