1

这是我的查询,任何人都可以看到任何方法来提高效率,以免超时?我正在使用 Exacttarget (Salesforce Marketing Cloud)。它有 30 分钟的超时限制。我试过移动东西,但似乎总是出错。我是 SQL 的初学者,但上周我一直很努力。我的查询如下。谢谢!

SELECT DISTINCT c.Email,  c.FName
FROM ENT.Contacts c WITH(NOLOCK)
INNER JOIN ENT.RegistrationData r WITH(NOLOCK)
ON c.Email  =  r.RegistrationContactEmail
LEFT Join ENT._Subscribers s  WITH(NOLOCK)
ON c.Email =  s.SubscriberKey
AND s.status NOT IN ('unsubscribed','held')

WHERE

(
    (
        (
            (
                r.RegistrationEmailOptStatus  =  '1' AND
                r.RegistrationEventType  =  'Wedding' AND
                r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
                r.RegistrationCountry IN ('USA') AND
                r.RegistrationEventDate < '2014-05-31'
            )

            OR

            (
                r.RegistrationEmailOptStatus  =  '1' AND
                r.RegistrationEventType  =  'Prom' AND
                r.RegistrationEventRole ='Prom' AND
                r.RegistrationCountry IN ('USA') AND
                r.RegistrationEventDate BETWEEN '2014-01-01' AND '2015-12-31'
            )
        )

        AND

        (
            (
                c.Email IN
                (
                    SELECT DISTINCT 
                        s.SubscriberKey AS Email
                    FROM 
                        _Open s
                    WHERE
                        datediff(mm,s.EventDate, getdate()) <= 3
                )
            )
            OR
            (
                c.Email IN
                (
                    SELECT DISTINCT 
                        s.SubscriberKey AS Email
                    FROM 
                        _Click s
                    WHERE
                        datediff(mm,s.EventDate, getdate()) <= 3
                )
            )
        )

    )

    OR

    (
        r.RegistrationEmailOptStatus  =  '1' AND
        r.RegistrationEventType  =  'Wedding' AND
        r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
        r.RegistrationCountry IN ('USA') AND
        r.RegistrationEventDate BETWEEN '2015-05-01' AND '2015-05-31'
    )
)
4

2 回答 2

1

我同意 Karl 的观点,即您的主要性能影响是在引用_Open_Click系统数据视图的子查询中。但是,根据我使用 ExactTarget (Salesforce Marketing Cloud) 的经验,您只能运行“SELECT”语句,并且无法以这种方式声明变量。

我建议在数据视图上运行单独的查询,_Open然后_Click在查询中引用生成的数据扩展名。这可能需要更多步骤。但是,您会发现整体处理时间更少。

对于第一个查询,我将为过去 3 个月内打开或点击过的每个人创建一个数据扩展。然后在第二个查询中,我将使用“IN”语句引用生成的数据扩展名。这将消除查询中的“OR”条件之一,这可能很昂贵。RegistrationData如果查询仍然执行不佳,我建议以一种避免“OR”条件的方式重写数据扩展上的条件逻辑。

查询1:

SELECT DISTINCT s.SubscriberKey AS Email
FROM  _Open s WITH(NOLOCK)
WHERE datediff(mm,s.EventDate, getdate()) <= 3

union all

SELECT DISTINCT s.SubscriberKey AS Email
FROM _Click s WITH(NOLOCK)
WHERE datediff(mm,s.EventDate, getdate()) <= 3

查询2:

SELECT DISTINCT c.Email,  c.FName
FROM ENT.Contacts c WITH(NOLOCK)
INNER JOIN ENT.RegistrationData r WITH(NOLOCK)
ON c.Email  =  r.RegistrationContactEmail
LEFT Join ENT._Subscribers s  WITH(NOLOCK)
ON c.Email =  s.SubscriberKey
AND s.status NOT IN ('unsubscribed','held')
WHERE  
(
    (
        (
            (
                r.RegistrationEmailOptStatus  =  '1' AND
                r.RegistrationEventType  =  'Wedding' AND
                r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
                r.RegistrationCountry IN ('USA') AND
                r.RegistrationEventDate < '2014-05-31'
            )

            OR

            (
                r.RegistrationEmailOptStatus  =  '1' AND
                r.RegistrationEventType  =  'Prom' AND
                r.RegistrationEventRole ='Prom' AND
                r.RegistrationCountry IN ('USA') AND
                r.RegistrationEventDate BETWEEN '2014-01-01' AND '2015-12-31'
            )
        )

        AND

        (
            c.Email  in (
                select s.SubscriberKey
                from OpenOrClickDE s
                where s.SubscriberKey = c.Email            
            )
        )

    )

    OR

    (
        r.RegistrationEmailOptStatus  =  '1' AND
        r.RegistrationEventType  =  'Wedding' AND
        r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
        r.RegistrationCountry IN ('USA') AND
        r.RegistrationEventDate BETWEEN '2015-05-01' AND '2015-05-31'
    )
)
于 2015-06-12T19:35:59.600 回答
0

我会拍的。可能有一些小东西,但在我看来,唯一能让查询旋转很长时间的事情是

            c.Email IN
            (
                SELECT DISTINCT 
                    s.SubscriberKey AS Email
                FROM 
                    _Open s
                WHERE
                    datediff(mm,s.EventDate, getdate()) <= 3
            )
        OR
            c.Email IN
            (
                SELECT DISTINCT 
                    s.SubscriberKey AS Email
                FROM 
                    _Click s
                WHERE
                    datediff(mm,s.EventDate, getdate()) <= 3
            )

里面有两个问题。首先,您要进行数十亿次的日期数学运算,其次在这里使用 IN (SELECT ...) 几乎可以肯定是低效的。

要解决第一个问题,请计算一个测试日期并使用它。对于第二个更喜欢检查 EXISTS。

DECLARE @testDate DATE = DATEADD(mm,3,GETDATE())

...

        EXISTS(SELECT 1 FROM _Open s WHERE s.EventDate>@testDate AND c.Email = s.SubscriberKey)
     OR EXISTS(SELECT 1 FROM _Click s WHERE s.EventDate>@testDate AND c.Email = s.SubscriberKey)   

您也可以展开 EXISTS 并使用 _Open 和 _Click 的连接,但这感觉更复杂。

试一试,让我们知道它是否有帮助。

于 2015-06-12T01:42:26.967 回答