Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLlhN-00Gst8-Vy for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Dec 2024 16:05:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tLlhL-00DGfd-Bx for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Dec 2024 16:05:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLlhL-00DGfV-3E for pgsql-bugs@lists.postgresql.org; Thu, 12 Dec 2024 16:05:56 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLlhJ-002UKr-7w for pgsql-bugs@lists.postgresql.org; Thu, 12 Dec 2024 16:05:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4BCG5mas654490; Thu, 12 Dec 2024 11:05:49 -0500 From: Tom Lane To: =?UTF-8?Q?Niklas_Hamb=C3=BCchen?= cc: pgsql-bugs@lists.postgresql.org, ruben@benaco.com, =?UTF-8?Q?Niklas_Hamb=C3=BCchen?= Subject: Re: "memory exhausted" in query parser/simplifier for many nested parentheses In-reply-to: <161892c0-65fc-42a6-8af9-b098879decd4@nh2.me> References: <161892c0-65fc-42a6-8af9-b098879decd4@nh2.me> Comments: In-reply-to =?UTF-8?Q?Niklas_Hamb=C3=BCchen?= message dated "Wed, 11 Dec 2024 22:59:41 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <654488.1734019548.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 12 Dec 2024 11:05:48 -0500 Message-ID: <654489.1734019548@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =3D?UTF-8?Q?Niklas_Hamb=3DC3=3DBCchen?=3D writes: > we noticed that when writing a large query of form > (((A OR B) OR C) OR ...) > with many terms (e.g. 13000) this causes one of two errors: > 1. memory exhausted at or near "(" > 2. stack depth limit exceeded > ... > We consider this a bug because it means one cannot easily generate large= queries that query a couple thousand entries in a `SELECT ... WHERE` cond= ition. [ shrug... ] Even if these examples didn't fail, they would perform terribly. Limits are a fact of life. Write your query some other way, for example using "x IN (list)" or other shortcut syntaxes. regards, tom lane