pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Niklas Hambüchen <mail@nh2.me>
Cc: pgsql-bugs@lists.postgresql.org, ruben@benaco.com, Niklas Hambüchen <niklas@benaco.com>
Subject: Re: "memory exhausted" in query parser/simplifier for many nested parentheses
Date: Fri, 13 Dec 2024 17:02:32 -0500
Message-ID: <1258245.1734127352@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwa2c5Vjbbo4JoiJWdnqGd277yEfhVX-KJ7UYN+dPU8T7w@mail.gmail.com>
References: <161892c0-65fc-42a6-8af9-b098879decd4@nh2.me>
	<654489.1734019548@sss.pgh.pa.us>
	<e50e8be3-7b5e-42fa-ac8f-388e6598106b@nh2.me>
	<CAKFQuwa2c5Vjbbo4JoiJWdnqGd277yEfhVX-KJ7UYN+dPU8T7w@mail.gmail.com>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> I don't disagree with the premise that such hard-coded limits are
> undesirable but they also aren't always worth getting rid of, especially if
> they are inherited from an upstream dependency.

Having said all that ... I think there is a case here for raising
the core parser's YYMAXDEPTH, which would be a trivial matter of
inserting a #define for it.  Bison's default value of 10000
was probably set decades ago for much smaller hardware.  If I'm
computing it right, the space consumed per stack entry in PG
is 22 bytes (on 64-bit hardware), so that that limit corresponds
to only 220KB in stack, a fairly negligible number.  We could
make it 10 or 100 times larger without anyone noticing ---
especially since this is the upper limit for resizing the stack,
not the amount of space used to parse simple inputs.  That would
get us to a point where expression complexity would almost always
be limited by max_stack_depth, which the user has control over.

In theory we could make the limit as high as around 45M stack
levels, which would approach palloc's 1GB chunk limit.  But
I can't foresee a reason to let the parser stack get anywhere near
that big.  If you wrote millions of unmatched left parentheses,
you're just trying to cause trouble.  So I'd vote for going to
100K or 1M.

			regards, tom lane





view thread (10+ messages)

Message-ID: <1258245.1734127352@sss.pgh.pa.us>
Permalink:  ../1258245.1734127352@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1258245.1734127352@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, mail@nh2.me, niklas@benaco.com
  Subject: Re: "memory exhausted" in query parser/simplifier for many nested parentheses
  In-Reply-To: <1258245.1734127352@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox