pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Cc: Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
Cc: ajax@tvsquared.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: inconsistent results querying table partitioned by date
Date: Fri, 10 May 2019 17:05:09 -0400
Message-ID: <20307.1557522309@sss.pgh.pa.us> (raw)
In-Reply-To: <90aeaf38-270a-7e45-6b7d-af2e3d1e3719@lab.ntt.co.jp>
References: <FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com>
	<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>

Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> 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=# explain select * from dataid where id=1 and datadatetime < '2018-01-01'::timestamp;
                                               QUERY PLAN                                               
--------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on dataid_default  (cost=4.18..11.30 rows=3 width=12)
   Recheck Cond: ((id = 1) AND (datadatetime < '2018-01-01 00:00:00'::timestamp without time zone))
   ->  Bitmap Index Scan on dataid_default_pkey  (cost=0.00..4.18 rows=3 width=0)
         Index Cond: ((id = 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=# explain select * from dataid where id=1 and datadatetime < '2018-01-01'::timestamptz;
                                               QUERY PLAN                                               
--------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on dataid_default  (cost=4.18..11.30 rows=3 width=12)
   Recheck Cond: ((id = 1) AND (datadatetime < '2018-01-01 00:00:00-05'::timestamp with time zone))
   ->  Bitmap Index Scan on dataid_default_pkey  (cost=0.00..4.18 rows=3 width=0)
         Index Cond: ((id = 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





view thread (41+ messages)  latest in thread

Message-ID: <20307.1557522309@sss.pgh.pa.us>
Permalink:  ../20307.1557522309@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20307.1557522309@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Langote_Amit_f8@lab.ntt.co.jp, horiguchi.kyotaro@lab.ntt.co.jp, ajax@tvsquared.com
  Subject: Re: inconsistent results querying table partitioned by date
  In-Reply-To: <20307.1557522309@sss.pgh.pa.us>
  References: <FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com> <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> <20307.1557522309@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox