public static long queryApproximateRowCnt(JdbcConnection jdbc, TableId tableId)
            throws SQLException {
        // The statement used to get approximate row count which is less
        // accurate than COUNT(*), but is more efficient for large table.
        // https://stackoverflow.com/questions/7943233/fast-way-to-discover-the-row-count-of-a-table-in-postgresql
        // NOTE: it requires ANALYZE or VACUUM to be run first in PostgreSQL.
        final String query =
                String.format(
                        "SELECT reltuples::bigint FROM pg_class WHERE oid = to_regclass('%s')",
                        tableId.toString());

        return jdbc.queryAndMap(
                query,
                rs -> {
                    if (!rs.next()) {
                        throw new SQLException(
                                String.format(
                                        "No result returned after running query [%s]", query));
                    }
                    LOG.info("queryApproximateRowCnt: {} => {}", query, rs.getLong(1));
                    return rs.getLong(1);
                });
    }
Query-related Utilities for Postgres CDC source.
inlong-sort/sort-flink/sort-flink-v1.13/sort-connectors/postgres-cdc/src/main/java/org/apache/inlong/sort/cdc/postgres/source/utils/PgQueryUtils.java