From: Julien Rouhaud <rjuju123@gmail.com>
To: Alexey Kachalin <kachalin.alexey@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Prepared SQL name collision. The name implicitly is truncated by NAMEDATALEN
Date: Wed, 24 May 2023 21:15:32 +0800
Message-ID: <20230524131532.w44kifs3bbnti6nj@jrouhaud> (raw)
In-Reply-To: <CAF9fLqu+PuxKDvj5U1QAPegZso_fZ8vPy4wzBKyQAMTrKAURuA@mail.gmail.com>
References: <CAF9fLqtmtPqjLD06gnxFB_oLtx7SKm-gAe+7JNzXQG5iRb=utA@mail.gmail.com>
<909619.1684850832@sss.pgh.pa.us>
<CAF9fLqu+PuxKDvj5U1QAPegZso_fZ8vPy4wzBKyQAMTrKAURuA@mail.gmail.com>
Hi,
Please don't top post on this list.
On Wed, May 24, 2023 at 12:40:26PM +0100, Alexey Kachalin wrote:
>
> I would like to point out that this bug report is not about trucating
> identifiers as mentioned in documentation. The bug is collision, neither
> trucating.
>
> This is about getting different SQL errors on valid SQL statements.
> The valid SQL produces an error, it is a bug, isn't it?
> If a programmer did something wrong the error appears, I believe in that.
>
> Please consider an example:
> Run
> 'SELECT 222 as result_1'
> and get the result of '111' because of a collision.
> How should programmers understand the prepared SQL name exceeding length?
> No error, no warning, nothing, just valid sql returns the wrong result.
>
> If I exceed the limit I would like to get the error related to an issue,
> not just my valid SQL returns something unpredictable.
> Can I get a proper error for identifying issues and fixing?
> Is it expected behaviour that SQL returns corrupt value or error, when a
> prepared SQL statements name has gone beyond limit?
Unless I'm missing something your scenario did raise an error, you just
apparently ignored it and continued, and then eventually got wrong results:
rjuju=# PREPARE aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffggg AS
(SELECT 1);
PREPARE
rjuju=# PREPARE aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggg AS
(SELECT 2);
NOTICE: 42622: identifier "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggg" will be truncated to "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffggg"
ERROR: 42P05: prepared statement "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffggg" already exists
You should have stopped execution here, or at least tried to do something.
You simply can't expect to execute a prepared statements that you haven't
successfully prepared. The notice does gives you a clue of why it could have
failed, but it could have been something else too.
rjuju=# EXECUTE aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggg;
NOTICE: 42622: identifier "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggg" will be truncated to "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffggg"
?column?
----------
1
(1 row)
The fact that this execution returned the wrong result rather than error out
isn't really different from say a bug on your code that generates duplicated
names that don't get truncated. You shouldn't have tried to execute it.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: rjuju123@gmail.com, kachalin.alexey@gmail.com, tgl@sss.pgh.pa.us
Subject: Re: Prepared SQL name collision. The name implicitly is truncated by NAMEDATALEN
In-Reply-To: <20230524131532.w44kifs3bbnti6nj@jrouhaud>
References: <CAF9fLqtmtPqjLD06gnxFB_oLtx7SKm-gAe+7JNzXQG5iRb=utA@mail.gmail.com> <909619.1684850832@sss.pgh.pa.us> <CAF9fLqu+PuxKDvj5U1QAPegZso_fZ8vPy4wzBKyQAMTrKAURuA@mail.gmail.com> <20230524131532.w44kifs3bbnti6nj@jrouhaud>
* 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