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 1gIANN-0004mz-Du for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Nov 2018 10:38:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gIANK-0002A5-QT for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Nov 2018 10:38:54 +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 1gIANK-00029x-Fe for pgsql-hackers@lists.postgresql.org; Thu, 01 Nov 2018 10:38:54 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gIANH-0002fF-CX for pgsql-hackers@postgresql.org; Thu, 01 Nov 2018 10:38:53 +0000 Received: by mail-wm1-x335.google.com with SMTP id a8-v6so925742wmf.1 for ; Thu, 01 Nov 2018 03:38:51 -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=p5e7MN2UcE+UzWrJliuyRy5K5KgCY3sZ3Ud4yKSuJ9k=; b=h88NyIx1fVFh7THn2ocHWvnsR2OfLAujGYCEQTxFlkqiKXKNSj2grYc7rrACb6Gsgl nQNyaRdvxGr38I/fx2phV3rq3m0/eHJbQOiHsl15vSV1GKgafj4Z/JNEuQnUQ2yVh183 mXquLsagouyPEAiAFa3cLhsW/TDG2Yc2bbd+Ov1DVjWT/a6bA9W1PXx+Khg3IrLSaijk W5WhrPSeqMVcXhemIKKvDpsH+A63uE8X0uMWiCgEPCO4ZE+OkcjD5z7lIZbmtuhMv7zS pOln70FM+W3hFmJmdVcFrUN91TYL8vKMvc9+SwtnZERDVgcn1hKTwoCa7u1EUZIcPghk 283g== 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=p5e7MN2UcE+UzWrJliuyRy5K5KgCY3sZ3Ud4yKSuJ9k=; b=hIOJtNwyUQOiAqndH8OGUB1DZpi/dBesAD0IlQC/H3cr01SMWJd1gwj4uAbDwq92c9 gWtfrrozrE1ZBc7ujNvAorH3BapbbJQGW8/icXpoab2hUJUIGy5Wi/M6xG24H4FPup6g Sz90PpoUAHcP3/IIbpwv9Ip5TZKbeNk6eZKw95GIotGQdMYsSteIsGivlk0auwJTI+EE Z84BLWY7K5Q4l2DUAAeCmf0ZruZqIUGy+3ySj6Av+WC/5io0GYAjvct5IFcuvIWSkqmo K835NtclR5hvJgCrf1St20MuTMShKg55mZ4iEugfMuDvTwcl8/UPdtx2NT+6fO/LM1JM z5xQ== X-Gm-Message-State: AGRZ1gKhu1KOSsMh78LePDA/bqvHAP7+r/Wd3GBQncAbkG3Uv2Kd/+Vn hCDUpv5hdNL5bHTIqLJOLJZX4mB+E41xgSDydIG6T0VwD+o2F9c4/VgSprxZRS6An4M1SdQ1zWy HIOJWXYCFauVv5U6ZdyWDTuup6jE4bQnbwbEFCG9miL0ax/DltavmsbIVLqD7/xdXTCz5TIqtpi /cvhq+mac7UoI= X-Google-Smtp-Source: AJdET5dK2RH0rIOCRu2kUcmr8nGJR+/WHuGBeaZ5qF9loVRcfkSBcyPBFuHiY7hA9kCFtV446fR1fA== X-Received: by 2002:a1c:dc42:: with SMTP id t63-v6mr5282163wmg.17.1541068728948; Thu, 01 Nov 2018 03:38:48 -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 f67-v6sm12657027wme.22.2018.11.01.03.38.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Nov 2018 03:38:48 -0700 (PDT) Subject: Re: FETCH FIRST clause WITH TIES option To: Robert Haas , Andrew Gierth Cc: Surafel Temsgen , "pgsql-hackers@postgresql.org" References: <40c9e6c5-4fc7-1589-0cc5-8a857405b91a@2ndquadrant.com> <87r2g87py9.fsf@news-spur.riddles.org.uk> <942526de-1854-2bdc-ad17-e276c1efeb1d@2ndquadrant.com> <87muqw7luv.fsf@news-spur.riddles.org.uk> From: Tomas Vondra Message-ID: <65ecc991-97aa-50a2-7131-10c8b3991c8c@2ndquadrant.com> Date: Thu, 1 Nov 2018 11:38:46 +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: 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/31/2018 06:17 PM, Robert Haas wrote: > On Mon, Oct 29, 2018 at 12:48 PM Andrew Gierth > wrote: >> Then FETCH FIRST N WITH TIES becomes "stop when the expression >> rank() over (order by ...) <= N >> is no longer true" (where the ... is the existing top level order by) > > Wouldn't that be wicked expensive compared to something hard-coded > that does the same thing? > Not sure, but that was one of my concerns too, particularly for the simple FETCH FIRST N WITH TIES case. But I think Andrew has a point it would make it much easier to implement the PERCENT case. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services