You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by sa...@apache.org on 2016/06/01 21:28:18 UTC
phoenix git commit: Ignore serial hint for queries doing an ORDER BY
not along the PK axis
Repository: phoenix
Updated Branches:
refs/heads/4.x-HBase-0.98 e8c4582fa -> e5ff1dab8
Ignore serial hint for queries doing an ORDER BY not along the PK axis
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e5ff1dab
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e5ff1dab
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e5ff1dab
Branch: refs/heads/4.x-HBase-0.98
Commit: e5ff1dab8253c7e3a248faed6aefd9b932352988
Parents: e8c4582
Author: Samarth <sa...@salesforce.com>
Authored: Wed Jun 1 14:28:08 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Wed Jun 1 14:28:08 2016 -0700
----------------------------------------------------------------------
.../org/apache/phoenix/execute/ScanPlan.java | 3 +--
.../java/org/apache/phoenix/util/ScanUtil.java | 13 ++++++----
.../org/apache/phoenix/query/QueryPlanTest.java | 26 ++++++++++++++++++++
3 files changed, 35 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e5ff1dab/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java
index 9fbdb3a..cdd0703 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java
@@ -119,8 +119,7 @@ public class ScanPlan extends BaseQueryPlan {
* If a limit is provided and we have no filter, run the scan serially when we estimate that
* the limit's worth of data will fit into a single region.
*/
- boolean isOrdered = !orderBy.getOrderByExpressions().isEmpty();
- Integer perScanLimit = !allowPageFilter || isOrdered ? null : limit;
+ Integer perScanLimit = !allowPageFilter ? null : limit;
if (perScanLimit == null || scan.getFilter() != null) {
return false;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e5ff1dab/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
index f9e9913..f3e3d28 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
@@ -876,12 +876,15 @@ public class ScanUtil {
public static final boolean canQueryBeExecutedSerially(PTable table, OrderBy orderBy, StatementContext context) {
/*
- * For salted or local index tables, if rows are requested in a row key order, then we
- * cannot execute a query serially. We need to be able to do a merge sort across all scans
- * which isn't possible with SerialIterators. For other kinds of tables though we are ok
- * since SerialIterators execute scans in the correct order.
+ * If ordering by columns not on the PK axis, we can't execute a query serially because we
+ * need to do a merge sort across all the scans which isn't possible with SerialIterators.
+ * Similar reasoning follows for salted and local index tables when ordering rows in a row
+ * key order. Serial execution is OK in other cases since SerialIterators will execute scans
+ * in the correct order.
*/
- if ((table.getBucketNum() != null || table.getIndexType() == IndexType.LOCAL) && shouldRowsBeInRowKeyOrder(orderBy, context)) {
+ if (!orderBy.getOrderByExpressions().isEmpty()
+ || ((table.getBucketNum() != null || table.getIndexType() == IndexType.LOCAL) && shouldRowsBeInRowKeyOrder(
+ orderBy, context))) {
return false;
}
return true;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e5ff1dab/phoenix-core/src/test/java/org/apache/phoenix/query/QueryPlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryPlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryPlanTest.java
index b00ccc0..8af832b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryPlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryPlanTest.java
@@ -277,5 +277,31 @@ public class QueryPlanTest extends BaseConnectionlessQueryTest {
conn.close();
}
}
+
+ @Test
+ public void testSerialHintIgnoredForNonRowkeyOrderBy() throws Exception {
+
+ Properties props = PropertiesUtil.deepCopy(new Properties());
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ try {
+ conn.createStatement().execute("CREATE TABLE FOO(\n" +
+ " a VARCHAR NOT NULL,\n" +
+ " b TIMESTAMP NOT NULL,\n" +
+ " c VARCHAR,\n" +
+ " CONSTRAINT pk PRIMARY KEY (a, b DESC, c)\n" +
+ " )");
+ String query = "select /*+ SERIAL*/ * from foo where a = 'a' ORDER BY b, c";
+ ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+ String queryPlan = QueryUtil.getExplainPlan(rs);
+ assertEquals(
+ "CLIENT PARALLEL 1-WAY RANGE SCAN OVER FOO ['a']\n" +
+ " SERVER FILTER BY FIRST KEY ONLY\n" +
+ " SERVER SORTED BY [B, C]\n" +
+ "CLIENT MERGE SORT", queryPlan);
+ } finally {
+ conn.close();
+ }
+
+ }
}