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 1huf8O-0000AZ-BM for pgsql-general@arkaria.postgresql.org; Mon, 05 Aug 2019 15:42:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1huf8N-0007T1-3X for pgsql-general@arkaria.postgresql.org; Mon, 05 Aug 2019 15:42:51 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1huf8M-0007MZ-IC for pgsql-general@lists.postgresql.org; Mon, 05 Aug 2019 15:42:50 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1huf8F-0007Jr-1o for pgsql-general@postgresql.org; Mon, 05 Aug 2019 15:42:49 +0000 Received: by mail-qt1-x841.google.com with SMTP id h18so81392107qtm.9 for ; Mon, 05 Aug 2019 08:42:42 -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:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=1maAXkY/E+VvoA8Pxxw9XI9i8pG2a17JueU6pUJmKFs=; b=ngYPFQFEbdKLaiEKwbzPsB5WfehiH7MkUDrQp6k4b81QTniepBXWF/7DqOuyw1mV9w cc4NVvOLT3t7TuA51rzbv9qGwb4MaYqK045Cpcen8VOXYadDUZxo51JwSiL3O81N4/dA H7BKYYmUlJIHg6OsNoMAcQ6d24reAfiSOZZSjHUAVS3nDKuyRCD8JLEfovPPrJNVnWT/ 4/yjqPL9gZeVCI1dv+CR4Ds19lHnYQJFzLSlRbU7sqUdJ8lgTV3vbDRfYqTggsJhxsJd xruxHV2wUOonqKdSTCz3CRIxObuxObfc5u+lpfy77JIImaxwWJH18aM0hloGoWi5IKvS 4IbQ== 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=1maAXkY/E+VvoA8Pxxw9XI9i8pG2a17JueU6pUJmKFs=; b=r+mazFx/jG+b7kTkFcnXWDYFERUcNelM5ngc9jn3N4OGfKiT2QL1QKuRDvLAvcM7rN ZmWgvh47/xJRLJk3bJ+yYvlfeTB6AJtbaQpj80T0Lfx1RfksMA9sqQ32wOk+lj26KRAJ E8Xh0CJ15MRTY36EmpQu4eTeHMJfGP3dbqLt3hibx5qBrWTw43rwiNGPzYa2JM/UfhZW pwfvSNN+NYCY63eTPfKdfLWsuM9/vTZG+WzwsQrGGnSE+P3RJJA6/f9rWZp/wbMEQU19 QWLVw+c8y1dWrKJm9NtIvRLt0oNx7IFCYVsIir32S0EobDmySWLunMN/gOffF/KyisC+ ZEhw== X-Gm-Message-State: APjAAAXwammxnoe4HbQDu3I5Jj7SzVYu1iLLCTUVTlrxVqTDeLVcq4JI tVMXlAKjp3AvVn+G5xA++inLzw== X-Google-Smtp-Source: APXvYqyTp4cyB6JPZM7I8zK1NEwJt3jkLm+n6cQugwnK/VxAd1lmhchtO6eduB1F4Z4Ht1/LlwMIqQ== X-Received: by 2002:ad4:4870:: with SMTP id u16mr104984034qvy.174.1565019760562; Mon, 05 Aug 2019 08:42:40 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([201.186.81.5]) by smtp.gmail.com with ESMTPSA id 42sm43926935qtm.27.2019.08.05.08.42.39 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 08:42:40 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 20489123A8B; Mon, 5 Aug 2019 11:42:38 -0400 (-04) Date: Mon, 5 Aug 2019 11:42:38 -0400 From: Alvaro Herrera To: Jeremy Finzel Cc: Tom Lane , Postgres General Subject: Re: Aggregate not using BRIN index on timestamp Message-ID: <20190805154238.GA7309@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.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Aug-05, Jeremy Finzel wrote: > Thanks Tom. So, this is a very general question, but would it be possible > to develop that feature into BRIN, given what it stores? Even if it does > not have ordering information, doesn't it know which blocks would contain > the lowest values, so it could choose to do a "bitmap scan ordered sort" or > something, depending on the number of rows sought? Or is the problem that > it has no way of determining what value actually would be the "minimum" > without the query specifying a particular date, such as less than > "2013-04-01"? For btrees, we have planagg.c which transforms min() and max() into subqueries (SELECT .. WHERE ... ORDER BY .. LIMIT 1). In a BRIN index, you could execute the search by scanning the index to determine which ranges contain the least/greatest values, and then using a bitmap scan to scan those. I'm not sure that this is a transformation that can be applied cleanly, since that thing I describe doesn't look to be a "subquery". But maybe it can -- I think you'd need a special executor node. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services