Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lA6nE-0000ae-62 for pgsql-general@arkaria.postgresql.org; Thu, 11 Feb 2021 07:53:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lA6nD-0001D4-11 for pgsql-general@arkaria.postgresql.org; Thu, 11 Feb 2021 07:53:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lA6nC-0001Cx-Mr for pgsql-general@lists.postgresql.org; Thu, 11 Feb 2021 07:53:38 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lA6n8-0007zo-AE for pgsql-general@postgresql.org; Thu, 11 Feb 2021 07:53:38 +0000 Received: by mail-ej1-x635.google.com with SMTP id w1so8537605ejf.11 for ; Wed, 10 Feb 2021 23:53:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=QAHFiUsTeb1qpiwBSwtZIdcNedupWA775wAqoz3Unao=; b=DHCGUwPVWUrZPUurmdC03S+ExmCp0tM+L9qOMTk64IcORRan+/C2oNo7othsJ5ruo4 8bDDnCBdAoKvTXi6ydW78C2Q/YWeSaRb4kZLMgPPTWu8Ms4Cp9xtjgnSxH152JS/3lM3 wS1un+z/icoYtKxZE6llQoI9Oai8EvJqIZLEGJEflA1mimXI+EC2m7BPnWhimopvMibx 1CODKjbGd2og2/bZ6S/Eet5QSCV2g6+Zc+9EBLNGx62n6L+U7Szdu0doMv3ewGvdlv+u /IzRuKCqxvJng5ufktUYg0MtquwDQJlYwJTsOnixkDcP8p8gzkpfM3dxBPiHGPOgsl2P 76uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=QAHFiUsTeb1qpiwBSwtZIdcNedupWA775wAqoz3Unao=; b=KhSSUeW8Hey/XJuPDKKDPmGfJ8eeSoubfLMBBNGBb/VDrzFM681ypkILdHlXGrspYf /IWfLMw80z4UgdlGGUXHlQ6XFnCGO+nnhEPOVolAi4BqS66HM9XHgYzV3AkHPi18LVC1 EU1VB4q8lBTmzKVujN5IE8+Bp7pvPb0XbiPkJrqRwWaiQ8Domqbtu5kATjrrKMuJ4/KJ xJ7uaU6FgrA0ECbWvPp7Sza5UIB7sQ+L2O5qJrCVmCPac2NkQHAvFVA+tmKSLePgUoDJ SL1AtpamWrTgZzF11SGqWGq2GoAivwSI78n7w/pbsdgT9yEEmoWi2nvgkyESnQc9+ZvW 5KJQ== X-Gm-Message-State: AOAM532KNmLJBnBO7wUPbB3Rp9jEluRt6tWevIMmtmI6S8yUpPi3uwor pxBhzKDd2HSPyDEl1YjOaXR3sA== X-Google-Smtp-Source: ABdhPJzmQcPUe2CTJHYad1YpwIBtcwzYOqlMyz4CRkvVobG9Z0vnviw6HYsaQY/HKHo3XW8Y+kTYiw== X-Received: by 2002:a17:907:2805:: with SMTP id eb5mr7029764ejc.277.1613030012063; Wed, 10 Feb 2021 23:53:32 -0800 (PST) Received: from localhost.localdomain (217-149-170-189.nat.highway.telekom.at. [217.149.170.189]) by smtp.gmail.com with ESMTPSA id q14sm3095509edw.52.2021.02.10.23.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 23:53:31 -0800 (PST) Message-ID: <5e002236680a7bf095abf4508536c4b16bb77175.camel@cybertec.at> Subject: Re: Unable to execute Query in parallel for partitioned table From: Laurenz Albe To: Brajendra Pratap , pgsql-general@postgresql.org Date: Thu, 11 Feb 2021 08:53:31 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, 2021-02-11 at 05:09 +0530, Brajendra Pratap wrote: > I am unable to execute the below in parallel plz suggest how can I achieve parallelism here. > > select count(*) over () VIEWALLROWCOUNT,abc.*,ROW_NUMBER() OVER (order by trn_transaction_date desc ) AS RowNumber from ( > select * from transactions where trn_store_date_id=20201202) abc; > > Query plan is as mentioned below :- > > explain analyze select count(*) over () VIEWALLROWCOUNT,abc.*,ROW_NUMBER() OVER (order by trn_transaction_date desc ) AS RowNumber from ( > select * from transactions where trn_store_date_id=20201218) abc; > LOG: duration: 25820.176 ms statement: explain analyze select count(*) over () VIEWALLROWCOUNT,abc.*,ROW_NUMBER() OVER (order by trn_transaction_date desc ) AS RowNumber from ( > select * from transactions where trn_store_date_id=20201218) abc; > QUERY PLAN > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > WindowAgg (cost=4474843.51..4498066.81 rows=774110 width=21297) (actual time=21455.495..25241.738 rows=795190 loops=1) > -> WindowAgg (cost=4474843.51..4488390.44 rows=774110 width=21289) (actual time=10588.494..15311.865 rows=795190 loops=1) > -> Sort (cost=4474843.51..4476778.79 rows=774110 width=21281) (actual time=10588.422..11771.300 rows=795190 loops=1) > Sort Key: transactions.trn_transaction_date DESC > Sort Method: external merge Disk: 1496856kB > -> Result (cost=0.00..270640.32 rows=774110 width=21281) (actual time=0.117..4504.159 rows=795190 loops=1) > -> Append (cost=0.00..262899.22 rows=774110 width=21281) (actual time=0.094..1449.532 rows=795190 loops=1) > -> Seq Scan on transactions (cost=0.00..0.00 rows=1 width=47554) (actual time=0.019..0.019 rows=0 loops=1) > Filter: (trn_store_date_id = 20201218) > -> Index Scan using idx_202012_trn_store_date_id on transactions_202012 (cost=0.56..259028.67 rows=774109 width=21281) (actual time=0.074..1357.764 rows=795190 loops=1) > Index Cond: (trn_store_date_id = 20201218) > Planning Time: 116.472 ms > Execution Time: 25676.098 ms > > Note :- We had tried different options like max_worker_processes, max_parallel_workers, max_parallel_workers_per_gather,max_parallel_maintenance_worker to execute it in parallel but no luck. I don't think parallelization will help you here. Your problem is probably the "abc.*" in the SELECT list. There must be really large data in this table, so it takes a long time to fetch and sort the rows. Try selecting only the columns you need. Alternatively, add a LIMIT clause. Do you really need all 800000 rows? Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com