sybase中的查询优化

发布于 2024-11-25 07:23:42 字数 795 浏览 1 评论 0原文

我需要从 22 个客户数据库中检索客户 MSISDN(电话号码)。我为两种情况创建了一个视图:

  1. 首先我们需要检查哪个 MSISDN profile_id 16240 处于非活动状态。这可以通过在非活动数据不为空的数据库中查询来完成。

  2. 由于 GPRS 有两个配置文件 25054 和 16240,因此对于 MSISDN,25054(用于互联网目的)处于活动状态而 16240(用于 GPRS 未处于活动状态) 因此我们需要为此目的创建脚本。

我准备了一个查询:

CREATE VIEW SUBSCR_INFO_VIEW AS
SELECT subscr_no,account_no FROM CUSTOMER_PROFILE_DEF WHERE subscr_no NOT IN
(SELECT DISTINCT(subscr_no) FROM CUSTOMER_ID_EQUIP_MAP
WHERE inactive_date Is NOT NULL)
 AND (profile_id IN (16240) AND cutoff_end_dt IS NOT NULL) OR (profile_id IN (25054) AND profile_id NOT IN (16240) AND cutoff_end_dt IS NULL)

SET ROWCOUNT 100 

SELECT DISTINCT(subscr_no) FROM SUBSCR_INFO_VIEW 

这将在所有 22 个客户服务器中被命中,并且从单个客户获取数据需要 2.5 分钟。我想减少那个时间。请让我知道您的反馈。

I need to retrieve customer MSISDN (phone no) from 22 customer databases. I have created a view for two cases:

  1. First we need to check for which MSISDNs profile_id 16240 is inactive.This can be done by querying in database whose inactive data is not null.

  2. Since for GPRS we have two profile 25054 and 16240,it happens e for MSISDNs 25054 (for internet purpose) is active and 16240 (for GPRS is not active)
    so we need to create script for that purpose .

I have prepared a query:

CREATE VIEW SUBSCR_INFO_VIEW AS
SELECT subscr_no,account_no FROM CUSTOMER_PROFILE_DEF WHERE subscr_no NOT IN
(SELECT DISTINCT(subscr_no) FROM CUSTOMER_ID_EQUIP_MAP
WHERE inactive_date Is NOT NULL)
 AND (profile_id IN (16240) AND cutoff_end_dt IS NOT NULL) OR (profile_id IN (25054) AND profile_id NOT IN (16240) AND cutoff_end_dt IS NULL)

SET ROWCOUNT 100 

SELECT DISTINCT(subscr_no) FROM SUBSCR_INFO_VIEW 

This will be hit in all 22 customer servers and to take data from a single customer it's taking 2.5 min. I want to reduce that time. Please let me know your feedback.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪若未夕 2024-12-02 07:23:42

如果不了解更多关于数据库结构的信息,这个问题有点难以回答。 CUSTOMER_PROFILE_DEF 和 CUSTOMER_ID_EQUIP_MAP 表中有多少条记录,有哪些键?另外,您的 SQL 在原始帖子中很难理解,我在下面重新格式化了它并做了一些小更改:

    CREATE VIEW 
        SUBSCR_INFO_VIEW 
    AS SELECT 
        subscr_no,
        account_no 
    FROM 
        CUSTOMER_PROFILE_DEF 
    WHERE 
        subscr_no 
    NOT IN (
            SELECT DISTINCT
                subscr_no
            FROM 
                CUSTOMER_ID_EQUIP_MAP 
            WHERE
                inactive_date Is NOT NULL
        ) 
    AND ((profile_id = 16240 AND cutoff_end_dt IS NOT NULL) 
    OR   (profile_id = 25054 AND cutoff_end_dt IS NULL))

    SET ROWCOUNT 100 -- This is just for testing?

    SELECT DISTINCT(subscr_no) FROM SUBSCR_INFO_VIEW

sql 基本相同,但我将 (12345) 语句中的 profile_id 更改为profile_id = 12345 因为值列表中只有一个值。

This is a little difficult to answer without knowing more about the structure of the database. How many records do you have in the CUSTOMER_PROFILE_DEF and CUSTOMER_ID_EQUIP_MAP tables, and what keys do you have? Also, your SQL is very difficult to understand in the original post, I have reformatted it below and made some small changes:

    CREATE VIEW 
        SUBSCR_INFO_VIEW 
    AS SELECT 
        subscr_no,
        account_no 
    FROM 
        CUSTOMER_PROFILE_DEF 
    WHERE 
        subscr_no 
    NOT IN (
            SELECT DISTINCT
                subscr_no
            FROM 
                CUSTOMER_ID_EQUIP_MAP 
            WHERE
                inactive_date Is NOT NULL
        ) 
    AND ((profile_id = 16240 AND cutoff_end_dt IS NOT NULL) 
    OR   (profile_id = 25054 AND cutoff_end_dt IS NULL))

    SET ROWCOUNT 100 -- This is just for testing?

    SELECT DISTINCT(subscr_no) FROM SUBSCR_INFO_VIEW

The sql is largely the same, but I changed your profile_id in (12345) statements to profile_id = 12345 as there was only one value in the list of values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文