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 1soNbx-00AmkX-2I for pgsql-in-general@arkaria.postgresql.org; Wed, 11 Sep 2024 13:42:22 +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 1soNbw-000Ur2-Ff for pgsql-in-general@arkaria.postgresql.org; Wed, 11 Sep 2024 13:42:20 +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 1soNbw-000UqX-8a; Wed, 11 Sep 2024 13:42:20 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1soNbs-000eat-Re; Wed, 11 Sep 2024 13:42:19 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-53654dbde59so946593e87.1; Wed, 11 Sep 2024 06:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726062137; x=1726666937; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ESwChsIDHpRE3yaXc3m7g/vhow2b1ZOgDniDF6TbIPU=; b=jQEzjJKYuSgqOGjYLFxL89ocDd1YXhZCftodIS2UMyXM+UdEEjnLEXv2gSUTi7smMy VcXHej/pa17WVRTi/RIqWEgQ4GwJ6ddOuSamBG2DLGHASbZafx7GILGok52xKvl4OdkA yCbdeOQ+4Xv5G8H3X/kTEr4xHWiiPPS8TQzLPjlOUD4oio0ia1z4aZWU2QTY7351L8ck Mws4HyDlo0R4+Yfxsr8UDj1J+RiipHolud647dUFxnFOBjOGIhNT/0RMDD5+NIU0ZXMp CNg4E70QduqNdNuEpGJbNvjKAYckMR7Q597RBOka6DyfCxWMmodp6aE+wufP9JKaIY2H pniQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726062137; x=1726666937; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ESwChsIDHpRE3yaXc3m7g/vhow2b1ZOgDniDF6TbIPU=; b=F+B/ipDsS2U2TvCDAcdcvOTlGQTg3OhMD1K+wgwKAPpY8gyaRxKbWFUt/07Buj2Ath xRl3zzBJf7rkGktEvSzANcpPJaetXOz06tb0OIa73hAOkyEcTEf/hxUya7TF12vU78B6 3NhOXnBDmlyALdIwNg7my2Njyhsm8VW9ZM6SjdtAyCejRkO6ZH/049RewwjP6A7U2qJz SBNRT+Ggh3bUcoJ+wia3eQMxIP2drTEsMFXYpgXFInAdoV64dbzJMKtMUWeQfuV3dyRi Ri5GfC7iJT42B6c7PG84y41zr0Ny5/NXiuxNYKuHw+qHTezM+yibLej15c7EiRUgqKge gDBg== X-Forwarded-Encrypted: i=1; AJvYcCUKeHggSeJQni4VRZuERULh85l0TDRXH4G3HFOITBucL50ZJuEwCCs6zIJ2ePPyxtVnvNt5pMH3uKZYnNpBZZvMDw==@postgresql.org, AJvYcCVlOZRE/rfEkAkfsy7EaSn3ZOOmv3RujLmxktTO0NRAsRcXLpQKiUdZ7J1TGo25qZFf9ZUIURM8c0pgP2U3@postgresql.org X-Gm-Message-State: AOJu0Yz14tReR/ppzHxUfvBH7Fbw79bTBHigVjzjK6QzUX+wrLDjT8Pp 79Un/WFlqjFtAzqz/zug9tZX6d4DnWG90CdpugimBql3ZY6j8zK4gs8+i0fEDyp0d9kikrkX0aA wd3m0U7/Z4V4w1iUdpUSJ538XlcA= X-Google-Smtp-Source: AGHT+IFtVu5RgM8HRhh+fUQHLBKRHTC86waGIKiOKaFCyPjXMokrPOoSXzUgkP1tsIONJNL4JjSUnqzDxpLpfYMUTsw= X-Received: by 2002:ac2:4f02:0:b0:52e:fa78:63c0 with SMTP id 2adb3069b0e04-5366b933135mr2811640e87.13.1726062136859; Wed, 11 Sep 2024 06:42:16 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Greg Sabino Mullane Date: Wed, 11 Sep 2024 09:41:39 -0400 Message-ID: Subject: Re: Performance degrade on insert on conflict do nothing To: Durgamahesh Manne Cc: pgsql-general@lists.postgresql.org, pgsql-in-general@postgresql.org, Christoph Berg , laurenz.albe@cybertec.at, semab tariq , PostgreSQL mailing lists Content-Type: multipart/alternative; boundary="0000000000008722df0621d82804" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008722df0621d82804 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Sep 11, 2024 at 1:02=E2=80=AFAM Durgamahesh Manne wrote: > Hi > createdat | timestamp with time zone | | not null | now() > | plain | | | > modified | timestamp with time zone | | not null | now() > | plain | | | > Triggers: > i_dictionary_createdat BEFORE INSERT ON dictionary FOR EACH ROW > EXECUTE FUNCTION update_createdat_col() > i_dictionary_modified BEFORE INSERT OR UPDATE ON dictionary FOR EACH > ROW EXECUTE FUNCTION update_modified_col() > > How do we improve this query performance without taking more cpu? > 1. Lose the first trigger. I don't know exactly what those functions do, but if they are only for updating those columns, just remove the first one and let postgres handle it via NOT NULL DEFAULT. 2. Change the second trigger to just ON UPDATE 3. Remove that second trigger as well, and have the app populate that column (assuming that is all it does), e.g. UPDATE dictionary SET lang =3D 'foo', modified =3D DEFAULT, modified_by =3D 'foo' where tid =3D 12345; 4. Remove any indexes you do not absolutely need Cheers, Greg --0000000000008722df0621d82804 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Sep 11, 2024 at 1:02=E2=80=AFAM D= urgamahesh Manne <maheshpos= tgres9@gmail.com> wrote:
Hi=C2=A0
= =C2=A0createdat =C2=A0 =C2=A0 =C2=A0| timestamp with time zone | =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 | not null | now() =C2=A0 =C2=A0| plain =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=A0modified =C2=A0 =C2=A0 =C2=A0= | timestamp with time zone | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | not null= | now() =C2=A0 =C2=A0| plain =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|
Trigge= rs:
=C2=A0 =C2=A0 i_dictionary_createdat BEFORE INSERT ON dictionary FOR= EACH ROW EXECUTE FUNCTION update_createdat_col()
=C2=A0 =C2=A0 i_dictio= nary_modified BEFORE INSERT OR UPDATE ON dictionary FOR EACH ROW EXECUTE FU= NCTION update_modified_col()
=C2=A0
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
How = do we improve this query performance without taking more cpu?

1. Lose the first trigger. I don't know = exactly what those functions do, but if they are only for updating those co= lumns, just remove the first one and let postgres handle it via NOT NULL DE= FAULT.

2. Change the second trigger to just ON UPD= ATE

3. Remove that second trigger as well, and hav= e the app populate that column (assuming that is all it does), e.g. UPDATE = dictionary SET lang =3D 'foo', modified =3D DEFAULT, modified_by = =3D 'foo' where tid =3D 12345;

4. Remove a= ny indexes you do not absolutely need

Cheers,
Greg

--0000000000008722df0621d82804--