Improve execution time of a query that populates data

good morning

I need help related to a process whose popular purpose is data from one table to another, at the moment I’m using spring boot with native query, but it’s taking more than 30 minutes, java method:

    @Modifying
@Query(nativeQuery = true, value = "WITH transformed_source AS ( "
        + "    SELECT "
        + "        lcp.client, "
        + "        lcp.product_id, "
        + "        lcp.store_id, "
        + "        CASE "
        + "            WHEN lcp."source" = :client THEN 'PROPRIA' "
        + "            WHEN lcp."source" = 'INFOPRICE - INFOPANEL' THEN 'INFOPANEL' "
        + "            WHEN lcp."source" = 'INFOPRICE - MPDV' THEN 'MPDV' "
        + "            ELSE lcp."source" "
        + "            END AS source "
        + "    FROM "
        + "        last_competitor_prices lcp "
        + "    WHERE "
        + "            lcp.client = :client "
        + "      AND lcp."source" IS NOT NULL "
        + "      AND lcp.date BETWEEN :startingDate AND :endingDate "
        + "), "
        + "     agg_source AS ( "
        + "         SELECT "
        + "             product_id, "
        + "             store_id, "
        + "             string_agg(DISTINCT "source", '-' ORDER BY "source") AS "source" "
        + "         FROM "
        + "             transformed_source "
        + "         GROUP BY "
        + "             product_id, "
        + "             store_id "
        + "     ), "
        + "     agg_competitor_prices AS ( "
        + "         SELECT "
        + "             lcp.store_id, "
        + "             lcp.product_id, "
        + "             CAST(AVG(lcp.price_retail) OVER (PARTITION BY lcp.store_id, lcp.product_id) AS DECIMAL(17, 2)) AS avg_competitor_price_product, "
        + "             CAST(MIN(lcp.price_retail) OVER (PARTITION BY lcp.store_id, lcp.product_id) AS DECIMAL(17, 2)) AS min_competitor_price_product, "
        + "             CAST(MAX(lcp.price_retail) OVER (PARTITION BY lcp.store_id, lcp.product_id) AS DECIMAL(17, 2)) AS max_competitor_price_product, "
        + "             CAST(AVG(lcp.price_retail) OVER (PARTITION BY lcp.store_id, lcp.product_family_id, lcp.competitor_store_id) AS DECIMAL(17, 2)) AS avg_competitor_price_family, "
        + "             CAST(MIN(lcp.price_retail) OVER (PARTITION BY lcp.store_id, lcp.product_family_id, lcp.competitor_store_id) AS DECIMAL(17, 2)) AS min_competitor_price_family, "
        + "             CAST(MAX(lcp.price_retail) OVER (PARTITION BY lcp.store_id, lcp.product_family_id, lcp.competitor_store_id) AS DECIMAL(17, 2)) AS max_competitor_price_family, "
        + "             MAX(lcp.date) OVER (PARTITION BY lcp.client, lcp.store_id, lcp.product_id) AS max_date_competitor_price_product, "
        + "             ags."source" "
        + "         FROM "
        + "             last_competitor_prices lcp "
        + "                 LEFT JOIN "
        + "             agg_source ags ON lcp.product_id = ags.product_id AND lcp.store_id = ags.store_id "
        + "         WHERE "
        + "                 lcp.client = :client "
        + "           AND lcp.date BETWEEN :startingDate AND :endingDate "
        + "     ), "
        + "     final_competitor_prices AS ( "
        + "         SELECT "
        + "             store_id, "
        + "             product_id, "
        + "             avg_competitor_price_product, "
        + "             min_competitor_price_product, "
        + "             max_competitor_price_product, "
        + "             max_date_competitor_price_product, "
        + "             source, "
        + "             AVG(avg_competitor_price_family) AS avg_competitor_price_family, "
        + "             AVG(min_competitor_price_family) AS min_competitor_price_family, "
        + "             AVG(max_competitor_price_family) AS max_competitor_price_family "
        + "         FROM "
        + "             agg_competitor_prices "
        + "         GROUP BY "
        + "             store_id, "
        + "             product_id, "
        + "             avg_competitor_price_product, "
        + "             min_competitor_price_product, "
        + "             max_competitor_price_product, "
        + "             max_date_competitor_price_product, "
        + "             source "
        + "     ) "
        + "UPDATE "
        + "    products_to_be_priced ptb "
        + "SET "
        + "    acp_avg_competitor_price_product = fcp.avg_competitor_price_product, "
        + "    acp_min_competitor_price_product = fcp.min_competitor_price_product, "
        + "    acp_max_competitor_price_product = fcp.max_competitor_price_product, "
        + "    acp_avg_competitor_price_family = fcp.avg_competitor_price_family, "
        + "    acp_min_competitor_price_family = fcp.min_competitor_price_family, "
        + "    acp_max_competitor_price_family = fcp.max_competitor_price_family, "
        + "    acp_max_date_competitor_price_product = fcp.max_date_competitor_price_product, "
        + "    acp_days_competitor_price = :competitorDays, "
        + "    source = fcp.source "
        + "FROM "
        + "    final_competitor_prices fcp "
        + "WHERE "
        + "        ptb.client = :client "
        + "  AND ptb.product_id = fcp.product_id "
        + "  AND ptb.store_id = fcp.store_id")
void populateProductToBePricedByLastCompetitorPrice(@Param("client") String client, @Param("startingDate") LocalDate startingDate,
                                                    @Param("endingDate") LocalDate endingDate, @Param("competitorDays") int competitorDays);

eu ja criei alguns indices na tabelas last_competitor_prices:

create index if not exists idx_lcp_date_client_product_store
on public.last_competitor_prices (date, client, product_id, store_id);

create index if not exists last_competitor_prices_client_store_id_product_id_idx
on public.last_competitor_prices (client, store_id, product_id);

create index if not exists idx_lcp_client_store_product_family_date
on public.last_competitor_prices (client, store_id, product_family_id, date);

create index if not exists idx_lcp_client_date
on public.last_competitor_prices (client, date);

create index if not exists idx_lcp_product_store
on public.last_competitor_prices (product_id, store_id);

create index if not exists idx_lcp_product_family
on public.last_competitor_prices (product_family_id);

create index if not exists idx_lcp_competitor_store
on public.last_competitor_prices (competitor_store_id);

My question is, is there any way to improve either the query or the way it was done, to make this processing faster?
It could be any change, even perhaps migrating to spring batch, I would like some guidance if possible.
Thanks

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật