3

当我在外部表上完成流连接与将连续视图加入到外部表时,我得到不同的结果。我期望相同的两个查询似乎不同。我的本地管道实例和 fdw 中的表之间的延迟对我的连续流连接有影响吗?我正在尝试根据外部表格的 id 聚合 rx_bytes 和 tx_bytes。

我正在使用最新的 mysql_fdw

https://github.com/EnterpriseDB/mysql_fdw

  1. 创建外部表

    CREATE EXTENSION mysql_fdw;
    
    CREATE SERVER local_mysql
        FOREIGN DATA WRAPPER mysql_fdw
        OPTIONS (host 'localhost', port '3306', secure_auth 'true');
    
    CREATE USER MAPPING FOR pipeline
        SERVER local_mysql 
        OPTIONS(username 'username', password 'password');
    
    CREATE FOREIGN TABLE "foo_instance" (
         "id" bigint,
         "foo_id" bigint,
    )
    SERVERlocal_mysql
    OPTIONS(dbname 'schema', table_name 'foo_instance');
    
  2. 插入 10 次后,我希望这两个查询产生相同的结果:

一个)

    CREATE CONTINUOUS VIEW total_bytes
    AS SELECT date_trunc('minute', time_stamp::timestamp) AS minute,
        id::integer,
        sum(tx_bytes::bigint) AS tx_bytes,
        sum(rx_bytes::bigint) AS rx_bytes
     FROM byte_count_stream GROUP BY minute, id;

    SELECT minute, sum(tx_bytes) AS tx_bytes, sum(rx_bytes) AS rx_bytes, foo_id 
    FROM total_bytes JOIN foo_instance 
         ON total_bytes.id=foo_instance.id GROUP BY minute, foo_instance.foo_id;

           minute        | tx_bytes | rx_bytes | foo_id 
    ---------------------+----------+----------+---------
     2016-02-22 09:04:00 |      450 |      513 |    7939
     2016-02-22 09:04:00 |     2762 |     2210 |    7940
     2016-02-22 09:04:00 |      143 |      332 |    7941
     2016-02-22 09:04:00 |      371 |     1042 |    7942
     2016-02-22 09:04:00 |      865 |      987 |    7943
     (5 rows)

b)

    CREATE CONTINUOUS VIEW joined_foo_total_bytes
        AS SELECT date_trunc('minute', byte_count_stream.time_stamp::timestamp) AS minute,
            sum(byte_count_stream.tx_bytes::bigint) AS tx_bytes,
            sum(byte_count_stream.rx_bytes::bigint) AS rx_bytes,
            foo_instance.foo_id
        FROM byte_count_stream JOIN foo_instance ON byte_count_stream.id::integer = foo_instance.id
        GROUP BY minute, foo_instance.foo_id;



    pipeline=# select * from joined_user_total_bytes;       
           minute        | tx_bytes | rx_bytes | foo_id 
    ---------------------+----------+----------+---------
     2016-02-22 09:04:00 |      371 |     1042 |    7942
     2016-02-22 09:04:00 |      143 |      332 |    7941
     2016-02-22 09:04:00 |      865 |      987 |    7943
     2016-02-22 09:04:00 |     2762 |     2210 |    7940
     (4 rows)

显然结果是不一样的。我可以从连续视图到外部表进行连接,但更喜欢使用流连接。

4

0 回答 0