SML0127 commented on code in PR #4104:
URL: https://github.com/apache/flink-cdc/pull/4104#discussion_r2328628886


##########
flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/org/apache/flink/cdc/connectors/mysql/source/utils/StatementUtils.java:
##########
@@ -56,6 +61,31 @@ public static Object[] queryMinMax(JdbcConnection jdbc, 
TableId tableId, String
                 });
     }
 
+    public static Long queryRowCnt(
+            JdbcConnection jdbc, TableId tableId, String columnName, @Nullable 
String filter)
+            throws SQLException {
+
+        if (filter == null) {
+            return queryApproximateRowCnt(jdbc, tableId);
+        }
+
+        final String cntQuery =
+                String.format(
+                        "SELECT COUNT(%s) FROM %s WHERE %s",
+                        quote(columnName), quote(tableId), filter);
+        return jdbc.queryAndMap(
+                cntQuery,
+                rs -> {
+                    if (!rs.next()) {
+                        // this should never happen
+                        throw new SQLException(
+                                String.format(
+                                        "No result returned after running 
query [%s]", cntQuery));
+                    }
+                    return rs.getLong(1);
+                });
+    }
+

Review Comment:
   Because the filter is applied during split planning, the distribution factor 
may fall outside the configured bounds(0.05 ~1,000), affecting snapshot 
performance. I’d appreciate your thoughts on this.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to