-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8842 from systay/3.2-top-lp
Support Top in the compiled runtime
- Loading branch information
Showing
21 changed files
with
795 additions
and
105 deletions.
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
34 changes: 34 additions & 0 deletions
34
....2/src/main/scala/org/neo4j/cypher/internal/compiler/v3_2/planner/logical/plans/Top.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,34 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "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.internal.compiler.v3_2.planner.logical.plans | ||
|
||
import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.SortDescription | ||
import org.neo4j.cypher.internal.compiler.v3_2.planner.{CardinalityEstimation, PlannerQuery} | ||
import org.neo4j.cypher.internal.frontend.v3_2.ast.Expression | ||
import org.neo4j.cypher.internal.ir.v3_2.IdName | ||
|
||
case class Top(left: LogicalPlan, sortItems: Seq[SortDescription], limit: Expression) | ||
(val solved: PlannerQuery with CardinalityEstimation) extends LogicalPlan with EagerLogicalPlan { | ||
override def lhs: Option[LogicalPlan] = Some(left) | ||
|
||
override def rhs: Option[LogicalPlan] = None | ||
|
||
override def availableSymbols: Set[IdName] = left.availableSymbols | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...scala/org/neo4j/cypher/internal/compiler/v3_2/planner/logical/plans/rewriter/useTop.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,36 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "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.internal.compiler.v3_2.planner.logical.plans.rewriter | ||
|
||
import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.plans.{DoNotIncludeTies, Limit, Sort, Top} | ||
import org.neo4j.cypher.internal.frontend.v3_2.{Rewriter, bottomUp} | ||
|
||
/** | ||
* When doing ORDER BY c1,c2,...,cn LIMIT e, we don't have to sort the full result in one go | ||
*/ | ||
case object useTop extends Rewriter { | ||
|
||
private val instance: Rewriter = bottomUp(Rewriter.lift { | ||
case o @ Limit(Sort(src, sortDescriptions), limit, DoNotIncludeTies) => | ||
Top(src, sortDescriptions, limit)(o.solved) | ||
}) | ||
|
||
override def apply(input: AnyRef): AnyRef = instance.apply(input) | ||
} |
49 changes: 49 additions & 0 deletions
49
...a/org/neo4j/cypher/internal/compiler/v3_2/planner/logical/plans/rewriter/UseTopTest.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,49 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "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.internal.compiler.v3_2.planner.logical.plans.rewriter | ||
|
||
import org.neo4j.cypher.internal.compiler.v3_2.planner.LogicalPlanningTestSupport | ||
import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.Ascending | ||
import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.plans._ | ||
import org.neo4j.cypher.internal.frontend.v3_2.ast.AstConstructionTestSupport | ||
import org.neo4j.cypher.internal.frontend.v3_2.helpers.fixedPoint | ||
import org.neo4j.cypher.internal.frontend.v3_2.test_helpers.CypherFunSuite | ||
|
||
class UseTopTest extends CypherFunSuite with LogicalPlanningTestSupport with AstConstructionTestSupport { | ||
private val leaf = newMockedLogicalPlan() | ||
private val sortDescription = Seq(Ascending("x")) | ||
private val sort = Sort(leaf, sortDescription)(solved) | ||
private val lit10 = literalInt(10) | ||
|
||
test("should use Top when possible") { | ||
val limit = Limit(sort, lit10, DoNotIncludeTies)(solved) | ||
|
||
rewrite(limit) should equal(Top(leaf, sortDescription, lit10)(solved)) | ||
} | ||
|
||
test("should not use Top when including ties") { | ||
val original = Limit(sort, lit10, IncludeTies)(solved) | ||
|
||
rewrite(original) should equal(original) | ||
} | ||
|
||
private def rewrite(p: LogicalPlan): LogicalPlan = | ||
fixedPoint((p: LogicalPlan) => p.endoRewrite(useTop))(p) | ||
} |
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
56 changes: 56 additions & 0 deletions
56
...pher/acceptance-spec-suite/src/test/resources/cypher/features/SkipLimitAcceptance.feature
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,56 @@ | ||
# | ||
# Copyright (c) 2002-2017 "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 Affero 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 Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
Feature: SkipLimitAcceptance.feature | ||
|
||
Background: | ||
Given an empty graph | ||
|
||
Scenario: Negative parameter for LIMIT should not generate errors | ||
And having executed: | ||
""" | ||
CREATE (s:Person {name: 'Steven'}), | ||
(c:Person {name: 'Craig'}) | ||
""" | ||
And parameters are: | ||
| limit | -1 | | ||
When executing query: | ||
""" | ||
MATCH (p:Person) | ||
RETURN p.name AS name | ||
LIMIT $limit | ||
""" | ||
Then the result should be, in order: | ||
| name | | ||
And no side effects | ||
|
||
Scenario: Negative LIMIT should fail with a syntax exception | ||
And having executed: | ||
""" | ||
CREATE (s:Person {name: 'Steven'}), | ||
(c:Person {name: 'Craig'}) | ||
""" | ||
When executing query: | ||
""" | ||
MATCH (p:Person) | ||
RETURN p.name AS name | ||
LIMIT -1 | ||
""" | ||
Then a SyntaxError should be raised at compile time: NegativeIntegerArgument |
Oops, something went wrong.