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 1wQkNN-001qL0-2w for pgpool-hackers@arkaria.postgresql.org; Sat, 23 May 2026 11:18:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wQkNJ-00Fchu-2E for pgpool-hackers@arkaria.postgresql.org; Sat, 23 May 2026 11:18:38 +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 1wQkNJ-00Fchm-1C for pgpool-hackers@lists.postgresql.org; Sat, 23 May 2026 11:18:38 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wQkNB-00000000PLT-3Pxj for pgpool-hackers@lists.postgresql.org; Sat, 23 May 2026 11:18:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=kyAIU6poZUqF/XJCL0TJUCkb8Oa2PgkCHzN17owuxLo=; b=rROFgJiIXbI1YSGaotHpnPcmlH rCpEF0EZUEfkqtcnl/SJcXVitttC6sxEcVScTdbhsb+yOAJMkWdm/6v0usJN0ckDslSy4OALzD6OI jbwd2H0wibVBrYlVn1pge9bW4NVYa1iddqtVyeJRRdCkspQmqp2JkQ6mSSB8XggcptcmvHtjXC8I2 CVbz20G5Fr4/7oJaJXBq7MughMmk4OZXx2FgiKy6ehiLa8ZrC8+xBVcfj5ugxEg7wNH2jS/SQCB7i VSl3sT+vGj5HlM0PxQ81UtHHoiSAj+p3sweMAQVHNy9f8rKcDbRG2qX3NirJbgDRAtE5NPwvgN4ng uko/iBuw==; Received: from [2409:11:4120:300:2605:9a86:600:f539] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wQkN7-002QY6-2X; Sat, 23 May 2026 11:18:28 +0000 Date: Sat, 23 May 2026 20:18:16 +0900 (JST) Message-Id: <20260523.201816.2108820434774242495.ishii@postgresql.org> To: nadav@tailorbrands.com Cc: pgpool-hackers@lists.postgresql.org Subject: Re: Proposal: Recent mutated table tracking in memory From: Tatsuo Ishii In-Reply-To: <20260521.185044.504532841722447976.ishii@postgresql.org> References: <20260520.132810.1024114140609315185.ishii@postgresql.org> <20260521.185044.504532841722447976.ishii@postgresql.org> X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_May_23_20_18_16_2026_327)--" Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:2605:9a86:600:f539 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Sat_May_23_20_18_16_2026_327)-- Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit > I think you are talking about the logic to judge whether we are in an > explicite transaction or not here. Current dml_adaptive checks > supplied query is a transaction starting command like BEGIN. IMO this > is fundamentaly wrong because the command may fail by various reasons. > The correct way is checking transaction state by using TSTATE > macro. Note that the macro can only be used at leat one ready for > query response returned from backend (simple query protocol case), or > command complete response is returned from backend (extended query > protocol case). > >> In native replication and snapshot isolation modes, >> dml_adaptive() is never called (it lives inside >> where_to_send_main_replica), so is_in_transaction is never set >> to true even inside an explicit BEGIN/COMMIT block. That meant >> every DML in those modes was treated as autocommit by the >> write-tracking code, triggering >> pool_track_table_mutation_get_database_oid() ― which does a >> relcache do_query ― while a transaction was actually in flight >> on the backend connection. The do_query conflicts with the >> in-flight transaction and hangs the session. > > Assuming "a transaction was actually in flight" means a transaction > was open (explicit transaction), not really. do_query can be called > inside or outside of an explicit transaction. > > Anyway, I found dml_adaptive is completely broken (it brings wrong > results if query cache enabled). Unless there are users for the > feature, maybe we should remove dml_adaptive entirely? It appears that other options of disable_load_balance_on_write are all broken too, except "transaction". I don't want to discard all of them, so I come up with attached patch. The query cache relies on is_writing_transaction of session context to judge whether cache can be safely used. However, disable_load_balance_on_write overrides it to true when it should not, and vice versa for its own purpose. To fix this, a new session context variable "really_writing_transaction" is introduced. It is almost same as existing writing_transaction, but it faithfully tracks whether a writing query appears in an explicit transaction. The query cache uses it instead of writing_transaction variable. Currently, master branch is broken because of commit 2ae004a48. If you want to try the patch, I recommend to checkout 48e1d6d3c, then apply the patch. Regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp ----Next_Part(Sat_May_23_20_18_16_2026_327)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="v1-0001-Fix-disable_load_balance_on_write-and-query-cache.patch"