pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Korotkov <akorotkov@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Turn tail recursion into iteration in CommitTransactionCommand()
Date: Fri, 08 Mar 2024 11:19:14 +0000
Message-ID: <E1riYFt-002i19-TD@gemulon.postgresql.org> (raw)

Turn tail recursion into iteration in CommitTransactionCommand()

Usually the compiler will optimize away the tail recursion anyway, but
if it doesn't, you can drive the function into stack overflow. For
example:

    (n=1000000; printf "BEGIN;"; for ((i=1;i<=$n;i++)); do printf "SAVEPOINT s$i;"; done; printf "ERROR; COMMIT;") | psql >/dev/null

In order to get better readability and less changes to the existing code the
recursion-replacing loop is implemented as a wrapper function.

Report by Egor Chindyaskin and Alexander Lakhin.
Discussion: https://postgr.es/m/1672760457.940462079%40f306.i.mail.ru
Author: Alexander Korotkov, Heikki Linnakangas

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fefd9a3fed275cecd9ed4091b00698deed39b92e

Modified Files
--------------
src/backend/access/transam/xact.c | 151 ++++++++++++++++++++++++++------------
1 file changed, 106 insertions(+), 45 deletions(-)



view thread (2+ messages)

Message-ID: <E1riYFt-002i19-TD@gemulon.postgresql.org>
Permalink:  ../E1riYFt-002i19-TD@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1riYFt-002i19-TD@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: akorotkov@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Turn tail recursion into iteration in CommitTransactionCommand()
  In-Reply-To: <E1riYFt-002i19-TD@gemulon.postgresql.org>

* 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