Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.0 837838980 -> 44280897c
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/44280897 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/44280897 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/44280897 Branch: refs/heads/4.x-HBase-1.0 Commit: 44280897c38320fb095f6b1a8d9ad33940cf3718 Parents: 8378389 Author: Samarth <[email protected]> Authored: Wed Jun 1 14:34:35 2016 -0700 Committer: Samarth <[email protected]> Committed: Wed Jun 1 14:34:35 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/44280897/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/44280897/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/44280897/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(); + } + + } }
