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 1hBlAJ-0005fg-5k for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Apr 2019 19:03:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hBlAH-00062o-RS for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Apr 2019 19:03:13 +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 1hBlAH-00062Z-Bg for pgsql-hackers@lists.postgresql.org; Wed, 03 Apr 2019 19:03:13 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBlAE-0000W9-DM for pgsql-hackers@postgresql.org; Wed, 03 Apr 2019 19:03:12 +0000 Received: by mail-wr1-x433.google.com with SMTP id t17so199576wrw.13 for ; Wed, 03 Apr 2019 12:03:10 -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=AMr35woBuOjjkV6TD9LvBZ7DjeqvmcuzLt+HlXU+TXQ=; b=s5Py3Jc4EFDh/USp12Uj5kCV0398AXFaH3Ny+7k0bXkOWKvOlldyGGwN0aofOlqbry TRbQLomRc/o0wLYEj4W1W+cFhtPH5K/OiY55CYKX8UJsE2q9Lk+3M7oKf01dsCu3ePLR yAS+bUBq1pgLMunIlykptUy6X0KCvn9gtgy1tJwJ/fhC79RyTPOaNFIy7k/onZDIBVom MLYatY8V810J0mNSesMfVXCp4ir0N7cplpIkUFmz0Djyugom0RnNIPgeFq+pPeYZPHn5 AHzXyN1h0bVbXE99lOiy4AIFugcbb7Bwlr750Eeq+t7ex275mLpiPyOakOyBSnnULA/Q MonA== 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=AMr35woBuOjjkV6TD9LvBZ7DjeqvmcuzLt+HlXU+TXQ=; b=rZGc5bkhsTsb5Tub4mJ/ecn3ZjTBv0z/Nd3OEkd83V6A84QLWhgh1h0oswGRJ6ApvR lhKREnEajqZs1Z0QYpANw9N/3ix9AO7wxUgjWCZ4zrv+6R9o4+tpf0L6wiV62Q2W1/kj iuumgM6l/+lN0teYubI4/7z0b9ri6fHofQYgkZ5KMWJolg86IsyjR47rsj9QGf4W3z3m b2kibF3U9NMwI/siCgMKV3eLo9utcDRAT8oIXZztW7cXKs18QnzRRZBtOYKPVB2qoi/4 0fEa6xlVoI9jXh55kJCHNyd6JPqIlGCt1K2AaeiD88HdxQzYMtTbpFJcAdnmYMIle9M2 W0EA== X-Gm-Message-State: APjAAAXIJx2PZNexRCwZell4M3n2MFxwZ8sAyJFTadqrhzoFzpH7ujFm wLh/nr0gtDcyexg0yMjrVNSUUg== X-Google-Smtp-Source: APXvYqynJ4hYsG0xIU60hBDMwSRMDrTn8HMC6BxJlhzcJ3/ZGOrB3hIOa2Tc2T8xT6r5JOZQ0LztZg== X-Received: by 2002:adf:f309:: with SMTP id i9mr850849wro.258.1554318187170; Wed, 03 Apr 2019 12:03:07 -0700 (PDT) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id b204sm30467398wmh.29.2019.04.03.12.02.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Apr 2019 12:02:59 -0700 (PDT) Date: Wed, 3 Apr 2019 21:02:57 +0200 From: Tomas Vondra To: Surafel Temesgen Cc: David Steele , Michael Paquier , Robert Haas , andrew@tao11.riddles.org.uk, PostgreSQL Hackers Subject: Re: FETCH FIRST clause WITH TIES option Message-ID: <20190403190257.44fxttkpo4yopp3l@development> References: <20190204052857.GP29064@paquier.xyz> <20190329005648.GA1136@development> <20190331001446.GA10804@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-1432-ae87f8 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, Unfortunately this got broken again, this time by aef65db676 :-( I've tried to fix the merge conflict (essentially by moving some of the code to adjust_limit_rows_costs(), but I'm wondering if the code added to create_limit_path is actually correct if (count_est != 0) { double count_rows; if (count_est > 0) count_rows = (double) count_est; else count_rows = clamp_row_est(subpath->rows * 0.10); if (limitOption == WITH_TIES) { ... count_rows = Max(avgGroupSize, count_est + (...)); } ... } Firstly, this seriously needs some comment explaining why we do this. But more importantly - shouldn't it really be count_rows = Max(avgGroupSize, count_rows + (...)); instead of using count_est again (which might easily be -1 anyway)? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services