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 1j2e36-00050C-SR for pgsql-docs@arkaria.postgresql.org; Fri, 14 Feb 2020 16:42:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j2e35-0005KI-HO for pgsql-docs@arkaria.postgresql.org; Fri, 14 Feb 2020 16:42:39 +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 1j2e35-0005I9-98 for pgsql-docs@lists.postgresql.org; Fri, 14 Feb 2020 16:42:39 +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 1j2e33-0002NF-Ro for pgsql-docs@lists.postgresql.org; Fri, 14 Feb 2020 16:42:38 +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 01EGgYnL012810; Fri, 14 Feb 2020 11:42:34 -0500 From: Tom Lane To: samuel.hodge@live.com cc: pgsql-docs@lists.postgresql.org Subject: Re: Clarification on interactions between query parameters and partial indexes In-reply-to: <158163485510.6759.4276544280525471906@wrigleys.postgresql.org> References: <158163485510.6759.4276544280525471906@wrigleys.postgresql.org> Comments: In-reply-to PG Doc comments form message dated "Thu, 13 Feb 2020 23:00:55 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <12808.1581698554.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 14 Feb 2020 11:42:34 -0500 Message-ID: <12809.1581698554@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Doc comments form writes: > In section "11.8 Partial Indexes" it states the following: > "Matching takes place at query planning time, not at run time. As a resu= lt, > parameterized query clauses do not work with a partial index. For exampl= e a > prepared query with a parameter might specify =E2=80=9Cx < ?=E2=80=9D wh= ich will never imply > =E2=80=9Cx < 2=E2=80=9D for all possible values of the parameter." > We decided to run some tests to verify this statement, as we use both > partial indexes and parameterized queries on some very large tables (100= mil+ > rows). However, we are not able to replicate the stated behavior. It see= ms > like the query planner is able to make use of the partial index for both > parameterized and manually interpolated values. > Have we misunderstood what the documentation is trying to say or has thi= s > limitation been fixed? The statement is true as far as it goes: "x < $1" will never be considered to imply "x < 2". However, there's a lot of context that's going unstated there. In some code paths, higher-level code such as the plan cache may try substituting the concrete value of a parameter as a constant, to see if it can get a better (but less general) plan that way. I think that's probably what happened in your experiment, but you didn't provide enough details to be sure. regards, tom lane