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 1iaL6V-00021r-0I for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Nov 2019 14:49: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 1iaL6T-00078j-O0 for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Nov 2019 14:49:09 +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 1iaL6T-000784-BY for pgsql-hackers@lists.postgresql.org; Thu, 28 Nov 2019 14:49:09 +0000 Received: from mail-qv1-xf41.google.com ([2607:f8b0:4864:20::f41]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iaL6Q-00011e-Ps for pgsql-hackers@postgresql.org; Thu, 28 Nov 2019 14:49:08 +0000 Received: by mail-qv1-xf41.google.com with SMTP id i3so10417168qvv.7 for ; Thu, 28 Nov 2019 06:49:06 -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:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=XzOTuFuFQop/I5nx142iuB1Ajsta5JWAZBfaPOQb2IQ=; b=MBgnh4nK//WKFI4Yie5F4ibGKdrESPeZjIxHdG71lqdYprlDSx5F/Mcr1Rd53Edk/1 3C3EvHmyQqQi9Z9Q9SWMoMuFklvGdWTxaFOAUQ/YxwOU0MxfH7XbNg9fyvHgflTu6xo3 BCx0SogOByvn+d3frGf6tIlnCPjjnlAtEeGS4faH4tEu3XJBYvCQmxqsF+04LmWJFG5p Boa85UICygebir7NqSZNvYUee2VJP1OVnZaivhqwGoT7yXrMxYd6IENeY+Y9NWckZKW5 bbW4jBOuUN/+Yz/KdtEQyQGBomPfHdE15JcdFlYy7Gd9W0pUSidBIKPg5GDF6zH+m5++ T9Jw== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=XzOTuFuFQop/I5nx142iuB1Ajsta5JWAZBfaPOQb2IQ=; b=AlZH5wFGBJ2EOGHsWP2ycKMVO8fkaR2RmOUt/qRJJZUPabN1Sl9oXquyp/hVJZasuv vovhohQ35wkhDtEB1PCaxitRAafeROJTAiOgY2cOGdIuS4mFu0lo5OmDQxRKNmDkK8AK W1x75iCZYrhjDcbVJ9i8GSiMJOmkeRGlcLsNBd1srdAugzGLhZu43DOVLt3hwzGCSALv K0CZuMQejqXXFt7fsqtrCeF7JqbNYKyVDwXZE6jGFybXTJIykBK8waLOLcBUsrdWuh5X USUFt0BTIeokHSu+mkIzg1qzxyoic/p8q/IPuj7g1/HJLjLvvVmgGrapmx6eauDQEuQ+ LeUw== X-Gm-Message-State: APjAAAVQVwRJHsfZxp/rjTFqITz8wLDWzjS8M21JeRT0G+GpQfWDEAYl IBGfGUSIT237iczQBnEz92ryjQ== X-Google-Smtp-Source: APXvYqxaY/vGm7PHM6IzTciBsSFu6e9VQ/URTX9pU9FP96/992Md+A+0PhFXecsQW+B/mB0Zgo/3KA== X-Received: by 2002:a0c:b88f:: with SMTP id y15mr11334228qvf.161.1574952545980; Thu, 28 Nov 2019 06:49:05 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([179.56.96.77]) by smtp.gmail.com with ESMTPSA id n18sm9464222qtl.40.2019.11.28.06.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 06:49:05 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 599F8300663; Thu, 28 Nov 2019 11:49:03 -0300 (-03) Date: Thu, 28 Nov 2019 11:49:03 -0300 From: Alvaro Herrera To: Surafel Temesgen Cc: Tomas Vondra , PostgreSQL Hackers , Andrew Gierth Subject: Re: FETCH FIRST clause WITH TIES option Message-ID: <20191128144903.GA30772@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Nov-28, Surafel Temesgen wrote: > On Thu, Nov 28, 2019 at 12:36 AM Alvaro Herrera > wrote: > > > I think you should add a /* fall-though */ comment after changing state. > > Like this (this flow seems clearer; also DRY): > > > > if (!node->noCount && > > node->position - node->offset >= node->count) > > { > > if (node->limitOption == LIMIT_OPTION_COUNT) > > { > > node->lstate = LIMIT_WINDOWEND; > > return NULL; > > } > > else > > { > > node->lstate = LIMIT_WINDOWEND_TIES; > > /* fall-through */ > > } > > } > > else > > ... > > changed But you did not read my code snippet, did you ...? > > I think you need to stare a that thing a little harder. > > This is because the new state didn't know about backward scan > and there was off by one error it scan one position past to detect > ties. The attached patch fix both Oh, thanks, glad it was that easy. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services