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 1qBEhX-0006H3-Cw for pgsql-performance@arkaria.postgresql.org; Mon, 19 Jun 2023 13:13:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qBEhW-0002nA-2v for pgsql-performance@arkaria.postgresql.org; Mon, 19 Jun 2023 13:13:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBEhV-0002n1-Op for pgsql-performance@lists.postgresql.org; Mon, 19 Jun 2023 13:13:45 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qBEhS-003Qhe-27 for pgsql-performance@lists.postgresql.org; Mon, 19 Jun 2023 13:13:44 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-987c932883bso367006366b.0 for ; Mon, 19 Jun 2023 06:13:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1687180421; x=1689772421; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=4I+xjATN38AszwX7zxcD2tLSkHBnQSUNdLJmKWvdHQM=; b=BSsucaOWfR+VFWlCHCwo2zW/ey2n/gFCmgMecDGQnbZqLVuB2fxKYTEh6c23oqFC5z ZyTSAwGDrLxOTSw45GKwCKm5KmOnIEtQX27eHE6b2iWlxY1kNPLqpT04Zf9JG0Cq1Egf yureafwvObjtVFrb1nTE/SB20Pn0osspAOcRoeMPguj2gu4jFpvdHpRp5Kk2JZ8GiHMp TrS9e2TX8E1DigcVNBw0nthUUSMnll9zbyBaOOccWSdoJ8Nd4Xm7E635gtBsGDDWPoS5 xvk1Y4vjSSmWtS/8AfAfYBFDSjtPuoHVslZ8meeUC3ig99DrBuLOiGDK6upBzn91r2aZ tBTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687180421; x=1689772421; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4I+xjATN38AszwX7zxcD2tLSkHBnQSUNdLJmKWvdHQM=; b=bTNGVRSjpbVIBdW6b4fcXuke8jbf1kLBlZqwsJNGkyXeqedFuPB6+6USH4zpfoxvYD 05+LcpkgtovUango57fOO4B72vYekkamIQFVuD7MYTF78j8wA6+cGWbIWuhgdxARxkI4 t6X9Zw2aSntGDXZmIo38nJEYIhtjnHQER6qxV/PFxE2jdFZUDm2sQLCFblDP/VOhlEyz wUBiUpKbkE1ZxktnJ3WCg9SoRLeEQT2PIXU/WZjr6/ydb9AGNz/gm7EiKCPFH/n7aym9 9F+dgqqZCz+OtBX0s0/ZBU9CXBOk/iMVBpGpeTbvHg3jflbGFD9KvjDCKZoyTs+E8zVQ ObEQ== X-Gm-Message-State: AC+VfDwuTqzadaQEPZlbIVA34nx2XxCQMBN51LG6kMja2b0go9sIqfNq KgdRRZs8mzjEBE1MId5NjZbYWg== X-Google-Smtp-Source: ACHHUZ6pkR40qVkBOioJZTjGmGOJoA5WSEb0sbhUGzvqfUHWq3Z7Q74FoX0rqHuXyucVl7Jcx5OscA== X-Received: by 2002:a17:907:a06:b0:974:1e0e:9bd4 with SMTP id bb6-20020a1709070a0600b009741e0e9bd4mr8961411ejc.16.1687180420855; Mon, 19 Jun 2023 06:13:40 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-228-220.bb.vodafone.cz. [86.49.228.220]) by smtp.gmail.com with ESMTPSA id b22-20020a1709065e5600b009871d95e7d7sm3847942eju.140.2023.06.19.06.13.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Jun 2023 06:13:40 -0700 (PDT) Message-ID: <36cb9fe9-b792-2345-65ed-586de44a48b9@enterprisedb.com> Date: Mon, 19 Jun 2023 15:13:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 Subject: Re: Merge David and Goliath tables efficiently Content-Language: en-US To: nicolas paris , pgsql-performance@lists.postgresql.org References: <20230619074646.2zlxxaqjieiafgqi@alvherre.pgsql> <27cdb9c5-6dc7-87ff-303e-b0d0d20edbc4@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/19/23 14:20, nicolas paris wrote: >> IMHO the thing that breaks it is the ORDER BY in the merge, which >> likely >> acts as an optimization fence and prevents all sorts of smart things >> including the partitionwise join. I'd bet that if Nicolas replaces >> >>   MERGE INTO "goliath" ca >>   USING (SELECT * FROM "david" ORDER BY "list_id") AS t >>   . > > Sorry if it was not clear, however there is no order by in the 2.1 > strategy. Then this cannot be the reason of not triggering the optim. > > For information I do enable partition join feature with jdbc call just > before the merge: > set enable_partitionwise_join=true > But you wrote that in both cases the query is: MERGE INTO "goliath" ca USING (SELECT * FROM "david" ORDER BY "list_id") AS t ON t."list_id" = ca."list_id" WHEN MATCHED THEN UPDATE SET ... WHEN NOT MATCHED THEN INSERT (...) VALUES (...) With all due respect, I'm getting a bit tired of having to speculate about what exactly you're doing etc. based on bits of information. I'm willing to continue to investigate, but only if you prepare a reproducer, i.e. a SQL script that demonstrates the issue - I don't think preparing that should be difficult, something like the SQL script I shared earlier today should do the trick. I suggest you do that directly, not through JDBC. Perhaps the JDBC connection pool does something funny (like connection pooling and resetting settings). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company