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 1vrhRO-001K6T-11 for pgsql-general@arkaria.postgresql.org; Sun, 15 Feb 2026 19:05:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vrhQM-001yQ1-11 for pgsql-general@arkaria.postgresql.org; Sun, 15 Feb 2026 19:04:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vrhQL-001yPt-2l for pgsql-general@lists.postgresql.org; Sun, 15 Feb 2026 19:04:53 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vrhQJ-00000000m02-1ONE for pgsql-general@lists.postgresql.org; Sun, 15 Feb 2026 19:04:52 +0000 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-65a431e305eso4325532a12.0 for ; Sun, 15 Feb 2026 11:04:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771182285; cv=none; d=google.com; s=arc-20240605; b=MaoR/gzpze/kdTzzpm6CIFMnwsy4mp5Vde2CgB1y3eaQ518U/doKLqW+3pOL4Adb3K CC8ZDW3EGSwXLuk79jT3G1gaZS3Pxkm11tls078GMF+2PArhRGDZhyFvqSxwlPsCHdN0 9P0jpHpK2p65X8Y3z5nG5LPPkNrr4zqe1ItHzFTO+H3Isko3BCLJmPStHL5T5oPLnPrh sXl98X4HBzvMaOLGTdLEI8n5ZYw+WQHc9hJGWSIUz7FKCjXwIXCRrh5EzFnUEnu3FAw6 fWA6wKzwI2FphRUQnlbvd0YyQ2KoKNAQ+ZEedcofrwKgSU/Mpvmx6cz0l1g3AAj+oL4i 17MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=sJiGnSbEgGBgwnvjswICulN/yHJ1OpIhci0d5yBIgX8=; fh=U9Vkrj/8YXu+wNKP4ImG87p6jlJYRxuB/zicT9qNons=; b=giSdGF0ggHcR6gYMYkWr3KLVIFwfEwa46N1XQ0aUnEP6l2c89bipi8tIVsj0hCL2bH 6bmevr7miTa9h+vB9LmXXzisbXXDSDG1GSbbn4rXBY+FdUJarYhKRNRsbBq7+5LWHYRq eP/hJBprpvt7+DRU7FHc7wf3osQC+lhmTuArGq+Yg2TCTixkmuprMHvXjbeIDblSjzeR abMnb9nFQdK/u6fxe2wY0OLO9UDE+MpOM9YP5UDs5Ukqpm7wL5h0k3NpgtBwY9F9spyt hD7IBA5/PlkYTnQKMvUUq9swESZ/Yt+UElQjQwLjJ6DGyD8NH+WAyIYxj/1rcLBv5Srv ZSQQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771182285; x=1771787085; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=sJiGnSbEgGBgwnvjswICulN/yHJ1OpIhci0d5yBIgX8=; b=EjPACzQlkZJfTVjWga8NdXfjLJOgrWmoI+/zjgK/Jke8YCdpN+pereb6mq7U4F3fhp bypF3+nbSRZPrHAAdyN3XhZSI9XagDPy5Rlhww20n0H9b7gof2W4eWL3NO1RlEo0inHx R42I2wVyO7zyvmmpWWOnfn0inFCVbl+o6A1FtH8AgNB5Ep0c/2FCEovDT7Zfk8432rTw NWnnL+k9dBlPY4qKXRNXgRCp+3eeoTZWEm2aY5/7IxO8qjG3kHCetDj9UNVUgL5D/Bh/ msZQZE7rYVa3fiACrtG76qFe8/iey0Mh5H1qNTUTXIOzlPaODCmGcSpNUMdq5xtWHcXE kBGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771182285; x=1771787085; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sJiGnSbEgGBgwnvjswICulN/yHJ1OpIhci0d5yBIgX8=; b=vmjBLRfx8RhRkWcH1QajWB2s8GjtL99KZPnTspMUutgzV4IBC66B/iV7C6F0WCAtjB qTW/oMvbo9SPtHqmTeZO9Hjttqs240WMkH5EX7IgDokB6/OR+ApgM0iNX+twayMOapoD 8Z/IjL5LAGSYj1Phm+qf+XLE5EnfYFnqS3DMdRMT0JTDWuH2IKu5b0QFv+lgqI6JVlYS V01b37kBP0jDbczJxIEpnJI997GYtINb0bXNzR/xi//b7F4UlJz+wzDCOZ9xC4ApUxGw sOTkHPsDWb3D2bWqfcpcQWKuHiO8s/J+sIksShuaUr/0vYszsUBDUrkUaMcDebhRJTO1 hLeA== X-Gm-Message-State: AOJu0YxptoDYniv7kwcVuOW81Pk1abPUPmyVMVMVY5d4yGyrGHfYrutd /ky071uUuDb2yuMhcltATBijEt5lJwgmtv/biY9oZhiN0bHEFsgjYS4DkfYowH2rIu2OtrsGBDS fntw75FOdh3dH1nfRpc/RpCAAhyb+vIFf2kX1 X-Gm-Gg: AZuq6aIGWevO4y9P90zRkQybPRqxCwRzLTjJZI4YsAzSeEO7lo5e9pGxJ94NU0ptpCV vm+KsULZTQQ1sknRKXOtnTKeeKqwx0Uu1+UPcPXuYP1fdxZcjqHNDA97yDeYrYR4qVTqvPFF+pP V+YNXSJ9d0+i7TugO+ONJIGNgbwX9m09JaHw2s1XGOni9oPfiFPxZyyu0uzY9POdLZzFIe2aV5r CjA5Zqd1Yj2cIAdXo1Ai6CTnP5B2HdZ6jZSPz5DLxCR2B3cCISy/DmvfQ9rUKUAKZNrw8J4XV5O mfx4aDT9S4JsH42af3XMeR3ZvKKAQ9L/LlQT X-Received: by 2002:a05:6402:90a:b0:659:3ed2:13dd with SMTP id 4fb4d7f45d1cf-65bc78549ccmr2773867a12.4.1771182285118; Sun, 15 Feb 2026 11:04:45 -0800 (PST) MIME-Version: 1.0 From: yudhi s Date: Mon, 16 Feb 2026 00:34:30 +0530 X-Gm-Features: AaiRm52wJFtgTwA3GigSS9QmT_Xgf9v6H6VUovNMxAsG6NlbIMXzeUiGgINddK0 Message-ID: Subject: Question on execution plan and suitable index To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000efe209064ae1820e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000efe209064ae1820e Content-Type: text/plain; charset="UTF-8" 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". *Below is the query and its complete plan:- * https://gist.github.com/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 --000000000000efe209064ae1820e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,
It's postgres version 17. We are having a criti= cal UI query which runs for ~7 seconds+. The requirement is to bring down t= he 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 shou= ld be addressed. i.e. "Full scan of table "orders" and Neste= d loop with event_audit_log table".
<= br>
Below is the query and its= complete plan:-=C2=A0

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 creat= e composite Index on column (request_id,created_at,event_comment_text) or s= hould we create the covering index i.e. just on two column (request_id,crea= ted_at) with "include" clause for "event_comment_text".= How and when the covering index indexes should be used here in postgres. W= ant to understand from experts?=C2=A0
2)Similarly for table orders:- Sho= uld we create a covering index on column (entity_id,due_date,order_type) wi= th 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?

-> =C2=A0Nested Loop =C2=A0(cost=3D50.06..2791551.71 rows=3D3148 wid= th=3D19) (actual time=3D280.735..7065.313 rows=3D57943 loops=3D3)
=C2= =A0Buffers: shared hit=3D10014901
=C2=A0-> =C2=A0Hash Join =C2=A0(c= ost=3D49.49..1033247.35 rows=3D36729 width=3D8) (actual time=3D196.407..380= 5.755 rows=3D278131 loops=3D3)
Hash Cond: ((ord.entity_id)::numeric = =3D e.entity_id)
Buffers: shared hit=3D755352
-> =C2=A0Paral= lel Seq Scan on orders ord =C2=A0(cost=3D0.00..1022872.54 rows=3D3672860 wi= dth=3D16) (actual time=3D139.883..3152.627 rows=3D2944671 loops=3D3)
= =C2=A0Filter: ((due_date >=3D '2024-01-01'::date) AND (due_dat= e <=3D '2024-04-01'::date) AND (order_type =3D ANY ('{TYPE_A= ,TYPE_B}'::text[])))
=C2=A0Rows Removed by Filter: 6572678
= =C2=A0Buffers: shared hit=3D755208
=

Regards<= /font>
Yudhi
--000000000000efe209064ae1820e--