Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHA8B-00035G-HD for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Oct 2018 16:11:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gHA61-0003Cq-7e for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Oct 2018 16:08:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHA60-0003Cj-L0 for pgsql-hackers@lists.postgresql.org; Mon, 29 Oct 2018 16:08:52 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gHA5r-0005ZV-Mg for pgsql-hackers@postgresql.org; Mon, 29 Oct 2018 16:08:50 +0000 Received: by mail-wr1-x441.google.com with SMTP id d17-v6so9022035wre.11 for ; Mon, 29 Oct 2018 09:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=8JChGxrHNnCwKxR2sUbeB5asQUV/VmmyNoac78ZOhXc=; b=0c0pi9gWhvz8EipyubnWjPKmqgrGUNC4VYc3TVMausq+Fkjfn3nxATaEymtq7DIA7p S9BsK4c4rBbgXY5jbT2TMLig0KSmSCG2Nwe5YTlTz1tObD1X0ta09n8G3gLQP7N5Qvz6 C4gq2FNATH/DZGXZjfjbnNPwxbutdzyREUr5391/mEnKZeVhV7mf6LpImzQvjbXzYVJf MKfNgDtVLt/MgL/D6a6o/8UGDBz9WgtzE2XHnHF4f9ORSzhnGHhojRSAT9JqvxpEEhAj lahQoMDIFjLxoj8USP8xwTlrC5LzVDUxKAlkbgP//RpQ2ZEMHrkiTEuRz+GukqnqUJ5M oQ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8JChGxrHNnCwKxR2sUbeB5asQUV/VmmyNoac78ZOhXc=; b=jhXK7slkPXK6sVCtiQDx5GqqYuB6RVbsWK48iGo0FY31tzJISAp+aooDVPyq2FIsxf joQpOlHgRi7mO+ZbU+xWnBP+kddortHuts5CJ3sHFUG6Tf+8LduIkOcr9OcORBalpepc gcKVmR0N6BA4irt+NhyykNOiuYvB1YmbG7gYiXcuqaJvixwie/i+hDJC/SLAGNQUB6tQ jpbnwFTHXs9foOiWZ1WuhmyTTaVLN0ANTYI7kLLukgCM6MnPiS83CHdJnPis3W0cxfCD CjyqsEUKJGnouPgM+CmLkVtPcmk9dvUKfpUPgo21YmBUS/PDWYlumA6eD9JUNz4Vea62 O6Xw== X-Gm-Message-State: AGRZ1gIEvkjlBp9Ni9FLd9KNu63EqzoTKzTSLSpkR0ljgWfxUg/gtvZG jcyHlg5B59F+kZ1Ddi5UPKxQ0bLt72e5EVwpmdPNwhTIvjjkHM9SlkWpmyQHV9RrrPMy2q2r3wn Lj/Bsxr+vby0zqQntEWyaahGF2LHW1SI+C71NknJBmRRRTDZswiEOLp43fEvGwQy1icMVYW33F5 8DPHjI4cPV68c= X-Google-Smtp-Source: AJdET5cmTJpl8afStddSt35V9HGO1JmNupCey0jBO/T1cu7FCBzGodudYzzzIU6ZfqZuHzkhieB7Ug== X-Received: by 2002:a5d:5245:: with SMTP id p5-v6mr13949499wrv.147.1540829321489; Mon, 29 Oct 2018 09:08:41 -0700 (PDT) Received: from [10.137.2.21] (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id j6-v6sm15793867wmd.29.2018.10.29.09.08.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Oct 2018 09:08:40 -0700 (PDT) Subject: Re: FETCH FIRST clause WITH TIES option To: Andrew Gierth Cc: Surafel Temesgen , PostgreSQL Hackers References: <40c9e6c5-4fc7-1589-0cc5-8a857405b91a@2ndquadrant.com> <87r2g87py9.fsf@news-spur.riddles.org.uk> From: Tomas Vondra Message-ID: <942526de-1854-2bdc-ad17-e276c1efeb1d@2ndquadrant.com> Date: Mon, 29 Oct 2018 17:08:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <87r2g87py9.fsf@news-spur.riddles.org.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10/29/2018 04:17 PM, Andrew Gierth wrote: >>>>>> "Tomas" == Tomas Vondra writes: > > > On 10/26/2018 12:28 PM, Surafel Temesgen wrote: > >> hello , > >> > >> The WITH TIES keyword is sql standard that specifies any peers of > >> retained rows to retained in the result set too .which means > >> according to ordering key the result set can includes additional rows > >> which have ties on the last position, if there are any and It work > >> with ORDER BY query. > > Tomas> Thanks for the patch. I've looked at it today, and it seems > Tomas> mostly OK, with a couple of minor issues. Most of it is code > Tomas> formatting and comment wording issues, so I'm not going to go > Tomas> through them here - see the attached 0002 patch (0001 is your > Tomas> patch, rebased to current master). > > I still think that this is the wrong approach. Implementing WITH TIES > and PERCENT together using an implicit window function call kills two > birds with one very small stone (the only executor change needed would > be teaching LIMIT to be able to stop on a boolean condition), with > maximum reuse of existing facilities. > Hmmm, maybe. How would that work, exactly? Wouldn't that mean extra overhead (the window functions are hardly free) and limitations? Perhaps that was discussed in some other thread in the past? FWIW, I doubt the patch can be much smaller/simpler - a significant part of the new stuff is in gram.y and node read/out infrastructure, the changes to LIMIT node are fairly minimal. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services