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 1hPChn-0001r4-Q5 for pgsql-bugs@arkaria.postgresql.org; Fri, 10 May 2019 21:05:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hPChl-0003to-I4 for pgsql-bugs@arkaria.postgresql.org; Fri, 10 May 2019 21:05:21 +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 1hPChl-0003th-6A for pgsql-bugs@lists.postgresql.org; Fri, 10 May 2019 21:05:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hPChe-0003Wh-OQ for pgsql-bugs@lists.postgresql.org; Fri, 10 May 2019 21:05:19 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x4AL5906020308; Fri, 10 May 2019 17:05:10 -0400 From: Tom Lane To: Amit Langote cc: Kyotaro HORIGUCHI , ajax@tvsquared.com, pgsql-bugs@lists.postgresql.org Subject: Re: inconsistent results querying table partitioned by date In-reply-to: <90aeaf38-270a-7e45-6b7d-af2e3d1e3719@lab.ntt.co.jp> References: <24525.1557444159@sss.pgh.pa.us> <49cd5235-cbe6-e686-8014-85c1e45efe56@lab.ntt.co.jp> <20190510.153337.236910404.horiguchi.kyotaro@lab.ntt.co.jp> <90aeaf38-270a-7e45-6b7d-af2e3d1e3719@lab.ntt.co.jp> Comments: In-reply-to Amit Langote message dated "Fri, 10 May 2019 18:18:32 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20306.1557522309.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 10 May 2019 17:05:09 -0400 Message-ID: <20307.1557522309@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Langote writes: > [ v2 patches ] While this does seem to be fixing real bugs, it's failing to address my point about stable vs. immutable operators. Taking Alan's test case again (and using the v2 patch), consider: regression=3D# explain select * from dataid where id=3D1 and datadatetime = < '2018-01-01'::timestamp; QUERY PLAN = = --------------------------------------------------------------------------= ------------------------------ Bitmap Heap Scan on dataid_default (cost=3D4.18..11.30 rows=3D3 width=3D= 12) Recheck Cond: ((id =3D 1) AND (datadatetime < '2018-01-01 00:00:00'::ti= mestamp without time zone)) -> Bitmap Index Scan on dataid_default_pkey (cost=3D0.00..4.18 rows=3D= 3 width=3D0) Index Cond: ((id =3D 1) AND (datadatetime < '2018-01-01 00:00:00'= ::timestamp without time zone)) (4 rows) That's fine. The given date is older than anything in the dataid_201902 partition, so we can prune. But change it to this: regression=3D# explain select * from dataid where id=3D1 and datadatetime = < '2018-01-01'::timestamptz; QUERY PLAN = = --------------------------------------------------------------------------= ------------------------------ Bitmap Heap Scan on dataid_default (cost=3D4.18..11.30 rows=3D3 width=3D= 12) Recheck Cond: ((id =3D 1) AND (datadatetime < '2018-01-01 00:00:00-05':= :timestamp with time zone)) -> Bitmap Index Scan on dataid_default_pkey (cost=3D0.00..4.18 rows=3D= 3 width=3D0) Index Cond: ((id =3D 1) AND (datadatetime < '2018-01-01 00:00:00-= 05'::timestamp with time zone)) (4 rows) That's not fine. What we have here is a "timestamp < timestamptz" operator, which is only stable, therefore it might give different results at runtime than at plan time. You can't make plan-time pruning decisions with that. What we should have gotten here was an Append node that could do run-time pruning. regards, tom lane