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 1kZyVA-0003xX-HU for pgsql-performance@arkaria.postgresql.org; Tue, 03 Nov 2020 15:45:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kZyV8-0005fR-Ou for pgsql-performance@arkaria.postgresql.org; Tue, 03 Nov 2020 15:45:38 +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 1kZyV8-0005f3-Cj for pgsql-performance@lists.postgresql.org; Tue, 03 Nov 2020 15:45:38 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kZyUu-0004g5-Kh for pgsql-performance@lists.postgresql.org; Tue, 03 Nov 2020 15:45:37 +0000 Received: by mail-wr1-x432.google.com with SMTP id x7so19077557wrl.3 for ; Tue, 03 Nov 2020 07:45:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=GXHZJYig8MK76fbOXfqr9VJXct3VmtnbJJ4xFOEIWWk=; b=UdZl8iopl//Rw1xvKrI6FYVvS/sm5eyaK1iukQw/n7mojOTz1L5AKGFuFRWkyEU9Bm UfQucJFACqMBR3gmRoufWDPEY03EAccjgXGi5J2kZ6XDjLL87ns905UV0SdCkU3ppsZe XakljslrgsFI5U7oFVB9lHjHjl0CseVr98lEYfTLeuoAM3OWlxjfT+LUqD5y0aHbgwDT BhMgL/3PPIil13Sk7ucpJXSgbkEKa5Gh7432ckH9YFDK7xQ/Aq6XBDbTSMkrc/IoyaSY WOLt/sTYlR+0Cyrum4w03eQFwoMzCbe7jihEd43aw0up7WLn2Bojx8Al49EndUlbUSXi oYfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=GXHZJYig8MK76fbOXfqr9VJXct3VmtnbJJ4xFOEIWWk=; b=PdK+m6+d0lZm4ZKJGic9GCTpESTCyo72RT66IScjFn86KPZdFntvRSyllXFn1pTye8 fsThN5XcRxXIlhRES/atEJcnkt3oomjJj9R4lL01LMuhIOSPeqg1iS2m0IofGGh/ks55 1y/64/4esGioCSmP4kN9dUHkf7F7+zjma020kQ6kdV4CPv8jVY53xHHxsPtNRATytRvC iQJ7i41N5jkdBzkF9KC+yF1CIIgnxeF3OMeTUdyn8019YHA+kJnLP8u1i5d8lqJlmBD8 WCjAVMQ8LJNmA4OE5q7DueNmTswLkALJlQGf4RAv3Z5JKfN5LAtkQlAyJmcSLiNyYxBG P76g== X-Gm-Message-State: AOAM532YH+X+SvVtUdquxXklDnzNR2VG5yDMGEzqfQrt9PxuV5GsWrah C+ITVgcY74t5LUWFMX75upSUog== X-Google-Smtp-Source: ABdhPJz5Q+vj0yB2tdy+avLOXuUt928NCFhxaFpP84KHrQ9O2lz0851C1W3SiSlE7RKq730rK2vc+A== X-Received: by 2002:adf:e650:: with SMTP id b16mr27760018wrn.350.1604418322505; Tue, 03 Nov 2020 07:45:22 -0800 (PST) Received: from localhost.localdomain (217-149-173-218.nat.highway.telekom.at. [217.149.173.218]) by smtp.gmail.com with ESMTPSA id e2sm27902993wrr.85.2020.11.03.07.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:45:21 -0800 (PST) Message-ID: <2bc1899e624f66e4ca90978540d4e4eeecfe47c6.camel@cybertec.at> Subject: Re: Partition pruning with joins From: Laurenz Albe To: "Ehrenreich, Sigrid" , "pgsql-performance@lists.postgresql.org" Date: Tue, 03 Nov 2020 16:45:21 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, 2020-11-03 at 13:20 +0000, Ehrenreich, Sigrid wrote: > I would like to join a partitioned table and have the joined columns in the where clause to be used for partition pruning. > From some readings in the internet, I conclude that this was not possible in v12. I hoped for the > “improvements in partition pruning” in v13, but it seems to me, that it is still not possible, or is it and I am missing something here? > > My testcase: > create table fact (part_key integer) partition by range (part_key); > create table fact_100 partition of fact for values from (1) to (101); > create table fact_200 partition of fact for values from (101) to (201); > > insert into fact (part_key) select floor(random()*100+1) from generate_series(1,10000); > insert into fact (part_key) select floor(random()*100+101) from generate_series(1,10000); > > create table dim as (select distinct part_key from fact); > create unique index on dim (part_key); > > analyze fact; > analyze dim; > > -- Statement > explain SELECT > count(*) > FROM > dim INNER JOIN fact ON (dim.part_key=fact.part_key) > WHERE dim.part_key >= 110 and dim.part_key <= 160; > > Plan shows me, that all partitions are scanned: > Aggregate (cost=461.00..461.01 rows=1 width=8) > -> Hash Join (cost=4.64..448.25 rows=5100 width=0) > Hash Cond: (fact.part_key = dim.part_key) > -> Append (cost=0.00..390.00 rows=20000 width=4) > -> Seq Scan on fact_100 fact_1 (cost=0.00..145.00 rows=10000 width=4) ⇐==== unnecessarily scanned > -> Seq Scan on fact_200 fact_2 (cost=0.00..145.00 rows=10000 width=4) > -> Hash (cost=4.00..4.00 rows=51 width=4) > -> Seq Scan on dim (cost=0.00..4.00 rows=51 width=4) > Filter: ((part_key >= 110) AND (part_key <= 160)) One thing you could try is to partition "dim" just like "fact" and set "enable_partitionwise_join = on". I didn't test it, but that might do the trick. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com