使用Sybase中的conditional where子句表现不佳

时间:2012-02-08 14:01:19

标签: tsql sybase

我有以下SQL我试图在Sybase中执行。在SQL Server中,这些类型的查询是标准的,但性能使这在Sybase中无法使用。

DECLARE
    @pMEME_FIRST_NAME char(100),
    @pMEME_LAST_NAME char(100)

SET @pMEME_FIRST_NAME = 'Lisa'
SET @pMEME_LAST_NAME = 'Spivey'

    SELECT TOP 1 CMC_MEME_MEMBER.MEME_FIRST_NAME,
        CMC_MEME_MEMBER.MEME_LAST_NAME,
        CMC_MEME_MEMBER.MEME_SEX,
        CMC_MEME_MEMBER.MEME_SFX,
        CMC_SBSB_SUBSC.SBSB_ID, 
        CMC_MEME_MEMBER.MEME_REL,
        CMC_SBAD_ADDR.SBAD_ADDR1,
        CMC_SBAD_ADDR.SBAD_ADDR2,
        CMC_SBAD_ADDR.SBAD_CITY,
        CMC_SBAD_ADDR.SBAD_STATE,
        CMC_SBAD_ADDR.SBAD_ZIP,
        CMC_GRGR_GROUP.GRGR_ID,
        CMC_GRGR_GROUP.GRGR_NAME,
        CMC_MEME_MEMBER.MEME_SSN,   
        CMC_MEME_MEMBER.MEME_BIRTH_DT,
        CMC_MEME_MEMBER.MEME_CK,
        CMC_MEME_MEMBER.SBSB_CK,
        CMC_MEME_MEMBER.GRGR_CK,
        CMC_MEME_MEMBER.MEME_FAM_LINK_ID
    FROM CMC_MEME_MEMBER CMC_MEME_MEMBER
        INNER JOIN CMC_SBSB_SUBSC CMC_SBSB_SUBSC
        ON CMC_MEME_MEMBER.SBSB_CK = CMC_SBSB_SUBSC.SBSB_CK
        AND CMC_MEME_MEMBER.GRGR_CK = CMC_SBSB_SUBSC.GRGR_CK

        INNER JOIN CMC_SBAD_ADDR CMC_SBAD_ADDR
        ON CMC_MEME_MEMBER.SBSB_CK = CMC_SBAD_ADDR.SBSB_CK
        AND CMC_MEME_MEMBER.GRGR_CK = CMC_SBAD_ADDR.GRGR_CK

        INNER JOIN CMC_GRGR_GROUP CMC_GRGR_GROUP
        ON CMC_MEME_MEMBER.GRGR_CK = CMC_GRGR_GROUP.GRGR_CK
    WHERE (@pMEME_FIRST_NAME IS NULL OR (CMC_MEME_MEMBER.MEME_FIRST_NAME = @pMEME_FIRST_NAME))
    AND (@pMEME_LAST_NAME IS NULL OR (CMC_MEME_MEMBER.MEME_LAST_NAME = @pMEME_LAST_NAME))
--    WHERE ((CMC_MEME_MEMBER.MEME_FIRST_NAME = @pMEME_FIRST_NAME))
--    AND ((CMC_MEME_MEMBER.MEME_LAST_NAME = @pMEME_LAST_NAME))

如果我取出其中一个IS NULL检查,则查询将在几毫秒内运行。

有什么想法吗?

0 个答案:

没有答案