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 1j3MKQ-0001G6-Cm for pgsql-performance@arkaria.postgresql.org; Sun, 16 Feb 2020 15:59:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j3MKO-0002KP-PC for pgsql-performance@arkaria.postgresql.org; Sun, 16 Feb 2020 15:59:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3MKO-0002KC-6F for pgsql-performance@lists.postgresql.org; Sun, 16 Feb 2020 15:59:28 +0000 Received: from mail-yw1-xc42.google.com ([2607:f8b0:4864:20::c42]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j3MKI-0003NV-0Q for pgsql-performance@lists.postgresql.org; Sun, 16 Feb 2020 15:59:24 +0000 Received: by mail-yw1-xc42.google.com with SMTP id i126so6763295ywe.7 for ; Sun, 16 Feb 2020 07:59:21 -0800 (PST) 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:mime-version:content-disposition :in-reply-to:user-agent; bh=JSJSkdmDcNe01mK5LixCd2xRw781Ita4LCUaV7HYNv4=; b=fp5Ga4p8b8hqQDK1jHnP0DJbKuV6n+ZjZ0leGzQz2/RBnNDj7XFe7R3lxOJQREjB+V wp7VhLTbY6p4nSccefp2Jj1P9xMjzRPQPl5uomU6xo3H8bd8nrLj65EpAZegXh+kLiIt IDZ0wZtZZgU4acuPVwNwwbGe+L2+wAr6+iYId6rCJAqi/KyqWOqJAWC67e7u6RIMxSuW j5jhl3W+RWwYq6yhq9QsLcInfLrki3fzXUCpwB0QEMoKSW+ETRn6GBjRN5mDv4O+aSOt VbzMNl3DWhwmAAYzoyMM7L3IzgQxwJAi1okd/UyzgH3omsDKQ86vfP+8QWaa9n23uxPb s4bQ== 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:in-reply-to:user-agent; bh=JSJSkdmDcNe01mK5LixCd2xRw781Ita4LCUaV7HYNv4=; b=b2KD1a3gNwbs0ekGuZqdRYd6Fbw8tduLNdynUu3kYxQ/+q3IrqjtSoXZ0Qtrg9npxH jydToVfkAXhUUX2mxDrdSXIkCp3c7ffRgCSFGoJrGPQfUdzMakIiBXSFtTDQdTxWhW0g NZ72nJZE/eKtWjPezQDh43G+ninfPRp7LoAWdzISlFrCTF3kfq+aIB7cEOvueD1zMfUz aH/hHxI5LGUXUVPK+FqHCSBvf/t5x/pM77jPhhTyGrKjJWiiTC/mIdIYbsU2deRfOBB2 wd2iT9nKsyYm/J04D0I0/NoKpEv+RvNtt+yDSAVuGnpSy0x2uOKLx9CeHF4uKJlU1ejC kP0Q== X-Gm-Message-State: APjAAAWXVB+lsf0HfSGdDKQ9n2s0CGVSlobsVrNMcQvN+gtL1jQ46Jze 0Qnn0irM6O8FxFGANs1v5QWbKA== X-Google-Smtp-Source: APXvYqxGpE0icz5JL9MRFCNgwd5f2Ws5H0utkhauqiRjzpozVwEbyU1ExGNf7GN+B/fKFq5hHP/elQ== X-Received: by 2002:a0d:f106:: with SMTP id a6mr9227759ywf.318.1581868761094; Sun, 16 Feb 2020 07:59:21 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id d22sm5164071ywb.77.2020.02.16.07.59.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Feb 2020 07:59:20 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 46C47800AA0; Sun, 16 Feb 2020 09:59:19 -0600 (CST) Date: Sun, 16 Feb 2020 09:59:19 -0600 From: Justin Pryzby To: Laurenz Albe , Tom Lane Cc: MingJu Wu , pgsql-performance@lists.postgresql.org Subject: Re: Partial index creation always scans the entire table Message-ID: <20200216155919.GI31889@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <19549.1581867005@sss.pgh.pa.us> <43b329d274c3535c75d2fbd6912b5ae8e3e51582.camel@cybertec.at> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Feb 15, 2020 at 10:15:53PM +0100, Laurenz Albe wrote: > > My scenario is that I have a table with 50M rows that are categorized into 10K categories. > > I need to create a partial index for each category. I have created a index on the category > > column, hoping that postgres can use this information when creating the partial indexes. > > However, postgres always performs full table scan. > > There is your problem. > > You don't need a partial index per category, you need a single index that *contains* the category. On Sun, Feb 16, 2020 at 10:30:05AM -0500, Tom Lane wrote: > Laurenz Albe writes: > > On Sat, 2020-02-15 at 19:04 +0800, MingJu Wu wrote: > >> My scenario is that I have a table with 50M rows that are categorized into 10K categories. > >> I need to create a partial index for each category. > > > You don't need a partial index per category, you need a single index that *contains* the category. > > Yeah, that's an anti-pattern. Essentially, you are trying to replace the The OP mentioned having an index on "category", which they were hoping the creation of partial indexes would use: On Sat, Feb 15, 2020 at 07:04:48PM +0800, MingJu Wu wrote: > My scenario is that I have a table with 50M rows that are categorized into > 10K categories. I need to create a partial index for each category. I have > created a index on the category column, hoping that postgres can use this > information when creating the partial indexes. However, postgres always > performs full table scan. So the question is why they (think they) *also* need large number of partial indexes. 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-in-production -- Justin