Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfSou-0004Hg-3x for pgsql-performance@arkaria.postgresql.org; Mon, 24 Jun 2019 17:31:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfSor-0002nK-E2 for pgsql-performance@arkaria.postgresql.org; Mon, 24 Jun 2019 17:31:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfSoq-0002nD-TK for pgsql-performance@lists.postgresql.org; Mon, 24 Jun 2019 17:31:53 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfSon-0003k3-LE for pgsql-performance@postgresql.org; Mon, 24 Jun 2019 17:31:51 +0000 Received: by mail-io1-xd2c.google.com with SMTP id h6so666586ioh.3 for ; Mon, 24 Jun 2019 10:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=6Te/oduHm/64rZyoaZ66Qu9r2vqfcZmUQ287rVcJp24=; b=P/iTn42VqlwU8VlZxO6CO9KBgUke08zXXmrkQdObd5MRHYjmDyQJzemo0XUrIPu61D ffHD42u1KWQvusa20vgnGXJX4SdA5wOXurWXDplvNi6Y/+MOsP4cG2ycuQOPym9kmCku 1oUbbJFlzXvjuc737X75kRPQfQu3FZKOcYNoZfE9WIYLFBQy6SCzbU0Lj3gmKstA4KYw GbG4wumQCRuQ/Yv2i875It0R9ZJcutuYOvQU5TjiOjA1iE2EkcwXMHyukwDozzK5hO4w A4HgzhpQDyAjl/CyFbN0XEnI/k87y0++RKwLG7LWatD03W664/MOKcPat5zEmXYkIqTJ m4oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=6Te/oduHm/64rZyoaZ66Qu9r2vqfcZmUQ287rVcJp24=; b=F6TMhLITYrH8GiD0g47Z7l6g1U1SuFOfA0CZkI/8B+2Tn9u+nXGtZf97zfskjM0wva /UhtvNgBi3TsH56eOgj7WIgbx/5olgOreRdsdRNhtG63lRlTKKjI/QqRQtiooJA73y5J fSvR1LCDmGtGCuuZTEc7PMOuZB8Ya+8ZbyKE/t4kwngJgkeeo3vPdxNMz5GcfIfVk3H+ 4C/M8l74HfaRTL0ycW8HkSR4X05wGF5EmoEfh/pB1qgMbAZSasM7yAPb6G1fo9XRf1oY ZBJKYXm09pdLCNAmKVxYCo5KC3544wi87nFqQ9bpGQDBbdZ6JOtnTLi5RGm7p3ZUa5xx TytA== X-Gm-Message-State: APjAAAVpi2Tk1QvoOUaZZ2tWFGlTieSmeFRGJcLqkBggfePia9pHTtin AfT/yZG2W3x+mm8YinK0CB7rPkoM60g= X-Google-Smtp-Source: APXvYqw0JziT2zOjUSrBe5sovwsaDK4Xxfh1MHmvgvy3sNqmJoLQwuIsrwgdzpa9mfM3XbBqLsk1Jw== X-Received: by 2002:a02:394c:: with SMTP id w12mr26939625jae.126.1561397508142; Mon, 24 Jun 2019 10:31:48 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id v13sm14442723ioq.13.2019.06.24.10.31.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jun 2019 10:31:47 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 6B37C800AB8; Mon, 24 Jun 2019 12:31:46 -0500 (CDT) Date: Mon, 24 Jun 2019 12:31:46 -0500 From: Justin Pryzby To: pgsql-performance@postgresql.org Subject: scans on table fail to be excluded by partition bounds Message-ID: <20190624173146.GA32632@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I came across a poorly performing report with a subplan like this: ts=# explain SELECT * FROM eric_enodeb_cell_metrics WHERE start_time BETWEEN '2019-01-01 04:00' AND '2019-01-01 05:00' OR start_time BETWEEN '2019-01-02 04:00' AND '2019-01-02 05:00'; Append (cost=36.04..39668.56 rows=12817 width=2730) -> Bitmap Heap Scan on eric_enodeb_cell_20190101 (cost=36.04..19504.14 rows=6398 width=2730) Recheck Cond: (((start_time >= '2019-01-01 04:00:00-05'::timestamp with time zone) AND (start_time <= '2019-01-01 05:00:00-05'::timestamp with time zone)) OR ((start_time >= '2019-01-02 04:00:00-05'::timestamp with time zone) AND (start_time <= '2019-01-02 05:00:00-05'::timestamp with time zone))) -> BitmapOr (cost=36.04..36.04 rows=6723 width=0) -> Bitmap Index Scan on eric_enodeb_cell_20190101_idx (cost=0.00..16.81 rows=6465 width=0) Index Cond: ((start_time >= '2019-01-01 04:00:00-05'::timestamp with time zone) AND (start_time <= '2019-01-01 05:00:00-05'::timestamp with time zone)) -> Bitmap Index Scan on eric_enodeb_cell_20190101_idx (cost=0.00..16.03 rows=259 width=0) Index Cond: ((start_time >= '2019-01-02 04:00:00-05'::timestamp with time zone) AND (start_time <= '2019-01-02 05:00:00-05'::timestamp with time zone)) -> Bitmap Heap Scan on eric_enodeb_cell_20190102 (cost=36.08..20100.34 rows=6419 width=2730) Recheck Cond: (((start_time >= '2019-01-01 04:00:00-05'::timestamp with time zone) AND (start_time <= '2019-01-01 05:00:00-05'::timestamp with time zone)) OR ((start_time >= '2019-01-02 04:00:00-05'::timestamp with time zone) AND (start_time <= '2019-01-02 05:00:00-05'::timestamp with time zone))) -> BitmapOr (cost=36.08..36.08 rows=6982 width=0) -> Bitmap Index Scan on eric_enodeb_cell_20190102_idx (cost=0.00..16.03 rows=259 width=0) Index Cond: ((start_time >= '2019-01-01 04:00:00-05'::timestamp with time zone) AND (start_time <= '2019-01-01 05:00:00-05'::timestamp with time zone)) -> Bitmap Index Scan on eric_enodeb_cell_20190102_idx (cost=0.00..16.84 rows=6723 width=0) Index Cond: ((start_time >= '2019-01-02 04:00:00-05'::timestamp with time zone) AND (start_time <= '2019-01-02 05:00:00-05'::timestamp with time zone)) Is there some reason why the partition constraints aren't excluding any of the index scans ? In the actual problem case, there's a longer list of "OR" conditions and it's even worse. The partitions looks like this: Partition of: eric_enodeb_cell_metrics FOR VALUES FROM ('2019-01-02 00:00:00-05') TO ('2019-01-03 00:00:00-05') Indexes: "eric_enodeb_cell_20190102_idx" brin (start_time) WITH (autosummarize='true'), tablespace "oldindex" "eric_enodeb_cell_20190102_site_idx" btree (site_id) WITH (fillfactor='100'), tablespace "oldindex" Check constraints: "eric_enodeb_cell_20190102_start_time_check" CHECK (start_time >= '2019-01-02 00:00:00-05'::timestamp with time zone AND start_time < '2019-01-03 00:00:00-05'::timestamp with time zone) Tablespace: "zfs" And: pg_get_partition_constraintdef | ((start_time IS NOT NULL) AND (start_time >= '2019-01-02 00:00:00-05'::timestamp with time zone) AND (start_time < '2019-01-03 00:00:00-05'::timestamp with time zone)) ts=# SELECT version(); version | PostgreSQL 11.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23), 64-bit ts=# SHOW constraint_exclusion ; constraint_exclusion | partition ts=# SHOW enable_partition_pruning; enable_partition_pruning | on Thanks in advance. Justin