From commits-return-19771-archive-asf-public=cust-asf.ponee.io@phoenix.apache.org Sat Mar 10 00:55:55 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id E7D4A180677 for ; Sat, 10 Mar 2018 00:55:54 +0100 (CET) Received: (qmail 92195 invoked by uid 500); 9 Mar 2018 23:55:54 -0000 Mailing-List: contact commits-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list commits@phoenix.apache.org Received: (qmail 92129 invoked by uid 99); 9 Mar 2018 23:55:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Mar 2018 23:55:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A492FF3536; Fri, 9 Mar 2018 23:55:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamestaylor@apache.org To: commits@phoenix.apache.org Date: Fri, 09 Mar 2018 23:55:55 -0000 Message-Id: In-Reply-To: <6d30753d543e49d98c71aab182db1b0d@git.apache.org> References: <6d30753d543e49d98c71aab182db1b0d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/4] phoenix git commit: PHOENIX-1267 Set scan.setSmall(true) when appropriate (Abhishek Singh Chouhan) PHOENIX-1267 Set scan.setSmall(true) when appropriate (Abhishek Singh Chouhan) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/6b6c8334 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6b6c8334 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6b6c8334 Branch: refs/heads/4.x-HBase-0.98 Commit: 6b6c8334637530918081d0f5d226ec74b96dab37 Parents: d542566 Author: James Taylor Authored: Thu Mar 8 14:38:28 2018 -0800 Committer: James Taylor Committed: Fri Mar 9 15:53:28 2018 -0800 ---------------------------------------------------------------------- .../apache/phoenix/execute/BaseQueryPlan.java | 18 +++++++++---- .../org/apache/phoenix/query/QueryServices.java | 2 ++ .../phoenix/query/QueryServicesOptions.java | 1 + .../phoenix/compile/QueryCompilerTest.java | 27 ++++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b6c8334/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java index d923d2f..df55e63 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java @@ -62,6 +62,8 @@ import org.apache.phoenix.parse.HintNode.Hint; import org.apache.phoenix.parse.ParseNodeFactory; import org.apache.phoenix.parse.TableName; import org.apache.phoenix.query.QueryConstants; +import org.apache.phoenix.query.QueryServices; +import org.apache.phoenix.query.QueryServicesOptions; import org.apache.phoenix.schema.KeyValueSchema; import org.apache.phoenix.schema.PColumn; import org.apache.phoenix.schema.PName; @@ -235,12 +237,14 @@ public abstract class BaseQueryPlan implements QueryPlan { scan = context.getScan(); } + ScanRanges scanRanges = context.getScanRanges(); + /* * For aggregate queries, we still need to let the AggregationPlan to * proceed so that we can give proper aggregates even if there are no * row to be scanned. */ - if (context.getScanRanges() == ScanRanges.NOTHING && !getStatement().isAggregate()) { + if (scanRanges == ScanRanges.NOTHING && !getStatement().isAggregate()) { return getWrappedIterator(caches, ResultIterator.EMPTY_ITERATOR); } @@ -267,12 +271,16 @@ public abstract class BaseQueryPlan implements QueryPlan { } } - if (statement.getHint().hasHint(Hint.SMALL)) { + + PhoenixConnection connection = context.getConnection(); + final int smallScanThreshold = connection.getQueryServices().getProps().getInt(QueryServices.SMALL_SCAN_THRESHOLD_ATTRIB, + QueryServicesOptions.DEFAULT_SMALL_SCAN_THRESHOLD); + + if (statement.getHint().hasHint(Hint.SMALL) || (scanRanges.isPointLookup() && scanRanges.getPointLookupCount() < smallScanThreshold)) { scan.setSmall(true); } - PhoenixConnection connection = context.getConnection(); - if (!table.isTransactional()) { + if (!table.isTransactional()) { // Get the time range of row_timestamp column TimeRange rowTimestampRange = context.getScanRanges().getRowTimestampRange(); // Get the already existing time range on the scan. @@ -541,4 +549,4 @@ public abstract class BaseQueryPlan implements QueryPlan { return estimateInfoTimestamp; } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b6c8334/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java index 1ec91fd..56d6e06 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java @@ -290,6 +290,8 @@ public interface QueryServices extends SQLCloseable { //Update Cache Frequency default config attribute public static final String DEFAULT_UPDATE_CACHE_FREQUENCY_ATRRIB = "phoenix.default.update.cache.frequency"; + public static final String SMALL_SCAN_THRESHOLD_ATTRIB = "phoenix.query.smallScanThreshold"; + /** * Get executor service used for parallel scans */ http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b6c8334/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java index b30413c..33a319b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java @@ -310,6 +310,7 @@ public class QueryServicesOptions { //default update cache frequency public static final int DEFAULT_UPDATE_CACHE_FREQUENCY = 0; + public static final int DEFAULT_SMALL_SCAN_THRESHOLD = 100; @SuppressWarnings("serial") public static final Set DEFAULT_QUERY_SERVER_SKIP_WORDS = new HashSet() { http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b6c8334/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java index 1d61003..deed381 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java @@ -4387,4 +4387,31 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest { assertEquals(6, outerScans.size()); } } + + @Test + public void testSmallScanForPointLookups() throws SQLException { + Properties props = PropertiesUtil.deepCopy(new Properties()); + createTestTable(getUrl(), "CREATE TABLE FOO(\n" + + " a VARCHAR NOT NULL,\n" + + " b VARCHAR NOT NULL,\n" + + " c VARCHAR,\n" + + " CONSTRAINT pk PRIMARY KEY (a, b DESC, c)\n" + + " )"); + + props.put(QueryServices.SMALL_SCAN_THRESHOLD_ATTRIB, "2"); + try (Connection conn = DriverManager.getConnection(getUrl(), props)) { + String query = "select * from foo where a = 'a' and b = 'b' and c in ('x','y','z')"; + PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class); + QueryPlan plan = stmt.optimizeQuery(query); + plan.iterator(); + //Fail since we have 3 rows in pointLookup + assertFalse(plan.getContext().getScan().isSmall()); + query = "select * from foo where a = 'a' and b = 'b' and c = 'c'"; + plan = stmt.compileQuery(query); + plan.iterator(); + //Should be small scan, query is for single row pointLookup + assertTrue(plan.getContext().getScan().isSmall()); + } + } + }