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 1qBajp-0005yq-M2 for pgsql-performance@arkaria.postgresql.org; Tue, 20 Jun 2023 12:45:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qBajo-0002t7-Aj for pgsql-performance@arkaria.postgresql.org; Tue, 20 Jun 2023 12:45:36 +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 1qBajn-0002sx-S4 for pgsql-performance@lists.postgresql.org; Tue, 20 Jun 2023 12:45:35 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qBajk-003cmf-73 for pgsql-performance@lists.postgresql.org; Tue, 20 Jun 2023 12:45:34 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4f7deee339dso5718181e87.0 for ; Tue, 20 Jun 2023 05:45:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1687265131; x=1689857131; 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=bDgscNi5zqS0ZVfO51JH+GrAXPwMcs0isGIcAfzxf/U=; b=LwvZne1GrRVNl1n+F3R0c848s/RIMgPhmy4RQbqI4Ys/CzsE0J48XLr99lNEVq+sDo GBpsfPMb2HWcEdJUDIuC23xRRXYjcem3vtuQW8v94jmHIUDY15u/qFOE+izrqXWRB7rv +++R88ONOQd3to+Eo9EYcyexY3ghauXiKyzTITLmc5OmVZQ2jpYldniMoJp/N7ovI3y2 zPBYoO9Yd6X6idkTT0seSKxqgPvjFD7TO9Ey+1UsVNYVyfOtXYBZyeoo0yeqDadLAdqO V1/YzU5FaGSI3P/9iWg/hwwUWhUsvQ9ujnFKogYnVZ0Cl+JzJjlyPyn2drvK3f7Cm4Dd 4mCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687265131; x=1689857131; 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=bDgscNi5zqS0ZVfO51JH+GrAXPwMcs0isGIcAfzxf/U=; b=gZWMm8ew+QDTVvcYCqK5Mrh6oexOPioB9qPhVm6v3fAFB+0ARS+O5G1AaONWzcepHd 761Em9T0WrnjaANYthg3/ZdebxGpvW1aNUSBcyMR7PkBuo2i6MzhyZ/ehuPhcd9bhkG5 kYRd+X9Fk4RZqxC2K2xLumYJaMr0Xd1v1kvEEre/8SMrviAm0+4K//AnCPb491/98DZw kdl8UFpljNd0aJVM7OG34Yz/DY0bYlYFX+E+KFHucuTk3pGnPs/jGJ9rclaZcCEKx/rf W9RiJWMRkx63OCoS0x36ngFPwmByH7Ie1cSHoFcEi+9gUE/4OAP4qHfS69ZAgXh+2Qjm tgpw== X-Gm-Message-State: AC+VfDyk7zW7mJz8wjAnY5l5w0vB8I0d8EwaR2CY1tN1rcYFbbP6vfuS OkHUp+xcQKbuQBn8hPc1ys5h4w== X-Google-Smtp-Source: ACHHUZ44unFrggupf/Xso1+I4pKu3okhgqCwTHUnU0z0Iw1tso5x23sP/yEeQRDSNW9rTYnLHYx5OQ== X-Received: by 2002:a19:9113:0:b0:4f8:7055:6f7e with SMTP id t19-20020a199113000000b004f870556f7emr3005472lfd.44.1687265130920; Tue, 20 Jun 2023 05:45:30 -0700 (PDT) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id a2-20020a05600c224200b003f9b53959a4sm2850980wmm.43.2023.06.20.05.45.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Jun 2023 05:45:30 -0700 (PDT) Message-ID: <3efe2d22-504a-a1bc-79fa-cff64c81e76a@enterprisedb.com> Date: Tue, 20 Jun 2023 14:45:30 +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> <36cb9fe9-b792-2345-65ed-586de44a48b9@enterprisedb.com> <45316372426111f4b1dffa6de420804da3befa3d.camel@riseup.net> <63977a990ee6f3fbbedf4ca78e289591fe38d8a3.camel@riseup.net> From: Tomas Vondra In-Reply-To: <63977a990ee6f3fbbedf4ca78e289591fe38d8a3.camel@riseup.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/20/23 12:02, nicolas paris wrote: >... > > Definitely this makes sense to add the part_col in the join columns. > Also it helps the planner to choose a better plan, since now it goes > with per partition nested loop without having to trick the costs > (either enable_hashjoin/random_page_cost), with my current workload so > far. > Right. With non-partitionwise join the nestloop inner lookup has to do indexscan on every partition (it can't decide which of the partitions will have a match, and for costing we assume there's at least 1 row in each lookup). Which essentially amplifies the amount of random I/O by a factor of 100x (or whatever the number of partitions is). That is, instead of doing 100x nested loops like this: -> Nested Loop Left Join (cost=0.29..33.42 rows=8 width=47) -> Seq Scan on david_98 david_99 (cost=0.00..1.08 -> Index Scan using goliath_98_id_part_col_idx on Index Cond: ((id = david_99.id) AND ...) we end up doing one nested loop with an inner lookup like this -> Append (cost=0.29..557.63 rows=100 width=14) -> Index Scan using ... goliath_1 (cost=0.29..5.57 ... Index Cond: (id = david.id) ... And this is per-loop, of which there'll be 500 (because the small david table has 500 rows). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company