You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/11/12 22:52:04 UTC

[GitHub] [phoenix] gjacoby126 commented on a change in pull request #961: PHOENIX-6218 Rows deleted count is incorrect for immutable tables with indexes

gjacoby126 commented on a change in pull request #961:
URL: https://github.com/apache/phoenix/pull/961#discussion_r522483197



##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
##########
@@ -899,6 +899,39 @@ public void testUpdateNonIndexedColumn() throws Exception {
       }
   }
 
+    @Test
+    public void testDeleteCount_nonPK() throws Exception {
+        String schemaName = generateUniqueName();
+        String dataTableName = "TBL_" + generateUniqueName();

Review comment:
       is there a reason we need this test carried over from the immutable index test but not the others? 

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
##########
@@ -630,4 +632,181 @@ public Thread newThread(Runnable r) {
         }
     }
 
+    @Test
+    public void testDeleteCount_PK() throws Exception {
+        String schemaName = generateUniqueName();
+        String dataTableName = "TBL_" + generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = "IND_" + generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName
+                + " (ID INTEGER NOT NULL PRIMARY KEY, VAL1 INTEGER, VAL2 INTEGER) "
+                + this.tableDDLOptions);
+
+            conn.createStatement().execute(String.format(
+                "CREATE INDEX %s ON %s (VAL1) INCLUDE (VAL2)", indexTableName, dataTableFullName));
+
+            PreparedStatement dataPreparedStatement =
+                conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?)");
+            for (int i = 1; i <= 10; i++) {
+                dataPreparedStatement.setInt(1, i);
+                dataPreparedStatement.setInt(2, i + 1);
+                dataPreparedStatement.setInt(3, i * 2);
+                dataPreparedStatement.execute();
+            }
+            conn.commit();
+
+            PreparedStatement deleteStmt =
+                conn.prepareStatement("DELETE FROM " + dataTableFullName + " WHERE ID > 5");
+            assertEquals(5, deleteStmt.executeUpdate());
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testDeleteCount_nonPK() throws Exception {
+        String schemaName = generateUniqueName();
+        String dataTableName = "TBL_" + generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = "IND_" + generateUniqueName();
+        String indexTableName2 = "IND_" + generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName
+                + " (ID INTEGER NOT NULL PRIMARY KEY, VAL1 INTEGER, VAL2 INTEGER) "
+                + this.tableDDLOptions);
+
+            conn.createStatement().execute(String.format(
+                "CREATE INDEX %s ON %s (VAL1) INCLUDE (VAL2)", indexTableName, dataTableFullName));
+
+            conn.createStatement().execute(String.format(
+                "CREATE INDEX %s ON %s (VAL2) INCLUDE (VAL1)", indexTableName2, dataTableFullName));
+
+            PreparedStatement dataPreparedStatement =
+                conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?)");
+            for (int i = 1; i <= 10; i++) {
+                dataPreparedStatement.setInt(1, i);
+                dataPreparedStatement.setInt(2, i + 1);
+                dataPreparedStatement.setInt(3, i * 2);
+                dataPreparedStatement.execute();
+            }
+            conn.commit();
+
+            PreparedStatement deleteStmt =
+                conn.prepareStatement("DELETE FROM " + dataTableFullName + " WHERE VAL1 > 6");
+            assertEquals(5, deleteStmt.executeUpdate());
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testDeleteCount_limit() throws Exception {
+        String schemaName = generateUniqueName();
+        String dataTableName = "TBL_" + generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = "IND_" + generateUniqueName();
+        String indexTableName2 = "IND_" + generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName
+                + " (ID INTEGER NOT NULL PRIMARY KEY, VAL1 INTEGER, VAL2 INTEGER) "
+                + this.tableDDLOptions);
+
+            conn.createStatement().execute(String.format(
+                "CREATE INDEX %s ON %s (VAL1) INCLUDE (VAL2)", indexTableName, dataTableFullName));
+
+            conn.createStatement().execute(String.format(
+                "CREATE INDEX %s ON %s (VAL2) INCLUDE (VAL1)", indexTableName2, dataTableFullName));
+
+            PreparedStatement dataPreparedStatement =
+                conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?)");
+            for (int i = 1; i <= 10; i++) {
+                dataPreparedStatement.setInt(1, i);
+                dataPreparedStatement.setInt(2, i + 1);
+                dataPreparedStatement.setInt(3, i * 2);
+                dataPreparedStatement.execute();
+            }
+            conn.commit();
+
+            PreparedStatement deleteStmt =
+                conn.prepareStatement("DELETE FROM " + dataTableFullName + " WHERE VAL1 > 6 LIMIT 3");
+            assertEquals(3, deleteStmt.executeUpdate());
+            conn.commit();
+        }
+    }
+
+    @Test
+    public void testDeleteCount_noCoveredColumn() throws Exception {
+        String schemaName = generateUniqueName();
+        String dataTableName = "TBL_" + generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = "IND_" + generateUniqueName();
+        String indexTableName2 = "IND_" + generateUniqueName();

Review comment:
       Setup code looks copy-pasted multiple times; could you please extract to a helper method?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org