pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <david.rowley@2ndquadrant.com>
Cc: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Cc: Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
Cc: Alan Jackson <ajax@tvsquared.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: inconsistent results querying table partitioned by date
Date: Wed, 15 May 2019 20:28:50 -0400
Message-ID: <23372.1557966530@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKJS1f9QP2tDczHDFk=55Jh-wS+bCUWTuBd0uiqg5dfpz6r44g@mail.gmail.com>
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>
	<a0bca4f7-b493-4d0a-8080-8dad3748c5ae@lab.ntt.co.jp>
	<CAKJS1f92Uq+SV+WKKa+B5Fd9PcrwhYFsvxUudm_9F8egi4paXQ@mail.gmail.com>
	<d7878f1f-f7c5-4f23-127e-ced79a64ddf1@lab.ntt.co.jp>
	<CAKJS1f-xHgnr0QVfGtt9BU38kB8a5fp4Y=CYbChV8xSqw6pZ9w@mail.gmail.com>
	<e903adfc-c7a5-58f9-6b7f-16ab6f48be5c@lab.ntt.co.jp>
	<28453.1557867500@sss.pgh.pa.us>
	<CAKJS1f82n-WNsu6G5WNXGFV4MsnosydiouRvTNnZYmQz0tciuQ@mail.gmail.com>
	<588f56cb-aaed-14b0-8a21-13486bd1c706@lab.ntt.co.jp>
	<CAKJS1f-QVbr-9-m+=b6mxWxaJYzdK554uptnNyV5M6AhkUMcdg@mail.gmail.com>
	<CAKJS1f-ABcw68AH7tRRRmBTEwhd-Y_Lm8HpfydWw6aPS8G715A@mail.gmail.com>
	<10502.1557941878@sss.pgh.pa.us>
	<CAKJS1f9QP2tDczHDFk=55Jh-wS+bCUWTuBd0uiqg5dfpz6r44g@mail.gmail.com>

David Rowley <david.rowley@2ndquadrant.com> writes:
> Thinking about this more, if we're now making it so a forplanner =
> true set of steps requires all values being compared to the partition
> key to be Const, then anything that's not Const must require run-time
> pruning. That means the:

> else if (func_volatile(fnoid) != PROVOLATILE_IMMUTABLE)

> in analyze_partkey_exprs() can simply become "else".

Um ... what about a merely-stable comparison operator with a Const?

> I think it would be nicer if we made match_clause_to_partition_key()
> do everything that analyze_partkey_exprs() currently does, but if we
> change that "else if" to just "else" then the only advantage is not
> having to make another pass over the pruning steps.  We'd have to make
> it so match_clause_to_partition_key() did all the pull_exec_paramids()
> stuff and add some new fields to PartitionPruneStepOp to store that
> info.  We'd also need to store hasexecparam in the
> PartitionPruneStepOp and change the signature of
> partkey_datum_from_expr() so we could pass that down as we'd no longer
> have context->exprhasexecparam... Well, we could keep that, but if
> we're trying to not loop over the steps again then we'll need to store
> that value in the step when it's created rather than put it in
> PartitionPruneContext.

The loop over steps, per se, isn't that expensive --- but extra syscache
lookups are.  Or at least that's my gut feeling about it.  If we just had
match_clause_to_partition_key mark the steps as being plan-time executable
or not, we could avoid the repeat lookup.

>> * Teach match_clause_to_partition_key to not emit plan-time-usable
>> quals at all if it is called with forplanner = false, or

> That's not really possible.  Imagine a table partitioned by HASH(a,b)
> and WHERE a = $1 and b = 10;  we can't do any pruning during planning
> here, and if we only generate steps containing "a = $1" for run-time,
> then we can't do anything there either.

That's an interesting example, but how does it work now?  I did not
observe any code in there that seems to be aware of cross-dependencies
between steps.  Presumably somewhere we are combining those hash quals,
so couldn't we mark the combined step properly?

>> Perhaps this implies too much code churn/restructuring to be reasonable
>> to consider right now, but I thought I'd ask.  It sure seems like this
>> work is being done in a pretty inefficient and duplicative way.

> I certainly think the above would be cleaner and I don't mind working
> on it, but if it's too much churn for this time of year then I'd
> rather not waste time writing a patch that's going to get rejected.

Yeah, I'm leery of adding much new complexity right now, but maybe
adding a flag field to save a syscache lookup wouldn't be out of line.

			regards, tom lane





view thread (41+ messages)  latest in thread

Message-ID: <23372.1557966530@sss.pgh.pa.us>
Permalink:  ../23372.1557966530@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23372.1557966530@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, david.rowley@2ndquadrant.com, 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: <23372.1557966530@sss.pgh.pa.us>
  References: <FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com> <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> <a0bca4f7-b493-4d0a-8080-8dad3748c5ae@lab.ntt.co.jp> <CAKJS1f92Uq+SV+WKKa+B5Fd9PcrwhYFsvxUudm_9F8egi4paXQ@mail.gmail.com> <d7878f1f-f7c5-4f23-127e-ced79a64ddf1@lab.ntt.co.jp> <CAKJS1f-xHgnr0QVfGtt9BU38kB8a5fp4Y=CYbChV8xSqw6pZ9w@mail.gmail.com> <e903adfc-c7a5-58f9-6b7f-16ab6f48be5c@lab.ntt.co.jp> <28453.1557867500@sss.pgh.pa.us> <CAKJS1f82n-WNsu6G5WNXGFV4MsnosydiouRvTNnZYmQz0tciuQ@mail.gmail.com> <588f56cb-aaed-14b0-8a21-13486bd1c706@lab.ntt.co.jp> <CAKJS1f-QVbr-9-m+=b6mxWxaJYzdK554uptnNyV5M6AhkUMcdg@mail.gmail.com> <CAKJS1f-ABcw68AH7tRRRmBTEwhd-Y_Lm8HpfydWw6aPS8G715A@mail.gmail.com> <10502.1557941878@sss.pgh.pa.us> <CAKJS1f9QP2tDczHDFk=55Jh-wS+bCUWTuBd0uiqg5dfpz6r44g@mail.gmail.com> <23372.1557966530@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