[1/2] phoenix git commit: PHOENIX-4712 When creating an index on a table, meta data cache of views related to the table isn't updated [Forced Update!]
Repository: phoenix Updated Branches: refs/heads/4.x-cdh5.14 2b22c2986 -> c943a5715 (forced update) PHOENIX-4712 When creating an index on a table, meta data cache of views related to the table isn't updated Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/cf4ee4bd Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/cf4ee4bd Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/cf4ee4bd Branch: refs/heads/4.x-cdh5.14 Commit: cf4ee4bd8a19584dea1030e1033c7c6d5b30a592 Parents: 6b5ff31 Author: Thomas D'SilvaAuthored: Tue May 1 21:32:45 2018 +0100 Committer: Pedro Boado Committed: Wed May 2 09:03:25 2018 +0100 -- .../java/org/apache/phoenix/end2end/ViewIT.java | 46 .../apache/phoenix/schema/MetaDataClient.java | 11 +++-- 2 files changed, 53 insertions(+), 4 deletions(-) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/cf4ee4bd/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java index 5c0d100..279bbd7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java @@ -33,6 +33,7 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.util.List; import java.util.Properties; @@ -894,6 +895,51 @@ public class ViewIT extends BaseViewIT { } } +@Test +public void testQueryWithSeparateConnectionForViewOnTableThatHasIndex() throws SQLException { +try (Connection conn = DriverManager.getConnection(getUrl()); +Connection conn2 = DriverManager.getConnection(getUrl()); +Statement s = conn.createStatement(); +Statement s2 = conn2.createStatement()) { +String tableName = generateUniqueName(); +String viewName = generateUniqueName(); +String indexName = generateUniqueName(); +helpTestQueryForViewOnTableThatHasIndex(s, s2, tableName, viewName, indexName); +} +} + +@Test +public void testQueryForViewOnTableThatHasIndex() throws SQLException { +try (Connection conn = DriverManager.getConnection(getUrl()); +Statement s = conn.createStatement()) { +String tableName = generateUniqueName(); +String viewName = generateUniqueName(); +String indexName = generateUniqueName(); +helpTestQueryForViewOnTableThatHasIndex(s, s, tableName, viewName, indexName); +} +} + +private void helpTestQueryForViewOnTableThatHasIndex(Statement s1, Statement s2, String tableName, String viewName, String indexName) +throws SQLException { +// Create a table +s1.execute("create table " + tableName + " (col1 varchar primary key, col2 varchar)"); + +// Create a view on the table +s1.execute("create view " + viewName + " (col3 varchar) as select * from " + tableName); +s1.executeQuery("select * from " + viewName); +// Create a index on the table +s1.execute("create index " + indexName + " ON " + tableName + " (col2)"); + +try (ResultSet rs = +s2.executeQuery("explain select /*+ INDEX(" + viewName + " " + indexName ++ ") */ * from " + viewName + " where col2 = 'aaa'")) { +String explainPlan = QueryUtil.getExplainPlan(rs); + +// check if the query uses the index +assertTrue(explainPlan.contains(indexName)); +} +} + private void validate(String viewName, Connection tenantConn, String[] whereClauseArray, long[] expectedArray) throws SQLException { for (int i = 0; i < whereClauseArray.length; ++i) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/cf4ee4bd/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java index 69d8a56..009289b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java @@ -682,7 +682,7 @@ public class MetaDataClient { // In this case, we update the parent table which may in turn pull //
[1/2] phoenix git commit: PHOENIX-4712 When creating an index on a table, meta data cache of views related to the table isn't updated [Forced Update!]
Repository: phoenix Updated Branches: refs/heads/4.x-cdh5.13 d1a0df37a -> db0d7030d (forced update) PHOENIX-4712 When creating an index on a table, meta data cache of views related to the table isn't updated Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/cf4ee4bd Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/cf4ee4bd Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/cf4ee4bd Branch: refs/heads/4.x-cdh5.13 Commit: cf4ee4bd8a19584dea1030e1033c7c6d5b30a592 Parents: 6b5ff31 Author: Thomas D'SilvaAuthored: Tue May 1 21:32:45 2018 +0100 Committer: Pedro Boado Committed: Wed May 2 09:03:25 2018 +0100 -- .../java/org/apache/phoenix/end2end/ViewIT.java | 46 .../apache/phoenix/schema/MetaDataClient.java | 11 +++-- 2 files changed, 53 insertions(+), 4 deletions(-) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/cf4ee4bd/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java index 5c0d100..279bbd7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java @@ -33,6 +33,7 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.util.List; import java.util.Properties; @@ -894,6 +895,51 @@ public class ViewIT extends BaseViewIT { } } +@Test +public void testQueryWithSeparateConnectionForViewOnTableThatHasIndex() throws SQLException { +try (Connection conn = DriverManager.getConnection(getUrl()); +Connection conn2 = DriverManager.getConnection(getUrl()); +Statement s = conn.createStatement(); +Statement s2 = conn2.createStatement()) { +String tableName = generateUniqueName(); +String viewName = generateUniqueName(); +String indexName = generateUniqueName(); +helpTestQueryForViewOnTableThatHasIndex(s, s2, tableName, viewName, indexName); +} +} + +@Test +public void testQueryForViewOnTableThatHasIndex() throws SQLException { +try (Connection conn = DriverManager.getConnection(getUrl()); +Statement s = conn.createStatement()) { +String tableName = generateUniqueName(); +String viewName = generateUniqueName(); +String indexName = generateUniqueName(); +helpTestQueryForViewOnTableThatHasIndex(s, s, tableName, viewName, indexName); +} +} + +private void helpTestQueryForViewOnTableThatHasIndex(Statement s1, Statement s2, String tableName, String viewName, String indexName) +throws SQLException { +// Create a table +s1.execute("create table " + tableName + " (col1 varchar primary key, col2 varchar)"); + +// Create a view on the table +s1.execute("create view " + viewName + " (col3 varchar) as select * from " + tableName); +s1.executeQuery("select * from " + viewName); +// Create a index on the table +s1.execute("create index " + indexName + " ON " + tableName + " (col2)"); + +try (ResultSet rs = +s2.executeQuery("explain select /*+ INDEX(" + viewName + " " + indexName ++ ") */ * from " + viewName + " where col2 = 'aaa'")) { +String explainPlan = QueryUtil.getExplainPlan(rs); + +// check if the query uses the index +assertTrue(explainPlan.contains(indexName)); +} +} + private void validate(String viewName, Connection tenantConn, String[] whereClauseArray, long[] expectedArray) throws SQLException { for (int i = 0; i < whereClauseArray.length; ++i) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/cf4ee4bd/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java index 69d8a56..009289b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java @@ -682,7 +682,7 @@ public class MetaDataClient { // In this case, we update the parent table which may in turn pull //
[1/2] phoenix git commit: PHOENIX-4712 When creating an index on a table, meta data cache of views related to the table isn't updated [Forced Update!]
Repository: phoenix Updated Branches: refs/heads/4.x-cdh5.12 5de0ec17e -> 719836e8f (forced update) PHOENIX-4712 When creating an index on a table, meta data cache of views related to the table isn't updated Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/cf4ee4bd Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/cf4ee4bd Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/cf4ee4bd Branch: refs/heads/4.x-cdh5.12 Commit: cf4ee4bd8a19584dea1030e1033c7c6d5b30a592 Parents: 6b5ff31 Author: Thomas D'SilvaAuthored: Tue May 1 21:32:45 2018 +0100 Committer: Pedro Boado Committed: Wed May 2 09:03:25 2018 +0100 -- .../java/org/apache/phoenix/end2end/ViewIT.java | 46 .../apache/phoenix/schema/MetaDataClient.java | 11 +++-- 2 files changed, 53 insertions(+), 4 deletions(-) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/cf4ee4bd/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java index 5c0d100..279bbd7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java @@ -33,6 +33,7 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.util.List; import java.util.Properties; @@ -894,6 +895,51 @@ public class ViewIT extends BaseViewIT { } } +@Test +public void testQueryWithSeparateConnectionForViewOnTableThatHasIndex() throws SQLException { +try (Connection conn = DriverManager.getConnection(getUrl()); +Connection conn2 = DriverManager.getConnection(getUrl()); +Statement s = conn.createStatement(); +Statement s2 = conn2.createStatement()) { +String tableName = generateUniqueName(); +String viewName = generateUniqueName(); +String indexName = generateUniqueName(); +helpTestQueryForViewOnTableThatHasIndex(s, s2, tableName, viewName, indexName); +} +} + +@Test +public void testQueryForViewOnTableThatHasIndex() throws SQLException { +try (Connection conn = DriverManager.getConnection(getUrl()); +Statement s = conn.createStatement()) { +String tableName = generateUniqueName(); +String viewName = generateUniqueName(); +String indexName = generateUniqueName(); +helpTestQueryForViewOnTableThatHasIndex(s, s, tableName, viewName, indexName); +} +} + +private void helpTestQueryForViewOnTableThatHasIndex(Statement s1, Statement s2, String tableName, String viewName, String indexName) +throws SQLException { +// Create a table +s1.execute("create table " + tableName + " (col1 varchar primary key, col2 varchar)"); + +// Create a view on the table +s1.execute("create view " + viewName + " (col3 varchar) as select * from " + tableName); +s1.executeQuery("select * from " + viewName); +// Create a index on the table +s1.execute("create index " + indexName + " ON " + tableName + " (col2)"); + +try (ResultSet rs = +s2.executeQuery("explain select /*+ INDEX(" + viewName + " " + indexName ++ ") */ * from " + viewName + " where col2 = 'aaa'")) { +String explainPlan = QueryUtil.getExplainPlan(rs); + +// check if the query uses the index +assertTrue(explainPlan.contains(indexName)); +} +} + private void validate(String viewName, Connection tenantConn, String[] whereClauseArray, long[] expectedArray) throws SQLException { for (int i = 0; i < whereClauseArray.length; ++i) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/cf4ee4bd/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java index 69d8a56..009289b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java @@ -682,7 +682,7 @@ public class MetaDataClient { // In this case, we update the parent table which may in turn pull //