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 1ubgIf-003tzb-Gw for pgsql-general@arkaria.postgresql.org; Tue, 15 Jul 2025 14:06:29 +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 1ubgId-002Her-JI for pgsql-general@arkaria.postgresql.org; Tue, 15 Jul 2025 14:06:28 +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 1ubgId-002Hei-6o for pgsql-general@lists.postgresql.org; Tue, 15 Jul 2025 14:06:27 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ubgIb-007t1K-14 for pgsql-general@lists.postgresql.org; Tue, 15 Jul 2025 14:06:27 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-ae0bc7aa21bso1148383266b.2 for ; Tue, 15 Jul 2025 07:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1752588382; x=1753193182; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=oGGovvUhOYgKgF51nOzV+/Leeb2TZNL7tWvKAvVU+uE=; b=GzLBsFvJ2cu02qNL5zqSRGann1km9PVdPI5JRjo+85qAzR40ZaZ157DVLAp3XZkS1N caD1OXZSoOe3fQzJesUKho7g6U0hGexZgjcocUaRkKrADCkRmTVaHscmEn73YcTEDzjo qrUgGGzhDDWFYYaRT+uiBsW/IlffnFkQyClgmHckfsBsM2ZUHXt2xFiT2bBj7ts2hu0+ oGsmnV5OTrVc6FoYKC60oECptPg06Ku711LTZKuYU8xfCowcs9O54HH2YWCz/YRl11ap 5y9sEn1RyCNiyFY/JTYKjeTjFQvl1Mi00CibxyfhQ/oUIXp76EMcG4EOC/rGoiepK2RI bQWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752588382; x=1753193182; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=oGGovvUhOYgKgF51nOzV+/Leeb2TZNL7tWvKAvVU+uE=; b=I6AleZg+jjXm04wjDUneiUN3txfCTWmmLVajj3bBZw1tPWA6s0D6BTv1E6FIL8aek5 dtpX9iULQGiGTU5eZGnZRzdY3IEeUsiO5xueKNH0h4gTvvybvTBT8NN+j6scfqazH1YP gBlDsec331+PbdC1rdHxTwkkjTUHlNyOWq7y1yWAZ1olykiWT9f49Lzo6A8enaqbIQG5 gn93r2ZyGBuFApy9swshyltO5QMx0cr7Opnj3XurqicwdSRJYN2V0loLOj7Y2TTNm+Rv OodgPk3QF+rBT+sqaaWjo0QC7zkEJ2vpl2fB/UzlDJvi5Vf8Ni/KBeSBrdlApqI+j2LW xC1g== X-Gm-Message-State: AOJu0Yy/X/4fP6tF9HS6W8FpsfxYvj+rADAA1FYbAB0iBmE1G8SyOpis aZOjTkwTewswY0kR4IC/xQ0HrxC/JDS2QaG3ehrdCF3c6GYjshJIM8h6Vn/cis1o4ZEQvACKwqs fZgB2 X-Gm-Gg: ASbGncumLwAHqGuYXgGJlzIsXsBng/rFJeVHdDK+OGuIxB4i/ISW+O6OH4sZS+QEIaZ 5BALUK3p3DYhQOfQeJbdf4UAuu9fTEru23tYmPcH5fbAZkk9VwSDRH0tdZlK/M0Fwy11hytZHVp ZPbFWKBz/pTB85mdmF1WLdnn/B0xBx5T+W9jLzZYzcRr/zZWaS4uEf3/WfEUldr+zvbYskIr0Uy RtCadWsQ14zt4ofrpu1wZukLz+x2a3+CgMlcWlHGBnsjd+uYtOsmjNH3OotQtYDOYSj6nWVQJHn 1b1uiomHEF4AAYsMUid/Z+GpLrgaebKStdz+Z0Aq28iA3+X/EagTmQNMdiZY8HJNibr18S8I3n2 ic04TO3go4P5+04A9b0Vae8lwlSdR7MOZ/aA3X8us3xAfZJJqw/Mm X-Google-Smtp-Source: AGHT+IGzUXG+1DlsDXXbnuyEJnYWtQ/KCGDnh40uk+7pM8IGo3pZY1rHnleug4JPuUKgThemBfR36g== X-Received: by 2002:a17:906:4fca:b0:adf:f82f:fe0a with SMTP id a640c23a62f3a-ae6fca48ec3mr2132230566b.16.1752588381483; Tue, 15 Jul 2025 07:06:21 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:260:6b34:b252:6ee9:4652:d1b4]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae6e8298f85sm1020360066b.144.2025.07.15.07.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jul 2025 07:06:21 -0700 (PDT) Message-ID: <826536fd65cb6b25e996ac449336ce9c2476174b.camel@cybertec.at> Subject: Re: Regarding query optimisation (select for update) From: Laurenz Albe To: Durgamahesh Manne Cc: pgsql-general Date: Tue, 15 Jul 2025 16:06:20 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-1.fc42) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-07-15 at 18:26 +0530, Durgamahesh Manne wrote: > On Tue, Jul 15, 2025 at 6:14=E2=80=AFPM Laurenz Albe wrote: > > On Tue, 2025-07-15 at 15:40 +0530, Durgamahesh Manne wrote: > > > We are facing issues=C2=A0with slow running query=C2=A0 > > > =C2=A0 =C2=A0SELECT betid, versionid, betdata, processed, messagetime= , createdat, updatedat > > > =C2=A0 =C2=A0 FROM praermabetdata where processed =3D 'false' > > > =C2=A0 =C2=A0 ORDER BY betid, versionid LIMIT 200 OFFSET 0 FOR UPDATE= ;=C2=A0=C2=A0 > > >=20 > > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0QUERY PLAN > > > ---------------------------------------------------------------------= ----------------------------------------------------------- > > > =C2=A0Limit =C2=A0(cost=3D0.28..1.89 rows=3D1 width=3D78) > > > =C2=A0 =C2=A0-> =C2=A0LockRows =C2=A0(cost=3D0.28..1.89 rows=3D1 widt= h=3D78) > > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-> =C2=A0Index Scan using idx_praer= mabetdata_processed_betid_versionid on praermabetdata =C2=A0(cost=3D0.28..1= .88 rows=3D1 width=3D78) > > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: (p= rocessed =3D false) > > >=20 > > > image.png > > >=20 > > > Do we have any alternative way to improve the performance? > > > Sometimes processed column use true as well as false=C2=A0 > >=20 > > Please provide EXPLAIN (ANALYZE, BUFFERS) output and use "log_lock_wait= s" > > to see if you are hanging behind locks for a longer time. >=20 > image.png Text is easier to read than images... Anyway, this statement was done in under a millisecond. I wouldn't call that slow... Yours, Laurenz Albe