Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tXNkL-005zto-FF for pgsql-general@arkaria.postgresql.org; Mon, 13 Jan 2025 16:57:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tXNkI-00BVy5-FY for pgsql-general@arkaria.postgresql.org; Mon, 13 Jan 2025 16:56:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tXNkI-00BVxw-2c for pgsql-general@lists.postgresql.org; Mon, 13 Jan 2025 16:56:58 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tXNkG-000Cht-1R for pgsql-general@lists.postgresql.org; Mon, 13 Jan 2025 16:56:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version :References:Reply-To:Message-ID:Subject:Cc:To:Sender:From:Date:Content-ID: Content-Description; bh=FlnOXMr4fOcefHY3bt3cxa9VLRobf6Rwp9qtEXf1n1w=; b=cl1ZG odN2GYZr489RdqfdSI+yS5GuQZ9O+eiPaDsiuBYCydxw4cE3gbcs7l+Byf2EcMws/6KAp9USmNUf9 F9oTcWdQf5PmDv7kAsTu/pPmE9Os8T5Texgud1mb5LmH++yuFYdjEWY68xRjRv7cRxdAfe3gd44nR lAbyfsAF6xL8=; Received: from depesz by depesz.com with local (Exim 4.96) (envelope-from ) id 1tXNkF-00FtxM-1Y; Mon, 13 Jan 2025 17:56:55 +0100 Date: Mon, 13 Jan 2025 17:56:55 +0100 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: =?utf-8?B?RcWfcmVmIEhhbMSxY8Sxb8SfbHU=?= Cc: "pgsql-general@lists.postgresql.org" Subject: Re: About PostgreSQL Query Plan Message-ID: Reply-To: depesz@depesz.com References: <1348181736777057@mail.yandex.com> <260121736786553@mail.yandex.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <260121736786553@mail.yandex.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jan 13, 2025 at 07:48:09PM +0300, Eşref Halıcıoğlu wrote: > Hello, >   > Yes, you are right; this query is not a SELECT, it is an UPDATE query, there was a mistake in expressing it here. The columns I want > to update here only operate on data from the last 3 months time interval. >   > I am also sharing the EXPLAIN ANALYZE output of the relevant query below: >   > Update on "TestTable1" t1  (cost=0.13..159114.84 rows=0 width=0) (actual time=0.007..0.008 rows=0 loops=1) >   Update on "PartitionTable_2020_10" t1 … 61 lines removed … >   Update on "PartitionTable_2025_12" t1 >   Update on "DefaultPartitionTable" t1 >   ->  Nested Loop  (cost=0.13..159114.84 rows=1 width=53) (actual time=0.006..0.006 rows=0 loops=1) >         ->  Seq Scan on "TempTable1" tmp  (cost=0.00..19.20 rows=920 width=31) (actual time=0.006..0.006 rows=0 loops=1) >         ->  Append  (cost=0.13..172.29 rows=64 width=38) (never executed) >               Subplans Removed: 60 >               ->  Index Scan using partitiontable_2024_10_pkey on "PartitionTable_2024_10" t2  (cost=0.43..4.21 rows=1 width=38) (never executed) >                     Index Cond: (("Col1" = tmp."Col2") AND ("Col3" >= (CURRENT_DATE - '3 mons'::interval)) AND ("Col3" <= CURRENT_DATE)) >                     Filter: ((NOT "IsDeleted") AND ("Col4" = tmp."Col5")) >               ->  Index Scan using partitiontable_2024_11_pkey on "PartitionTable_2024_11" t3  (cost=0.43..4.23 rows=1 width=38) (never executed) >                     Index Cond: (("Col1" = tmp."Col2") AND ("Col3" >= (CURRENT_DATE - '3 mons'::interval)) AND ("Col3" <= CURRENT_DATE)) >                     Filter: ((NOT "IsDeleted") AND ("Col4" = tmp."Col5")) >               ->  Index Scan using partitiontable_2024_12_pkey on "PartitionTable_2024_12" t4  (cost=0.43..4.34 rows=1 width=38) (never executed) >                     Index Cond: (("Col1" = tmp."Col2") AND ("Col3" >= (CURRENT_DATE - '3 mons'::interval)) AND ("Col3" <= CURRENT_DATE)) >                     Filter: ((NOT "IsDeleted") AND ("Col4" = tmp."Col5")) >               ->  Index Scan using partitiontable_2025_01_pkey on "PartitionTable_2025_01" t5  (cost=0.43..3.72 rows=1 width=38) (never executed) >                     Index Cond: (("Col1" = tmp."Col2") AND ("Col3" >= (CURRENT_DATE - '3 mons'::interval)) AND ("Col3" <= CURRENT_DATE)) >                     Filter: ((NOT "IsDeleted") AND ("Col4" = tmp."Col5")) > Planning Time: 3.860 ms > Execution Time: 0.066 ms Well, it helped, and I missed some bits of information earlier. Generally it looks that it was trying to scan only 4 partitions, but they all got skipped. Best regards, depesz