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 1f8LpZ-0001VD-VZ for pgsql-general@arkaria.postgresql.org; Tue, 17 Apr 2018 08:19:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f8LpY-0003M4-JP for pgsql-general@arkaria.postgresql.org; Tue, 17 Apr 2018 08:19:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f8LpY-0003Ls-BW for pgsql-general@lists.postgresql.org; Tue, 17 Apr 2018 08:19:12 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f8LpW-0006GZ-4R for pgsql-general@postgresql.org; Tue, 17 Apr 2018 08:19:11 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 4BF4A41047; Tue, 17 Apr 2018 10:19:08 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id yAJPng0drXOv; Tue, 17 Apr 2018 10:19:07 +0200 (CEST) Message-ID: <1523953145.2361.2.camel@cybertec.at> Subject: Re: To prefer sorts or filters in postgres, that is the question.... From: Laurenz Albe To: Bob Jones Cc: pgsql-general Date: Tue, 17 Apr 2018 10:19:05 +0200 In-Reply-To: References: <1523946266.2329.5.camel@cybertec.at> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Bob Jones wrote: > My current thinking is that the filter is a bit like an "fgrep" and > the sort actually requires memory allocation and some "real work", and > thus I've settled on the filter for now pending experiments with a > larger quantity of data. That's fine. A top-1-sort is less work than you maybe think: You go through all items and find the biggest one. So there is one comparison operator per row - very similar to what happens when "grepping" for NULL values. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com