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 1io81q-0001dh-D0 for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jan 2020 15:41:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1io81p-0007XU-1g for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jan 2020 15:41:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1io81o-0007XN-Le for pgsql-hackers@lists.postgresql.org; Sun, 05 Jan 2020 15:41:20 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1io81l-0004Ro-0V for pgsql-hackers@postgresql.org; Sun, 05 Jan 2020 15:41:19 +0000 Received: by mail-wm1-x341.google.com with SMTP id c127so10270642wme.1 for ; Sun, 05 Jan 2020 07:41:16 -0800 (PST) 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; bh=021rk23l0weajpvYwfiuxBLqPuAcqRjSkRbvvP1K19Y=; b=ewVI7FZ1D8MLk374g9OZdGtCXq3QE9R3ZSbuWq1yPaztIgMDJBlIlGD6AAAW7vs98P HL9hwdc38rpRWlVeky/DvXlS2XHO3adgSJ3tvDAxG773MJAxo5lF5HudBxazXoCEKhMR 0PqJ/TRTkMrN/YaDsY9sUin7AoWRY0/U7n7KDtCwSTG8rVGhOROMV8LtYnnf1oR+2l4U omME0eHVH+zAv1q4XRwHM8NK+Xh6UllLqd0xXpJCWpIH4IyWUpoSo8vitp33f+Klnir+ bZs/7JoIU6d5WzYx2QEY5Meha4lvp0U+mAbRCiIV/jm2G63wkdopy4fZb3KMPYTaiKGv DP9w== 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; bh=021rk23l0weajpvYwfiuxBLqPuAcqRjSkRbvvP1K19Y=; b=obpjFJqbQmEH2VZq6hCRoNyikwROOrwQBf2xufz0SvDCaXyyDk5+nKY7lXUBdZn/Wx PEXLEkvptyeSfIGucy22hUttTTpQnAmQJI33jOQu8oqd/w9fdo1MNrNCbMxibxEl1YJw /6wS+cqc0+UpsTzyZ58hIp6W6NXAHGwRA1Wit1lbZMdpuj/6In8ey4uwvhOEcUGraeU+ K6UdgMMI1gZEHETyQxS34DWvnFSv3F8TkmBrabLzoSkzIYrTgVRmxYjtYr5KTwALp8/R pIxuB3WU3m9+/Vm2xIQuAhBlDluzuxMuPc2eSF9tdLarViR1MPP/ozUsm0cfnngoysPb ja4w== X-Gm-Message-State: APjAAAVeYZFSRxBLPCMA+Afqy62blliFwVLtD8RgDH+/Z6/vos00Dr02 Bh+1Dzs3Q59r3U0ZPh2rbD9rag== X-Google-Smtp-Source: APXvYqylETU0hqOel88cVfZ02ZvnGCruobsXbr6fnc147BEZRisOlw/GU9W/awLdnFyy8n7h3BxkyA== X-Received: by 2002:a1c:f31a:: with SMTP id q26mr29769200wmq.142.1578238875481; Sun, 05 Jan 2020 07:41:15 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id w17sm70689494wrt.89.2020.01.05.07.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2020 07:41:14 -0800 (PST) Date: Sun, 5 Jan 2020 16:41:13 +0100 From: Tomas Vondra To: Andrew Gierth Cc: Alvaro Herrera , Surafel Temesgen , PostgreSQL Hackers Subject: Re: FETCH FIRST clause WITH TIES option Message-ID: <20200105154113.l3mejzem3k663l4v@development> References: <20191111145649.GA7829@alvherre.pgsql> <87sgm7z2z7.fsf@news-spur.riddles.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <87sgm7z2z7.fsf@news-spur.riddles.org.uk> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Nov 29, 2019 at 05:19:00AM +0000, Andrew Gierth wrote: >>>>>> "Alvaro" == Alvaro Herrera writes: > > Alvaro> First, I noticed that there's a significant unanswered issue > Alvaro> from Andrew Gierth about this using a completely different > Alvaro> mechanism, namely an implicit window function. Robert was > Alvaro> concerned about the performance of Andrew's proposed approach, > Alvaro> but I don't see any reply from Surafel on the whole issue. > > Alvaro> Andrew: Would you rather not have this feature in this form at > Alvaro> all? > >I have done a proof-of-concept hack for my alternative approach, which I >will post in another thread so as not to confuse the cfbot. > >The main advantage, as I see it, of a window function approach is that >it can also work for PERCENT with only a change to the generated >expression; the executor part of the code can handle any stopping >condition. It can also be generalized (though the POC does not do this) >to allow an SQL-level extension, something like "LIMIT WHEN condition" >to indicate that it should stop just before the first row for which the >condition is true. Whether this is a desirable feature or not is another >question. > For the record, the alternative approach was posted here: https://www.postgresql.org/message-id/flat/87o8wvz253.fsf@news-spur.riddles.org.uk I think we need to make a decision about which road to take - shall we continue with what Surafel originally proposed, or should we instead adopt Andrew's patch? Andrew's patch looks significantly simpler, although it probably will need more work to get it committable. My main concern about using window functions was performance, so I think we should benchmark. For example, considering window functions are not parallel safe, would this have negative impact on parallel queries? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services