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 1sdwJP-002Qw5-HM for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Aug 2024 18:32:03 +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 1sdwJO-005hfs-6i for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Aug 2024 18:32:02 +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 1sdwJN-005hfk-UK for pgsql-bugs@lists.postgresql.org; Tue, 13 Aug 2024 18:32:01 +0000 Received: from relay1-d.mail.gandi.net ([2001:4b98:dc4:8::221]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sdwJL-004a8y-BJ for pgsql-bugs@lists.postgresql.org; Tue, 13 Aug 2024 18:32:00 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 2AF77240004; Tue, 13 Aug 2024 18:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1723573915; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5SS/h8XJBAEFUUQzhPh3JYDQT8eEjB/1lmGJMYeUUTw=; b=cpjiZlmmtwSfGq8uo89bt0OxswuUhXrJO7xVDGibYVQoIodXYtAZ36xrYdmlDW55BZhviY V4BIqogcVvauoYm/BDukvt0swJ8cCKqbjRa0wzkjOqoyZPi6iO4bGgrRWHSUVP3U8VRf5a Sj9ukKgksOBDBP8xZJGzDYbXGOwWFWszkgJuJeTGn8bEGErjs5ORLwDNTcEW+9dox/+7eU XdMECYWWSPc0RMKvoXHKZQnZlzrgsuvlTPMuPs7DYQ4OI+07+H7046jNkckRuci4Efnl/l bXTdyNWQYtQUemrDbPNqDEMY0zU+mJegTmjagmkeQRt+Woe6x5/JwvQd91snUg== Message-ID: <900ad3fe-151e-4876-a399-fa12faa2c653@vondra.me> Date: Tue, 13 Aug 2024 20:31:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: FDW INSERT batching can change behavior To: git@jasonk.me, pgsql-bugs@lists.postgresql.org References: <20240809030755.jubqv6f6vpxkfkzv@jasonk.me> Content-Language: en-US From: Tomas Vondra In-Reply-To: <20240809030755.jubqv6f6vpxkfkzv@jasonk.me> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I took a closer look at this, planning to way to fix this, but I think it's actually a bit worse than reported - both in impact and ways how to fix that. The problem is it's not really specific to DEFAULT values. The exact same issue exists whenever the insert uses the expressions directly. That is, if you do this: insert into grem1 (a) values (counter()), (counter()), (counter()), (counter()), (counter()); it will misbehave in exactly the same way as with the default values. Of course, this also means that my original idea to disable batching if the foreign table has (volatile) expression in the DEFAULT value won't fly. This can happen whenever the to-be-inserted rows have any expressions. But those expressions are evaluated *outside* ModifyTable - in the nodes that produce the rows. In the above example it's ValueScan. But it could be any other node. For example: insert into grem1 (a) select counter() from generate_series(1,5); does that in a subquery. But AFAICS it could be any other node. Ideally we'd simply set batch_size=1 for those cases, but at this point I have no idea how to check this from ModifyTable :-( In retrospect the issue is pretty obvious, yet I haven't thought about this while working on the batching. This is embarrassing. regards -- Tomas Vondra