Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwXX6-0003qB-Mz for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Sep 2018 18:55:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fwXX3-0006WG-PJ for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Sep 2018 18:55:33 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwXX3-0006W9-Fu for pgsql-bugs@lists.postgresql.org; Sun, 02 Sep 2018 18:55:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwXWw-00066g-LR for pgsql-bugs@lists.postgresql.org; Sun, 02 Sep 2018 18:55:32 +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 w82ItKrj015720; Sun, 2 Sep 2018 14:55:20 -0400 From: Tom Lane To: Amit Kapila cc: Stephen Frost , Marko Tiikkaja , Andres Freund , Andrew Fletcher , PostgreSQL mailing lists Subject: Re: BUG #15324: Non-deterministic behaviour from parallelised sub-query In-reply-to: References: <21038.1534181205@sss.pgh.pa.us> <390.1534261450@sss.pgh.pa.us> <20180815111006.GB3326@tamriel.snowman.net> <19350.1534771766@sss.pgh.pa.us> Comments: In-reply-to Amit Kapila message dated "Sun, 02 Sep 2018 10:21:30 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <15718.1535914520.1@sss.pgh.pa.us> Date: Sun, 02 Sep 2018 14:55:20 -0400 Message-ID: <15719.1535914520@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Kapila writes: > Tom, do you have input on this? Is it okay to backpatch this fix? Well, >> + * Treat window functions as parallel-restricted as the row ordering >> + * induced by them is non-deterministic. We can relax this condition for >> + * cases where the row ordering can be deterministic like when there is >> + * an ORDER BY on the primary key, but those cases don't seem to be >> + * interesting enough to have additional checks. This comment seems fairly confused. I'd say something like * Treat window functions as parallel-restricted because we aren't sure * whether the input row ordering is fully deterministic, and the output * of window functions might vary across workers if not. (In some cases, * like where the window frame orders by a primary key, we could relax * this restriction. But it doesn't currently seem worth expending extra * effort to do so.) >> In addition to the above, I have marked all built-in window functions >> as parallel-restricted. I think even if we don't do that something >> like above check should be sufficient, but OTOH, I don't see any >> reason to keep the marking of such functions as parallel-safe. Is >> there a reason, why we shouldn't mark them as parallel-restricted? I am *strongly* against this. It's unnecessary catalog churn that we might need to undo someday, and it confuses a property of the window function infrastructure with a property of individual window functions. As a counterexample, if a window function were parallel-unsafe for some reason, we'd surely need to honor that. More realistically, someone might add a window function that actually needs to be parallel-restricted for reasons of its own, but then there would be no obvious distinction between such a function and one that you'd hacked up to be marked parallel-restricted even though it's safe in itself. If we then do make the sort of optimization suggested in the comment, it's likely that someone would just s/r/s/g for all the window functions and thereby break such a function. Better to retain the correct per-function markings. regards, tom lane