Repository: phoenix Updated Branches: refs/heads/4.13-HBase-0.98 9ab3bbe61 -> 455d0a6e4
PHOENIX-4397 Incorrect query results when with stats are disabled on a salted table Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/455d0a6e Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/455d0a6e Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/455d0a6e Branch: refs/heads/4.13-HBase-0.98 Commit: 455d0a6e4b94f67d44caa228f5fe2aef12082271 Parents: 9ab3bbe Author: Samarth Jain <sama...@apache.org> Authored: Fri Dec 8 14:46:24 2017 -0800 Committer: Samarth Jain <sama...@apache.org> Committed: Fri Dec 8 14:46:24 2017 -0800 ---------------------------------------------------------------------- .../end2end/ExplainPlanWithStatsEnabledIT.java | 36 ++++++++++++++++++++ .../phoenix/iterate/BaseResultIterators.java | 6 +--- 2 files changed, 37 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/455d0a6e/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java index a662986..c15641d 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java @@ -1068,4 +1068,40 @@ public class ExplainPlanWithStatsEnabledIT extends ParallelStatsEnabledIT { .getQueryPlan().getScans().get(0).size()); } } + + @Test + public void testQueryingWithUseStatsForParallelizationOnOff() throws SQLException { + testUseStatsForParallelizationOnSaltedTable(true, true); + testUseStatsForParallelizationOnSaltedTable(true, false); + testUseStatsForParallelizationOnSaltedTable(false, true); + testUseStatsForParallelizationOnSaltedTable(false, false); + } + + private void testUseStatsForParallelizationOnSaltedTable(boolean useStatsFlag, boolean salted) + throws SQLException { + String tableName = generateUniqueName(); + Connection conn = DriverManager.getConnection(getUrl()); + conn.createStatement().execute( + "create table " + tableName + "(k varchar not null primary key, v varchar) " + + (salted ? " SALT_BUCKETS=2," : "") + " USE_STATS_FOR_PARALLELIZATION=" + + useStatsFlag); + conn.createStatement().execute("upsert into " + tableName + " values ('1', 'B')"); + conn.createStatement().execute("upsert into " + tableName + " values ('2', 'A')"); + conn.commit(); + String query = "SELECT V FROM " + tableName + " ORDER BY V"; + ResultSet rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("A", rs.getString(1)); + assertTrue(rs.next()); + assertEquals("B", rs.getString(1)); + + // Collect stats and make sure query still works correctly + conn.createStatement().execute("UPDATE STATISTICS " + tableName); + rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("A", rs.getString(1)); + assertTrue(rs.next()); + assertEquals("B", rs.getString(1)); + } + } http://git-wip-us.apache.org/repos/asf/phoenix/blob/455d0a6e/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java index f397c8a..f9b90b4 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java @@ -609,11 +609,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result estimate.bytesEstimate += gpsBytes; } } - if (startNewScan && !scans.isEmpty() && useStatsForParallelization) { - /* - * Note that even if region boundary was crossed, if we are not using stats for - * parallelization, nothing gets added to the parallel scans. - */ + if (startNewScan && !scans.isEmpty()) { parallelScans.add(scans); scans = Lists.newArrayListWithExpectedSize(1); }