Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eENZn-0000ZY-85 for pgsql-performance@arkaria.postgresql.org; Mon, 13 Nov 2017 22:51:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eENZm-0002bq-Qf for pgsql-performance@arkaria.postgresql.org; Mon, 13 Nov 2017 22:51:34 +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.84_2) (envelope-from ) id 1eENXw-0007lh-Hj for pgsql-performance@postgresql.org; Mon, 13 Nov 2017 22:49:40 +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 1eENXu-000214-1e for pgsql-performance@postgresql.org; Mon, 13 Nov 2017 22:49:39 +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 vADMnXnb004277; Mon, 13 Nov 2017 17:49:33 -0500 From: Tom Lane To: Oliver Mattos cc: Arne Roland , "pgsql-performance@postgresql.org" Subject: Re: Query planner gaining the ability to replanning after start of query execution. In-reply-to: References: <252cab3895894337a3a88275f423fe0b@index.de> Comments: In-reply-to Oliver Mattos message dated "Mon, 13 Nov 2017 21:51:32 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4275.1510613373.1@sss.pgh.pa.us> Date: Mon, 13 Nov 2017 17:49:33 -0500 Message-ID: <4276.1510613373@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Oliver Mattos writes: >> Can you be more elaborate how you'd want to go about it? > ... If another candidate plan is now lower cost, the current plan would be > terminated[1] by setting a flag instructing each execnode to return as > if it had reached the end of the input, although still caching the > node selectivity values, and the new plan started from scratch. Quite aside from the implementation difficulties you'll have, that approach is a show-stopper right there. You can't just restart from scratch, because we may already have shipped rows to the client, or for DML cases already inserted/updated/deleted rows (and even if you could roll those back, we've possibly fired triggers with unpredictable side effects). Queries containing volatile functions are another no-fly zone for this approach. I can't see any way around that without unacceptable performance costs (i.e. buffering all the rows until we're done) or wire-protocol breakage. I think that a more practical way to address the class of problems you're talking about is to teach the planner to have some notion of worst-case as well as expected-case costs, and then incorporate some perhaps-configurable amount of risk aversion in its choices. regards, tom lane PS: please do not top-post, and do not quote the entire darn thread in each message. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance