Настройка запросов Postgres - PullRequest
       33

Настройка запросов Postgres

0 голосов
/ 22 октября 2018

У меня есть требование объединить две таблицы на основе условия отрицания, выполнение которого занимает много времени.

SELECT oola.ship_from_org_id ,
    oola.subinventory,
    oola.line_id ,
    crl.requirement_header_id,
    crl.inventory_item_id
    FROM racesbi_ods.ods_csp_requirement_lines crl
    LEFT JOIN  racesbi_ods.ods_csp_req_line_details crld
        ON crld.requirement_line_id = crl.requirement_line_id
    JOIN racesbi_ods.ods_oe_order_lines_all oola
        ON  crld.source_id               <> oola.line_id
        AND oola.header_id IN
            (SELECT header_id FROM racesbi_ods.ods_oe_order_lines_All
            WHERE line_id = crld.source_id
            )

Чтобы настроить это, я попытался использовать временные таблицы.но все же я сталкиваюсь с проблемой производительности.

create temporary table tst1 --ON commit drop    244067
as(select crl.requirement_header_id,
    crl.inventory_item_id,
    crld.requirement_line_id,
    crld.source_id FROM racesbi_ods.ods_csp_requirement_lines crl
    LEFT JOIN  racesbi_ods.ods_csp_req_line_details crld
        ON crld.requirement_line_id = crl.requirement_line_id
)  distributed randomly;
-- Query returned successfully: 244067 rows affected, 15264 ms execution time.

create temporary table tst2 --ON commit drop    2700951
as(
select ship_from_org_id,
    subinventory,
    line_id
    FROM racesbi_ods.ods_oe_order_lines_all
)  distributed randomly;


create temporary table tst3 --ON commit drop 
as(
select tst1.requirement_header_id,
    tst1.inventory_item_id,
    tst2.ship_from_org_id,
    tst2.subinventory,
    tst2.line_id
    FROM tst1 
    JOIN tst2 ON tst2.line_id != tst1.source_id
)  distributed randomly;

Пожалуйста, помогите, как обработать условие отрицания в JOINs

...