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 1tM66V-001iOz-9p for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Dec 2024 13:53:16 +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 1tM66S-0070zt-MY for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Dec 2024 13:53:13 +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 1tLmKU-00DUAH-VA for pgsql-bugs@lists.postgresql.org; Thu, 12 Dec 2024 16:46:24 +0000 Received: from mail.nh2.me ([116.202.188.98]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLmKT-002UeB-BV for pgsql-bugs@lists.postgresql.org; Thu, 12 Dec 2024 16:46:23 +0000 Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nh2.me; s=mail; t=1734021980; bh=jDGQsh6bBMw1P92YnHqrVqqoChmlMhA81lPGzqYNBGE=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=i312OCkyfqdOgsxTeIdHN10VPacD1riWzf2xyp5HE8YdJAc01X17LfERvygLEt1t7 jzpP4L3dT/cNLB0ry3ls8zEJFJCihniyRGqp9b5KZqgn+Jrp623yd4ScJQ9vTwMbkb TypJpBLZ+5UOc0TbDl/Os2+wmmlGtH0v4/8YU/olvFwBTTy5pUFER4bKkjtLiqGkHf iML1IqnH67OC2mwaJrLq4zTw+nLL2UsyQVJ/qmVTEHKqM1PHUVXMGF8f8UFKVlKDWw VWDYdM269BESMRGeNSNZ01V4QSLqOoIHWlrS6Cp6jVGk393pMhORSQYNXuNKuYLo5a ShvPqyL+wlwsA== Date: Thu, 12 Dec 2024 17:46:18 +0100 MIME-Version: 1.0 Subject: Re: "memory exhausted" in query parser/simplifier for many nested parentheses To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org, ruben@benaco.com, =?UTF-8?Q?Niklas_Hamb=C3=BCchen?= References: <161892c0-65fc-42a6-8af9-b098879decd4@nh2.me> <654489.1734019548@sss.pgh.pa.us> From: =?UTF-8?Q?Niklas_Hamb=C3=BCchen?= Content-Language: en-US In-Reply-To: <654489.1734019548@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Tom, > Write your query some other way, for example using "x IN (list)" or other shortcut syntaxes. As a user, how can I know that 10000 list entries in "x in (A, B, ...)" will not also hit an arbitrary parser implementation detail hardcoded limit? How shall the user have confidence that the parser is better at handling multiple commas than multiple parens? None of that seems to be documented anywhere (`max_stack_depth` is, but the code doesn't even get that far, and `YYMAXDEPTH` isn't). In absence of such docs, one must build systems that later fail at arbitrary limits when e.g. the user clicks some larger number of checkboxes that construct a batch query. There might be a different query that works for that number, but a user of postgres cannot know which construct will work unless they read GNU Bison's source code. If I build some workaround today, e.g. splitting the query into multiple ones of max length N, how do I know it will still work in the future, e.g. if Postgres changes the Bison version or switches to a different parser? The hardcodedness of arbitrary small limits that don't scale itself is also a problem: One cannot configure postgres to allow queries that the hardware is perfectly able of handling. It would be a bit like GCC giving up to compile a file if it contains more than 10000 words. > Limits are a fact of life. I agree limits can be a fact of life, but life is better if you know what those limits are, or if you can set them, versus having to guess and hope (it's especially difficult to build robust systems with "hope-based programming").