Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1la5oZ-0007If-8P for pgsql-general@arkaria.postgresql.org; Sat, 24 Apr 2021 00:06:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1la5oY-0007eR-6E for pgsql-general@arkaria.postgresql.org; Sat, 24 Apr 2021 00:06:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1la5oX-0007eD-PX for pgsql-general@lists.postgresql.org; Sat, 24 Apr 2021 00:06:25 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1la5oT-0002p1-Jj for pgsql-general@lists.postgresql.org; Sat, 24 Apr 2021 00:06:24 +0000 Received: by mail-ed1-x533.google.com with SMTP id h8so19088290edb.2 for ; Fri, 23 Apr 2021 17:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=ZxJvD0/DmSNwL+Rg8EnfSpfZtVWy1VEGzI9+YNVHSIU=; b=aY33A8XtdGNRbP6EfyPfqYLe1fMUfcVvZNetJn9vjyKoXL3pwROyw4xpu6dgSt8KaH 2OqUkOKFplEIZ9yNAVloWeYlVcMDrOCJwytgUmDorpxZlJAxCCErOrx6H5vdEzM5UuVM 8iq1qbx6nUiwzPMtlulrrHXfeAuvxdLaKBnz+NnPA9FIYRGxgpSEBpIBVn0/RHLhbFWq urIANgLBKH4G+WysMtQcQpRw1y+XpaRNI07JUqIexPGZJ9Ae3H6/Ej2u7lBRA+qBAJed Xs7E6tit3IMPaiVvXPEmeAlKIrzEWVjwgbnpAKReC3pN6YntjDZ1lUQvPYLh+sflZtjr oNEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZxJvD0/DmSNwL+Rg8EnfSpfZtVWy1VEGzI9+YNVHSIU=; b=OqDEsOq0fAtcOFC83TaAGKXY/oVmTo7phYKvhMhWE6laIZ3m8eQsqCLT84qmYwAdiE mmhcN+Pvic6tknCVKDLu+bmBA43gyLo9/01MD1hTf8TxQYUxARWGVRhgGkXvYjhXiLdb zLipr6kgnOy2adypA+QBfzFVLPYFS4VM8RdYpgnZN7mLq0ocK6Ie126lNIPEFI4pDBK0 D/7ROJhN7lf/DzPdACWqszb2AqZgCdqB+9gvERVQVBn0z0T93V19i24g2pLyDic5bqLE OLhQekvvmObz3b8pNNJZS8NdzSsfNwTA7u3erTyNeAMGqt6EfOmrK6r0gP86wH/PDbKh juoA== X-Gm-Message-State: AOAM530F/bsTIykNJW1JKkgWAB7nnhAIxqkEkET6o8pmOyNC5rVPJqbG +QCCKMrIr87wl5W/oN1TsW6fyOd9nbPnd5+czOs2KsdrvxKNilo1EMBwhiLEUuYeRxq43/pyTFu zuD3xqlI/sRHXTg7HwLrWKuxK8vSZuuUI5c4LEONik9bIzt2ChDp7YN6r/vnrz5oJ7odmPjs1Ix D1ctaem08GzNz/dypXjqNFcXBcdd9CX+RWhlDCRpGt+1qfS/jiZJ3Zr2mulSYpodCh7AFI+vnGO hO0vsGm4r9bMkuXxIwiC7mGkov765QL8xE5hirfaZffqazWpOXegxl+ X-Google-Smtp-Source: ABdhPJyEVe3W7CYGYfrPO+VKFmkC181TwrUP7ae4F0Okka2ppzr99puiiQNmUXKkjYhf1c4tcGiMCA== X-Received: by 2002:aa7:cdcc:: with SMTP id h12mr7438271edw.273.1619222780040; Fri, 23 Apr 2021 17:06:20 -0700 (PDT) Received: from [10.137.0.19] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id d10sm5184507ejw.125.2021.04.23.17.06.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Apr 2021 17:06:19 -0700 (PDT) Subject: Re: BRIN index on timestamptz To: Mohan Radhakrishnan , pgsql-general@lists.postgresql.org References: From: Tomas Vondra Message-ID: Date: Sat, 24 Apr 2021 02:06:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/23/21 10:31 AM, Mohan Radhakrishnan wrote: > Hi, >          I am planning to use as I search based on timestamptz fields. > There are millions of records.I refer > https://www.percona.com/blog/2019/07/16/brin-index-for-postgresql-dont-forget-the-benefits > > > I execute this on the AWS RDS instance. Is there something in the plan I > should pay attention to ? I notice the Execution Time. > > Thanks, > Mohan > > INSERT INTO testtab (id, date, level, msg) SELECT g, CURRENT_TIMESTAMP + > ( g || 'minute' ) :: interval, random() * 6, md5(g::text) FROM > generate_series(1,8000000) as g; Two things: a) You need to do ANALYZE, otherwise there are no statistics the optimizer could use (which is why the row estimates in the plans are entirely bogus). b) BRIN indexes don't work on random data, because the whole idea is about eliminating large blocks of data (e.g. 1MB). But with random data that's not going to happen, because each such range will match anything. Which is why seqscan is a bit faster than when using BRIN index. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company