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 1kVaxR-0007iq-AK for pgsql-performance@arkaria.postgresql.org; Thu, 22 Oct 2020 13:48:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kVaxO-0002BF-EP for pgsql-performance@arkaria.postgresql.org; Thu, 22 Oct 2020 13:48:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kVaxO-0002B8-21 for pgsql-performance@lists.postgresql.org; Thu, 22 Oct 2020 13:48:42 +0000 Received: from mail-il1-x141.google.com ([2607:f8b0:4864:20::141]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVaxB-0003EN-S1 for pgsql-performance@postgresql.org; Thu, 22 Oct 2020 13:48:40 +0000 Received: by mail-il1-x141.google.com with SMTP id j8so1791201ilk.0 for ; Thu, 22 Oct 2020 06:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-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=yYZmRCrD3ll4NGS9axxWNo30dSGT2Zxl0GJ4IgoMSCs=; b=V6FhGnEHOv9iGDFrzpFgWS1KLZcydfNvYaOkUpl1t08l5Nn5QtKw8wssg8NDdI8Mdp IzKRg5jF53LGVT8dfeSDBRHj1u8KAM+SWUECWIqoNh3T2Nz2B6+1mr4jd0rjgIRabQ/T kE/qj4tJpzIwXE17pQViTlhFwPD0Fu/zAnBYKPigmjeUXlHfcbLgcBmya1hkuJMnBwCo rO/a3PIeCi1SdA9I4Xzvch9CPmHGV3MjZBMscpA4YkQg/FSZTfcdZxIvDWzMgBMPBFF0 rrpZROQv4v2qPEx01xwb+VBNO2w4hvw5lSG4hHL2jMIxM7XlgxLHpa0eZG5E2vJhe1+s Zrbw== 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=yYZmRCrD3ll4NGS9axxWNo30dSGT2Zxl0GJ4IgoMSCs=; b=Z1Wg3cA8RxEWhp5A1z11Vl7DiE/3eaAvBIwh1N69p1YcfoyndwQOr4+Vl2MKPmpk0v dDa47CSRNr6J+Le23no5g6qhb5xLCDX/xNsUVajJkgvjyJn9LyyF3Dso4W8waC4xkhsA 8IKCSyIQhu9YQ9a5BZr+MXdO1JVolqmoU7+u5zWmpCBtQHRrR158x9cosbTM/G1fAhYo YrSIHeYgY4euiNaArdcIIlJtcj1v+WqSwYyDz98gBoX/BNb4fX536RblMf978gBO7+y9 r0uAc4OX7vLBBnROHDBFQCRaO0c0YJZCyqHLs12cif95dpF4LUDUQzci5mfQkn0ZCt4+ ON7g== X-Gm-Message-State: AOAM531405Np8Vi/DN3ILQLPyP4OtNFO79D68/Rp5weslcBIVuC3vUJL KzJi22RK0wBn2q0ZIggB9QT6kw== X-Google-Smtp-Source: ABdhPJxDcpPx3rrOmYmAqwxyJL17bzMXTv4mI+BQhWaIrYyvLrS5YDWh32t7jDOPLFJdJhDX7kbRbw== X-Received: by 2002:a92:5f03:: with SMTP id t3mr2040522ilb.25.1603374508920; Thu, 22 Oct 2020 06:48:28 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id t16sm1317541ild.27.2020.10.22.06.48.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2020 06:48:28 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id DBA59800740; Thu, 22 Oct 2020 08:48:26 -0500 (CDT) Date: Thu, 22 Oct 2020 08:48:26 -0500 From: Justin Pryzby To: Mats Olsen Cc: Sebastian Dressler , pgsql-performance@postgresql.org Subject: Re: Query Performance / Planner estimate off Message-ID: <20201022134826.GV9241@telsasoft.com> References: <61c9fd35-bdb8-3fe6-bda0-81c7e6a9eaf8@duneanalytics.com> <20201022063701.GU9241@telsasoft.com> <7f586824-0d53-0f84-15f1-f460dbc414b5@duneanalytics.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7f586824-0d53-0f84-15f1-f460dbc414b5@duneanalytics.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Oct 22, 2020 at 09:36:03AM +0200, Mats Olsen wrote: > On 10/22/20 8:37 AM, Justin Pryzby wrote: > > These look redundant (which doesn't matter for this the query): > > > > Partition key: RANGE (block_number) > > Indexes: > > "transactions_block_number_btree" btree (block_number DESC) > > "transactions_block_number_hash_key" UNIQUE CONSTRAINT, btree (block_number, hash) > > "transactions_block_number_time" btree (hash, block_number) > > > > Maybe that would be an index just on "hash", which might help here. > > > > Possibly you'd want to try to use a BRIN index on timestamp (or maybe > > block_number?). > > Yeah this could be a good idea, but the size of this table doesn't let me > add any indexes while it's online. I'll revisit these the next time we > redeploy the database. Why not CREATE INDEX CONCURRENTLY ? It seems to me you could add BRIN on all correlated indexes. It's nearly free. 0.102922715 | Pair_evt_Mint | evt_block_time | f | 0 | -0.56466025 | 10000 | 10001 | 0.964666 0.06872191 | Pair_evt_Mint | evt_block_time | f | 0 | -0.8379525 | 500 | 501 | 0.99982 0.06872191 | Pair_evt_Mint | evt_block_number | f | 0 | -0.8379525 | 500 | 501 | 0.99982 0.032878816 | Pair_evt_Mint | evt_block_number | f | 0 | -0.56466025 | 2500 | 2501 | 0.964666 > > Maybe you'd want to VACUUM the table to allow index-only scan on the hash > > columns ? Did you try it ? I think this could be a big win. Since it's append-only, autovacuum won't hit it (until you upgrade to pg13). -- Justin