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 1hfVNq-0003wB-TH for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jun 2019 20:16:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfVNp-0007b5-Mx for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jun 2019 20:16:09 +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 1hfVNp-0007ay-AN for pgsql-hackers@lists.postgresql.org; Mon, 24 Jun 2019 20:16:09 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfVNl-0006Nk-RV for pgsql-hackers@lists.postgresql.org; Mon, 24 Jun 2019 20:16:08 +0000 Received: by mail-wm1-x343.google.com with SMTP id x15so568535wmj.3 for ; Mon, 24 Jun 2019 13:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=fir+jyqU3suCs6vJl2nRVp5L40wXGbLXHkka/kx+Jlc=; b=kYm1zSaRkObwzLl26OXHwynWYPwv9oNb76d283NsBpd+0DBv+xwIMUYXwMawBpeTGl mKmsPXyNfu6i7e7hZLqzWTJs5mS34J2mcPh508xxqdpO9rnv3B0Z1zS1Lle0bMnXJid7 gew2MH1ZIBx9Yej5coTirq/Tq4zXpU+nzqoE6RewT5WoKc3+kt/Cl0EzgoQUqR1vjuWm 6DIxluNYkSz5Zwtg5efZ7H43eYWeE4cBuime3lzMHAwvbttnAgxir4LdVbYKZQ06A2Wo Rp4iMq48X4QGCphMaIaTGCnWn31JPhDDmtQrHBUP2TcEshW1gAJ9HcRLq9phnWyvUSyn r1Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=fir+jyqU3suCs6vJl2nRVp5L40wXGbLXHkka/kx+Jlc=; b=TXsNbfD/M7ttPmw18d1rcL7QDCwWPwaodLu2nzqIz6/iDAjYdcVZCkUJ78fHCDW/RU QG1acHJfHAUTy3sm5eLzRlNoIIrMwVHBSvRoiH1IAl3Hoz2wt4+27tzRsTWCjyii/B04 3aVFsnrtqODJ8uVLdpmqFyV+lzsf1Mxh8FjLFCQd7Ebsd1uB6odg3gMxBD6KQ9yPJWcX 3UbsFshUoMwOdKPxUnAAlUccUt3bVfltb4mHZfNpXLEkKtYWgH5mxL+6HKnGl7qt1PLR vDoPmpO05cvCzIMkRAZW0GCbARS8Nc0QXyZ/AzCCm34u/Rau2XJvZ8xIF+yEbp765+Lk Ueqw== X-Gm-Message-State: APjAAAWR0LQ0cf5riigdCykFz3qW+T9iFRrndgJvUeWOsmj3tzgRoWyC RmAvrobnKCbajAWCrnTAOfUT3A== X-Google-Smtp-Source: APXvYqwCZG+/m80ydar9DocJxaj7bq2NAZUWMDAOC3R+EayLZhnvl5B/WvtydDpYNzwnFLV+iq96Xg== X-Received: by 2002:a7b:c40c:: with SMTP id k12mr15920805wmi.122.1561407364352; Mon, 24 Jun 2019 13:16:04 -0700 (PDT) Received: from localhost (ip-86-49-253-160.net.upcbroadband.cz. [86.49.253.160]) by smtp.gmail.com with ESMTPSA id e11sm28291760wrc.9.2019.06.24.13.16.03 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 13:16:03 -0700 (PDT) Date: Mon, 24 Jun 2019 22:16:01 +0200 From: Tomas Vondra To: James Coleman Cc: Simon Riggs , Rafia Sabih , Shaun Thomas , Dmitry Dolgov <9erthalion6@gmail.com>, Alexander Korotkov , Tom Lane , PostgreSQL Developers Subject: Re: [PATCH] Incremental sort (was: PoC: Partial sort) Message-ID: <20190624201601.iqy3ddig72l5lvbz@development> References: <20190602211753.rxor4apm7zfiltt3@development> <20190614181135.tdj7aq4iffy5ghl2@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Jun 24, 2019 at 01:00:50PM -0400, James Coleman wrote: >On Mon, Jun 24, 2019 at 12:56 PM Simon Riggs wrote: >> >> On Mon, 24 Jun 2019 at 16:10, James Coleman wrote: >>> >>> On Thu, Jun 13, 2019 at 11:38:12PM -0400, James Coleman wrote: >>> >I think the first thing to do is get some concrete numbers on performance if we: >>> > >>> >1. Only sort one group at a time. >>> >2. Update the costing to prefer traditional sort unless we have very >>> >high confidence we'll win with incremental sort. >>> > >>> >It'd be nice not to have to add additional complexity if at all possible. >>> >>> I've been focusing my efforts so far on seeing how much we can >>> eliminate performance penalties (relative to traditional sort). It >>> seems that if we can improve things enough there that we'd limit the >>> amount of adjustment needed to costing -- we'd still need to consider >>> cases where the lower startup cost results in picking significantly >>> different plans in a broad sense (presumably due to lower startup cost >>> and the ability to short circuit on a limit). But I'm hopeful then we >>> might be able to avoid having to consult MCV lists (and we wouldn't >>> have that available in all cases anyway) >>> >>> As I see it the two most significant concerning cases right now are: >>> 1. Very large batches (in particular where the batch is effectively >>> all of the matching rows such that we're really just doing a standard >>> sort). >>> 2. Many very small batches. >> >> >> What is the specific use case for this? This sounds quite general case. > >They are both general cases in some sense, but the concerns lie mostly >with what happens when they're unexpectedly encountered. For example, >if the expected row count or group size is off by a good bit and we >effectively have to perform a sort of all (or most) possible rows. > >If we can get the performance to a point where that misestimated row >count or group size doesn't much matter, then ISTM including the patch >becomes a much more obvious total win. > Yes, that seems like a reasonable approach. Essentially, we're trying to construct plausible worst case examples, and then minimize the overhead compared to regular sort. If we get sufficiently close, then it's fine to rely on somewhat shaky stats - like group size estimates. >> Do we know something about the nearly-sorted rows that could help us? >> Or could we introduce some information elsewhere that would help with >> the sort? >> >> Could we for-example, pre-sort the rows block by block, or filter out >> the rows that are clearly out of order, so we can re-merge them >> later? > >I'm not sure what you mean by "block by block"? > I'm not sure what "block by block" means either. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services