Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fQdp7-0000Lx-CI for pgsql-general@arkaria.postgresql.org; Wed, 06 Jun 2018 19:10:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fQdp2-0001Iw-Fa for pgsql-general@arkaria.postgresql.org; Wed, 06 Jun 2018 19:10:16 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fQdp2-0001HK-3c for pgsql-general@lists.postgresql.org; Wed, 06 Jun 2018 19:10:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fQdou-0003ys-9K for pgsql-general@postgresql.org; Wed, 06 Jun 2018 19:10:14 +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 w56JA50H022137; Wed, 6 Jun 2018 15:10:05 -0400 From: Tom Lane To: Pavel Stehule cc: Jeremy Finzel , Postgres General Subject: Re: Slow planning time for simple query In-reply-to: References: Comments: In-reply-to Pavel Stehule message dated "Wed, 06 Jun 2018 20:52:02 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22135.1528312205.1@sss.pgh.pa.us> Date: Wed, 06 Jun 2018 15:10:05 -0400 Message-ID: <22136.1528312205@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Pavel Stehule writes: > 2018-06-06 18:59 GMT+02:00 Jeremy Finzel : >> We have an odd scenario on one of our OLTP systems, which behaves the same >> way on a streamer, of a 700-1000ms planning time for a query like this: >> SELECT * >> FROM table1 >> WHERE source_id IN (SELECT id FROM table2 WHERE customer_id = $1); > more times I seen similar issue based on bloated indexes on table - pg in > planning time detect min max from possible indexes Oh, hmm, yeah it could be ye olde get_actual_variable_range() issue. When this happens, are there perhaps a lot of recently-dead rows at either extreme of the range of table1.source_id or table2.id? We made a fix last year to improve that: https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=3ca930fc3 but it wasn't back-patched. regards, tom lane