Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q5nl1-0003Hn-Dn for pgsql-performance@arkaria.postgresql.org; Sun, 04 Jun 2023 13:26:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q5nl0-00075O-73 for pgsql-performance@arkaria.postgresql.org; Sun, 04 Jun 2023 13:26:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q5nkz-00075E-U2 for pgsql-performance@lists.postgresql.org; Sun, 04 Jun 2023 13:26:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q5nkt-0009ig-8o for pgsql-performance@lists.postgresql.org; Sun, 04 Jun 2023 13:26:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 354DQi3g3726929; Sun, 4 Jun 2023 09:26:44 -0400 From: Tom Lane To: Satalabaha Postgres cc: pgsql-performance@lists.postgresql.org Subject: Re: Weird behavior of INSERT QUERY In-reply-to: References: Comments: In-reply-to Satalabaha Postgres message dated "Sun, 04 Jun 2023 14:04:52 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3726927.1685885204.1@sss.pgh.pa.us> Date: Sun, 04 Jun 2023 09:26:44 -0400 Message-ID: <3726928.1685885204@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Satalabaha Postgres writes: > The select query in the insert returns about 499 rows. However, this insert > statement when executed from application user i.e. schema1_u takes close to > 8 minutes. When the same insert statement gets executed as postgres user > it takes less than 280 ms. Both the executions use the same execution plan > with only difference that when schema1_u executes the SQL, we observe > "Trigger for constraint fk_con_tablea: time=426499.314 calls=499" taking > more time. So you need to find out what's happening in the trigger. Perhaps auto_explain with auto_explain.log_nested_statements enabled would give some insight. I suspect there might be a permissions problem causing schema1_u to not be allowed to "see" the statistics for table_b, resulting in a bad plan choice for the FK enforcement query; but that's just a guess. regards, tom lane