-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop taking locks when reading from unique indexes #5988
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c041407
Stop taking locks when reading from unique indexes (Cost planner)
systay 70a036a
Stop taking locks when reading from unique indexes (Rule planner)
systay cfb6d02
Renamed QueryContext method to signify what it actually does
systay 5c537a2
Add test for no locking when using index search
henriknyman File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
community/cypher/cypher/src/test/scala/org/neo4j/cypher/UniqueIndexUsageAcceptanceTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Copyright (c) 2002-2015 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.cypher | ||
|
||
class UniqueIndexUsageAcceptanceTest extends ExecutionEngineFunSuite with NewPlannerTestSupport { | ||
test("should be able to use indexes") { | ||
given() | ||
|
||
// When | ||
val result = executeWithAllPlanners("MATCH (n:Crew) WHERE n.name = 'Neo' RETURN n") | ||
|
||
// Then | ||
result.executionPlanDescription().toString should include("NodeUniqueIndexSeek") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Probably not in 2.2 |
||
result should have size 1 | ||
} | ||
|
||
test("should not forget predicates") { | ||
given() | ||
|
||
// When | ||
val result = executeWithAllPlanners("MATCH (n:Crew) WHERE n.name = 'Neo' AND n.name = 'Morpheus' RETURN n") | ||
|
||
// Then | ||
result shouldBe empty | ||
result.executionPlanDescription().toString should include("NodeUniqueIndexSeek") | ||
} | ||
|
||
test("should use index when there are multiple labels on the node") { | ||
given() | ||
|
||
// When | ||
val result = executeWithAllPlanners("MATCH (n:Matrix:Crew) WHERE n.name = 'Cypher' RETURN n") | ||
|
||
// Then | ||
result.executionPlanDescription().toString should include("NodeUniqueIndexSeek") | ||
result should have size 1 | ||
} | ||
|
||
test("should be able to use value coming from UNWIND for index seek") { | ||
// Given | ||
graph.createConstraint("Prop", "id") | ||
val n1 = createLabeledNode(Map("id" -> 1), "Prop") | ||
val n2 = createLabeledNode(Map("id" -> 2), "Prop") | ||
val n3 = createLabeledNode(Map("id" -> 3), "Prop") | ||
for (i <- 4 to 30) createLabeledNode(Map("id" -> i), "Prop") | ||
|
||
// When | ||
val result = executeWithAllPlanners("unwind [1,2,3] as x match (n:Prop) where n.id = x return n;") | ||
|
||
// Then | ||
result.toList should equal(List(Map("n" -> n1), Map("n" -> n2), Map("n" -> n3))) | ||
result.executionPlanDescription().toString should include("NodeUniqueIndexSeek") | ||
} | ||
|
||
test("should handle nulls in index lookup") { | ||
// Given | ||
val cat = createLabeledNode("Cat") | ||
val dog = createLabeledNode("Dog") | ||
relate(cat, dog, "FRIEND_OF") | ||
|
||
// create many nodes with label 'Place' to make sure index seek is planned | ||
(1 to 100).foreach(i => createLabeledNode(Map("name" -> s"Area $i"), "Place")) | ||
|
||
graph.createConstraint("Place", "name") | ||
|
||
// When | ||
val result = executeWithCostPlannerOnly( | ||
""" | ||
|MATCH ()-[f:FRIEND_OF]->() | ||
|WITH f.placeName AS placeName | ||
|OPTIONAL MATCH (p:Place) | ||
|WHERE p.name = placeName | ||
|RETURN p, placeName | ||
""".stripMargin) | ||
|
||
// Then | ||
result.toList should equal(List(Map("p" -> null, "placeName" -> null))) | ||
} | ||
|
||
test("should not use indexes when RHS of property comparison depends on the node searched for (equality)") { | ||
// Given | ||
val n1 = createLabeledNode(Map("a" -> 0, "b" -> 1), "MyNodes") | ||
val n2 = createLabeledNode(Map("a" -> 1, "b" -> 1), "MyNodes") | ||
val n3 = createLabeledNode(Map("a" -> 2, "b" -> 2), "MyNodes") | ||
val n4 = createLabeledNode(Map("a" -> 3, "b" -> 5), "MyNodes") | ||
|
||
graph.createConstraint("MyNodes", "a") | ||
|
||
val query = | ||
"""|MATCH (m:MyNodes) | ||
|WHERE m.a = m.b | ||
|RETURN m""".stripMargin | ||
|
||
// When | ||
val result = executeWithAllPlanners(query) | ||
|
||
// Then | ||
result.toList should equal(List( | ||
Map("m" -> n2), | ||
Map("m" -> n3) | ||
)) | ||
result.executionPlanDescription().toString shouldNot include("Index") | ||
} | ||
|
||
private def given() { | ||
executeWithRulePlannerOnly( | ||
"""CREATE (architect:Matrix { name:'The Architect' }), | ||
| (smith:Matrix { name:'Agent Smith' }), | ||
| (cypher:Matrix:Crew { name:'Cypher' }), | ||
| (trinity:Crew { name:'Trinity' }), | ||
| (morpheus:Crew { name:'Morpheus' }), | ||
| (neo:Crew { name:'Neo' }), | ||
| smith-[:CODED_BY]->architect, | ||
| cypher-[:KNOWS]->smith, | ||
| morpheus-[:KNOWS]->trinity, | ||
| morpheus-[:KNOWS]->cypher, | ||
| neo-[:KNOWS]->morpheus, | ||
| neo-[:LOVES]->trinity""".stripMargin) | ||
|
||
for (i <- 1 to 10) createLabeledNode(Map("name" -> ("Joe" + i)), "Crew") | ||
|
||
for (i <- 1 to 10) createLabeledNode(Map("name" -> ("Smith" + i)), "Matrix") | ||
|
||
graph.createConstraint("Crew", "name") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming of these methods is a bit inconsistent. Maybe call this one
lockingExactIndexSearch
?Or maybe we can name them
exactIndexSearchForRead
andexactIndexSearchForWrite
.