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 1hR4Hc-000480-5q for pgsql-bugs@arkaria.postgresql.org; Thu, 16 May 2019 00:30:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hR4Gb-00033y-TB for pgsql-bugs@arkaria.postgresql.org; Thu, 16 May 2019 00:29:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hR4Gb-00033r-LT for pgsql-bugs@lists.postgresql.org; Thu, 16 May 2019 00:29:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hR4GY-0007B2-5z for pgsql-bugs@lists.postgresql.org; Thu, 16 May 2019 00:29:00 +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 x4G0SopI023373; Wed, 15 May 2019 20:28:50 -0400 From: Tom Lane To: David Rowley cc: Amit Langote , Kyotaro HORIGUCHI , Alan Jackson , PostgreSQL mailing lists Subject: Re: inconsistent results querying table partitioned by date In-reply-to: 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> <20307.1557522309@sss.pgh.pa.us> <28453.1557867500@sss.pgh.pa.us> <588f56cb-aaed-14b0-8a21-13486bd1c706@lab.ntt.co.jp> <10502.1557941878@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Thu, 16 May 2019 11:53:18 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23371.1557966530.1@sss.pgh.pa.us> Date: Wed, 15 May 2019 20:28:50 -0400 Message-ID: <23372.1557966530@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David Rowley 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