postgresql慢查询(dblink和内连接)

时间:2012-12-21 16:01:39

标签: database performance postgresql inner-join dblink

我有这个包含dblink的查询,因为我需要连接到另一个数据库,它看起来很慢(仅124条记录50.343秒)。有没有办法让它快?以下是代码:

select * 
from 
    customer  
    INNER JOIN  
    dblink('host=192.168.3.9 dbname=db2 user=postgres password=postgres', '
        SELECT
            status,
            last_churn_1,
            attempts,
            last_dialed,
            lead_id,
            date_added
        FROM campaign_customer
        ') AS table2 (
            status char(50),
            last_churn_1 char(50),
            attempts int,
            last_dialed char(250),
            lead_id char(8),
            date_added char(50)
        ) ON customer.phone1 = table2.last_dialed
where customer.leadid = '3434' and table2.lead_id='3434'

1 个答案:

答案 0 :(得分:4)

丹尼尔建议:

select * 
from 
    customer  
    INNER JOIN  
    dblink('host=192.168.3.9 dbname=db2 user=postgres password=postgres', $$
        SELECT
            status,
            last_churn_1,
            attempts,
            last_dialed,
            lead_id,
            date_added
        FROM campaign_customer
        where lead_id='3434'
        $$) AS table2 (
            status char(50),
            last_churn_1 char(50),
            attempts int,
            last_dialed char(250),
            lead_id char(8),
            date_added char(50)
        ) ON customer.phone1 = table2.last_dialed
where customer.leadid = '3434'