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 1sg0Ay-00E9TO-25 for pgsql-general@arkaria.postgresql.org; Mon, 19 Aug 2024 11:03:52 +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 1sg0Au-001OCd-UQ for pgsql-general@arkaria.postgresql.org; Mon, 19 Aug 2024 11:03:49 +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.94.2) (envelope-from ) id 1sg0Au-001OBS-HH for pgsql-general@lists.postgresql.org; Mon, 19 Aug 2024 11:03:49 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sg0As-000OOl-U9 for pgsql-general@lists.postgresql.org; Mon, 19 Aug 2024 11:03:48 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52f0277daa5so5359654e87.0 for ; Mon, 19 Aug 2024 04:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724065425; x=1724670225; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OdVgSKG33iBJ0QubMkn+J0s//ZUUtzyrELmrgWS94I4=; b=fXNWrIAf91daRFYzKkH+whzJoXZLaiDpZ8Sm4fra0dkx9N0yhKcEKCS4ohaQSRzxwR DImEqHJxwUUIT5jk4gF9VommaLant3mOgPLi0DOX2b04OO+3Bra67N14e7ZeWgS/5aLj 6d3rfZ6NIUOE5ADokPB+NstgK6nfHFeCokvrszRE6N9J+QlRD2vztUO6JeG3Jh9JGOI4 ITHbDx+ASo5deI5bzywaLiwXcu8PpCs8mBSswrwVRS5azUTocobsFE/UvX5HESux3h6W d653GHyfUeE6DgwtDGH/itlK3385x1c3L2Qaa60l3A3hhjRQn931W6YJ2he0V4N15E7J uCow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724065425; x=1724670225; h=content-transfer-encoding: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=OdVgSKG33iBJ0QubMkn+J0s//ZUUtzyrELmrgWS94I4=; b=MLjsS3alNPUbSmK3BLYAwZmJofSc0MSYd1pa9DYS30umT96Q5qZhTRCkZ9Rqw6yX26 3JmEYimmZIS7dALemSlA10xmUMEvjGPjCawfBWubhaO8HAxonGYUFtAWRhY0FoPyaba4 7e4XjKcQ4GkAo5avi6H7ijliQ46dl61DspkcmicVVNpkxVhUHMie0C6rgsqn43Rl+JGu M0jIA0ob0Lk55XFLLwsWr1X+UgLSKqrzLADMPE6VaSh/13GgXl0VDEkZGLNkJJLHcHDC QN6eEdOM37eyd8YKlx5s6p3/+DGyev40H6HjnrklhltZZLs7pYvxbshMkyIaD2drKNzm Oe/g== X-Gm-Message-State: AOJu0YycAviYQwNdh0hyQEomBsZvEuSm7D/6yBYrTTYkBN9BR5gaLCdP Z3R41I2MnFNbF00ciEoLllu9pQ1m4ThfVZqWwq0zXn0TXCfHMEiQ05bfXlf4WyLzTYXMjtCBkBS 6bTODTBZee3EGCT1egqA3ZtAa4yFc/77K X-Google-Smtp-Source: AGHT+IHVL9yxiByflV1Vl+GB88RlncH4k3kA2wSJz4ZMfqz4GSVLjk9SslRG+yzSIzZ2MMuRfOEyqHkW26XThPfYxVs= X-Received: by 2002:a05:6512:3085:b0:52c:f3fa:86c with SMTP id 2adb3069b0e04-5331c6a20fcmr6302292e87.18.1724065424365; Mon, 19 Aug 2024 04:03:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Mon, 19 Aug 2024 23:03:32 +1200 Message-ID: Subject: Re: Insert query performance To: sud Cc: pgsql-general Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 19 Aug 2024 at 19:48, sud wrote: > In a version 15.4 postgres database, Is it possible that , if we have two= big range partition tables with foreign key relationships between them, in= sert into the child table can cause slowness if we don't have foreign key i= ndex present in the child table? Basically it need to make sure the new row= already added to parent partition table or not. Having an index on the referencing columns is only useful for DELETEs and UPDATEs affecting the foreign key column(s). For INSERTs to the referencing table, technically having indexes there would only slow down inserts due to the additional overhead of having to maintain the index, however, the overhead of having the index might be fairly minuscule when compared to performing a CASCADE UPDATE or DELETE to the referencing table when the DDL is performed on the referenced table. > And if there is any possible way(example query tracing etc) to get the un= derlying system queries which gets triggered as part of the main insert que= ry? For example in above scenario, postgres must be executing some query to= check if the incoming row to the child table already exists in the parent= table or not? EXPLAIN ANALYZE will list the time it took to execute the foreign key trigger in the "Trigger for constraint" section. David