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.96) (envelope-from ) id 1vrj5g-002mjP-1Y for pgsql-general@arkaria.postgresql.org; Sun, 15 Feb 2026 20:51:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vrj5f-002D70-0q for pgsql-general@arkaria.postgresql.org; Sun, 15 Feb 2026 20:51:39 +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.96) (envelope-from ) id 1vrj5e-002D6r-1R for pgsql-general@lists.postgresql.org; Sun, 15 Feb 2026 20:51:38 +0000 Received: from fhigh-b7-smtp.messagingengine.com ([202.12.124.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vrj5b-00000000qOw-1qeo for pgsql-general@lists.postgresql.org; Sun, 15 Feb 2026 20:51:38 +0000 Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.stl.internal (Postfix) with ESMTP id 9D55F7A0066; Sun, 15 Feb 2026 15:51:32 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Sun, 15 Feb 2026 15:51:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1771188692; x=1771275092; bh=wsdMgmBLX7ejh1N8txQbwrMMZug3ExlR+03/UFBEyy4=; b= SNg6gEVQS3oDNxoJwTQlwMMCkm+N3QFw+V1Z4mLOOD9GzIJdqvBJB8fFxNwrSJfW 4fUu590SbmzALBZGKWa2d3r+fu3163WWQo/i8LCqRLj5wM7dh3uIsb4fHr1Bmq+C n1zGbY6/AroFGwwEWzP4msp11VLtFt765AGMo+u6h/f63a/6i2+DEhf6pRqAvTJ6 r+s3LOI+BJlTIkVCrhV3AjnUpJ+MJB6TPKTjIFCksWcoHimXeBBhLiUwHNJSIR05 T3YlDJIqGPSrgcNzG0FD0wKRl40nggx+Hh8S+BCcd4EdLKdiWUc9yE/aKBnMF+M8 b3i2ZWokNObQMq1kNcdXeQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1771188692; x=1771275092; bh=w sdMgmBLX7ejh1N8txQbwrMMZug3ExlR+03/UFBEyy4=; b=GLXsvo2QjsP9vw2BD KbbapGaQxhXKxmAExNvohm7GGkMr5tZyo7urdPuRKTlUUA+SzK78LH2+r3EvwHLX BAoWk+BIDmszBPe9t3T6/D5edeAEeo/hOemjgPzSu88Akt2D6TylGp1atXNLYs8g TbFY09MhE87sOsHPPEtAAkit7UAAS103GxIqwu+wqJ2P1Dz+/EqeYjRVCYPHPbzN F45So4j15fED07ofzkXnJuA2mZ7SvsOwdCy+NLkBVpitjVl7w1WAhqJgJVmWjnj/ X/xOyir5e8wZREobMoYCAaXbfxUtgAsX5M6+VcWSqHotYLNeTg3gb0sdsxLNDbr9 HG1Yg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvudehtddtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertd dtvdejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepveejueelvdehhf fggfeifefgtefgledttedvheffhfdvffevjeefleeiheeuhefhnecuffhomhgrihhnpehp ohhsthhgrhgvshhqlhdrohhrghdpghhithhhuhgsrdgtohhmnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhes rghklhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouh htpdhrtghpthhtoheplhgvrghrnhgvrhgurghtrggsrghsvgelleesghhmrghilhdrtgho mhdprhgtphhtthhopehpghhsqhhlqdhgvghnvghrrghlsehlihhsthhsrdhpohhsthhgrh gvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 15 Feb 2026 15:51:31 -0500 (EST) Message-ID: Date: Sun, 15 Feb 2026 12:51:31 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Question on execution plan and suitable index To: yudhi s , pgsql-general References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/15/26 11:04, yudhi s wrote: > Hi, > It's postgres version 17. We are having a critical UI query which runs > for ~7 seconds+. The requirement is to bring down the response time > within ~1 sec. Now in this plan , If i read this correctly, the below > section is consuming a significant amount of resources and should be > addressed. i.e. "Full scan of table "orders" and Nested loop with > event_audit_log table". For a start: 1) Supply the complete schema for the tables involved. 2) Also what is the minor version you are using e.g the x in 17.x? I also recommend reading: https://wiki.postgresql.org/wiki/Slow_Query_Questions > > *Below is the query and its complete plan:- * > https://gist.github.com/databasetech0073/ > f564ac23ee35d1f0413980fe4d00efa9 databasetech0073/f564ac23ee35d1f0413980fe4d00efa9> > > I am a bit new to the indexing strategy in postgres. My question is, > what suitable index should we create to cater these above? > > 1)For table event_audit_log:- Should we create composite Index on column > (request_id,created_at,event_comment_text) or should we create the > covering index i.e. just on two column (request_id,created_at) with > "include" clause for "event_comment_text". How and when the covering > index indexes should be used here in postgres. Want to understand from > experts? > 2)Similarly for table orders:- Should we create a covering index on > column (entity_id,due_date,order_type) with include clause > (firm_dspt_case_id). Or just a composite index > (entity_id,due_date,order_type). > 3)Whether the column used as range operator (here created_at or > due_date) should be used as leading column in the composite index or is > it fine to keep it as non leading? > > ->  Nested Loop  (cost=50.06..2791551.71 rows=3148 width=19) (actual > time=280.735..7065.313 rows=57943 loops=3) >  Buffers: shared hit=10014901 >  ->  Hash Join  (cost=49.49..1033247.35 rows=36729 width=8) (actual > time=196.407..3805.755 rows=278131 loops=3) > Hash Cond: ((ord.entity_id)::numeric = e.entity_id) > Buffers: shared hit=755352 > ->  Parallel Seq Scan on orders ord  (cost=0.00..1022872.54 rows=3672860 > width=16) (actual time=139.883..3152.627 rows=2944671 loops=3) >  Filter: ((due_date >= '2024-01-01'::date) AND (due_date <= > '2024-04-01'::date) AND (order_type = ANY ('{TYPE_A,TYPE_B}'::text[]))) >  Rows Removed by Filter: 6572678 >  Buffers: shared hit=755208 > > > Regards > Yudhi -- Adrian Klaver adrian.klaver@aklaver.com