Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eYaUy-0003Bf-Oy for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2018 16:42:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eYaUx-0000pU-LA for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2018 16:42:07 +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 1eYaUx-0000pK-B2 for pgsql-hackers@lists.postgresql.org; Mon, 08 Jan 2018 16:42:07 +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 1eYaUu-0004DR-WC for pgsql-hackers@postgresql.org; Mon, 08 Jan 2018 16:42:06 +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 w08Gg205002172; Mon, 8 Jan 2018 11:42:02 -0500 From: Tom Lane To: Jim Finnerty cc: pgsql-hackers@postgresql.org Subject: Re: Parallel append plan instability/randomness In-reply-to: <1515428895102-0.post@n3.nabble.com> References: <7752.1515284083@sss.pgh.pa.us> <7400.1515390981@sss.pgh.pa.us> <1515428895102-0.post@n3.nabble.com> Comments: In-reply-to Jim Finnerty message dated "Mon, 08 Jan 2018 09:28:15 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2170.1515429722.1@sss.pgh.pa.us> Date: Mon, 08 Jan 2018 11:42:02 -0500 Message-ID: <2171.1515429722@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jim Finnerty writes: > Ordering the plan output elements by estimated cost will cause spurious plan > changes to be reported after table cardinalities change. Can we choose an > explain output order that is stable to changes in cardinality, please? I found the code that's doing this, in create_append_path, and it says: * For parallel append, non-partial paths are sorted by descending total * costs. That way, the total time to finish all non-partial paths is * minimized. Also, the partial paths are sorted by descending startup * costs. There may be some paths that require to do startup work by a * single worker. In such case, it's better for workers to choose the * expensive ones first, whereas the leader should choose the cheapest * startup plan. There's some merit in that argument, although I'm not sure how much. It's certainly pointless to sort that way if the expected number of workers is >= the number of subpaths. More generally, I wonder if it wouldn't be better to implement this behavior at runtime rather than plan time. Something along the line of "workers choose the highest-cost remaining subplan, but leader chooses the lowest-cost one". regards, tom lane