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 1fisQC-0000GG-TA for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Jul 2018 02:24:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fisQ9-0006ia-Qg for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Jul 2018 02:23:57 +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 1fisQ9-0006iT-Gg for pgsql-bugs@lists.postgresql.org; Fri, 27 Jul 2018 02:23:57 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fisQ6-0000JO-BT for pgsql-bugs@postgresql.org; Fri, 27 Jul 2018 02:23:55 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 3DE0C5F79C; Thu, 26 Jul 2018 22:23:53 -0400 (EDT) Date: Thu, 26 Jul 2018 22:23:53 -0400 From: Stephen Frost To: Soni M , Tom Lane Cc: Postgres Bug Subject: Re: Scanning all partition when more than 100 items in "where id in ()" clause Message-ID: <20180727022353.GJ27724@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="53Fw8V47qtIl7ph/" Content-Disposition: inline In-Reply-To: <19851.1532642641@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --53Fw8V47qtIl7ph/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Greetings, * Soni M (diptatapa@gmail.com) wrote: > Hello All, I think I found bug here. Postgres 9.6.9 on Red Hat Enterprise > Linux Server release 7.5 (Maipo). [... the 99 item query ...] > Planning time: 12.969 ms > Execution time: 7.062 ms [... the 100 item query ...] > Planning time: 60.537 ms > Execution time: 51.401 ms * Tom Lane (tgl@sss.pgh.pa.us) wrote: > I think it's a consequence of the limitation in predtest.c that it won't > try to do predicate proofs using ScalarArrayOps with more than 100 array > entries: This is far from the first time we (or, at least, I) have seen complaints about that particular constant. > /* > * Proof attempts involving large arrays in ScalarArrayOpExpr nodes are > * likely to require O(N^2) time, and more often than not fail anyway. > * So we set an arbitrary limit on the number of array elements that > * we will allow to be treated as an AND or OR clause. > * XXX is it worth exposing this as a GUC knob? > */ > #define MAX_SAOP_ARRAY_SIZE 100 Which certainly makes me think that comment in there might be worth something- perhaps we should make this a GUC and let users see just what would end up happening with a different choice. There could certainly be cases where it'd be better to work it out. > Not a bug, but a tradeoff. You'd be unhappy if the planner spent longer > devising the plan than it saved to eliminate the extra partitions. While I agree in concept, I'm awful curious how the "simpler" approach used when we hit the limit resulted in a 5x increase in planning time. Looks a bit like the extra time required to perform that elimination for at least a few more items would be saving us cycles somewhere else that are apparently pretty expensive. Soni, any chance that this query was the first time all of those partitions were hit in this backend, meaning there was a lot of time required to load the relation information for them? What happens if you prime the backend by running the 100-item case once, and then do 5 runs of the 99-item and then 5 of the 100-item case? Thanks! Stephen --53Fw8V47qtIl7ph/ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJbWoI4AAoJEO1sijiDR2RVjfMP/1WV1cVm7l58cxwK3gIMEf4O XXcsN+ENRUmKIeLpeWvzrvUdKdbkOWciMFRXwPBos9e5vnSIQ8wwXhspEjTIO8xo ZgjRKdKBblm4Lk4ncw4YGO1mQ+C6PXkQBd04AbZwvmv+iwBKR0QaOu+Bp/TXYNX5 nyDUx3AzahzQQE8AoO/tRuQrlmT06TzALr8l2Br14hgn4u/twhIwiUGFlUQ7JQAg cJzeka4uAQdWYIriBa62YECWBhP0olGtIGQLyNAWswWtZJUdJsqyOILt2GsfODT9 OrRiv4V7HfnQ8ZzaleQXEytPhJqlVO7Gdfs9ztWtNUP1C7zG6eLghCU66qPB2jqI mZcBgy6mmWqGvb/LDXCtVgbddmWlOOdxFfUWTp7/wU0DA0Ci6jBrd8+Xl+cmfE1/ 1d5bFX8UKRtPA99SF7dtjJKlEix4+nyw0LSr6Tso9wa/vtH611Tx/pBNkqFYuMtl bQzokgqy+Q6ogMTh/kch5REL0k6f+QP8pzUxCZhJCKcK+gj3ZqvTYGaqh8PI6UYz 4eaqSGjrUyFpI/BleqXJkTjqCdnXKj/9I4Dd8MSB/pEZIU553blgsTAjzY/Bex7v TPxdxUBfrQ5/NDjmVhTkhEXlk3SIw32aKg0Ykneo8mBVhlHucjG7dTt6jfRpjuAm 5rSnKay9rGi4kuhkGG+s =vVut -----END PGP SIGNATURE----- --53Fw8V47qtIl7ph/--