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 1j3Mtk-0002IS-P7 for pgsql-performance@arkaria.postgresql.org; Sun, 16 Feb 2020 16:36:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j3Mtj-0001WA-3x for pgsql-performance@arkaria.postgresql.org; Sun, 16 Feb 2020 16:35:59 +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 1j3Mti-0001W1-QI for pgsql-performance@lists.postgresql.org; Sun, 16 Feb 2020 16:35:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j3MtZ-0000jj-LE for pgsql-performance@lists.postgresql.org; Sun, 16 Feb 2020 16:35:57 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 01GGZhg0023937; Sun, 16 Feb 2020 11:35:44 -0500 From: Tom Lane To: Justin Pryzby cc: Laurenz Albe , MingJu Wu , pgsql-performance@lists.postgresql.org Subject: Re: Partial index creation always scans the entire table In-reply-to: <20200216155919.GI31889@telsasoft.com> References: <20200216155919.GI31889@telsasoft.com> Comments: In-reply-to Justin Pryzby message dated "Sun, 16 Feb 2020 09:59:19 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <23935.1581870943.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 16 Feb 2020 11:35:43 -0500 Message-ID: <23936.1581870943@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Justin Pryzby writes: > I was reminded of reading this, but I think it's a pretty different case= . > https://heap.io/blog/engineering/running-10-million-postgresql-indexes-i= n-production Yeah, the critical paragraph in that is = This isn=E2=80=99t as scary as it sounds for a two main reasons. First= , we shard all of our data by customer. Each table in our database holds only one customer=E2=80=99s data, so each table has a only a few thous= and indexes at most. Second, these events are relatively rare. The most common defined events make up only a few percent of a customer=E2=80=99= s raw events, and most are much more rare. This means that we perform relatively little I/O maintaining this schema, because most incoming events match no event definitions and therefore don=E2=80=99t need to = be written to any of the indexes. Similarly, the indexes don=E2=80=99t ta= ke up much space on disk. A set of partial indexes that cover a small part of the total data can be sensible. If you're trying to cover most/all of the data, you're doing it wrong --- basically, you're reinventing partitioning using the wrong tools. regards, tom lane