Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1oLA-0006KD-9e for pgsql-bugs@arkaria.postgresql.org; Wed, 24 May 2023 13:15:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q1oL8-0005Xv-6u for pgsql-bugs@arkaria.postgresql.org; Wed, 24 May 2023 13:15:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1oL7-0005Xm-V1 for pgsql-bugs@lists.postgresql.org; Wed, 24 May 2023 13:15:41 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q1oL5-001dy4-Es for pgsql-bugs@lists.postgresql.org; Wed, 24 May 2023 13:15:40 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-2537909d28cso186203a91.0 for ; Wed, 24 May 2023 06:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684934138; x=1687526138; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=HmEo8BGcPrPEbgbX1aL/RPUwPYA8clXrU6rYqKgD6uc=; b=SWOGBF86unNrptd1s0/iIb8Q38gCm1J/ZfAh8Wbz4YCty5ExyYqM4Y6uLrYDboegeL OEBNyseVZykJ5oSthskectj3RAbOHIYG6yLv9zDK6rW7rtALcsKNyS65/RkThda89yN2 RhisGVdIxaEQ1qNnMvCRHOujntunBlPDbGHeNMeKi60kPknoLz6QwkSdtC2Un22G3ZiH hzoxJBBxJtLxWRXCKEd3ZFjbsksbonsFceGmFEMGd/VT57htSuNEwif7wdRyerlTFrhR UyZXfOQBkotIcv0SykFLDd15oHqKnQIw1IE7yCdD63+y4o7wE+vNRKSYZvENdskCb1Dt OADA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684934138; x=1687526138; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HmEo8BGcPrPEbgbX1aL/RPUwPYA8clXrU6rYqKgD6uc=; b=PQyVfuBO8QbMeVtnSpcPy2d4dH5/fv8F0o0L7OQBPPLiyXAvVpFIhIBmaLL8IV4wLZ wehCa22bv+E4Uj/bvST8uD/0ZSxMRAF5Sk2P5XniB+rAxlTWjgNwN5JiTx23+5hKjxtT 30CUhVjxqgjwbfmjfCh08Fsp6qjVKWAiuV+ZT/XJZbZ+rZhbedZW1TaK3uDxVOoAE+7T nBW0h02osuoSJk6e8c8CcRbSWeXtS+I6C4RhDn3cYkYU9PEwNM3gOSjLWl70dAMdy8km HeDiv1HCQUOGbJWdn7K3iF94R1nzetXSexw4zUskFpxZy2W9sMj/aa4y6bJE6H+VCJyb bhuA== X-Gm-Message-State: AC+VfDzlqmhTKQykWtITwLOkzsuoE1+WQXrV/OZJQl1RFtMzewXeyVa8 Z2eDi4pmiQGuq/cOTFz/lcU= X-Google-Smtp-Source: ACHHUZ6iNHx31FeP6PIfJUlYWo9QtKWFlmgED3QOdlEvAcxlRNJak3++GSkF6hokMe9r/fRLKqn05A== X-Received: by 2002:a17:90a:4286:b0:253:6db6:18be with SMTP id p6-20020a17090a428600b002536db618bemr16136837pjg.14.1684934137523; Wed, 24 May 2023 06:15:37 -0700 (PDT) Received: from jrouhaud (2001-b011-1006-5e24-f8a1-e581-df1a-752b.dynamic-ip6.hinet.net. [2001:b011:1006:5e24:f8a1:e581:df1a:752b]) by smtp.gmail.com with ESMTPSA id bs5-20020a632805000000b0051eff0a70d7sm7700142pgb.94.2023.05.24.06.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 06:15:36 -0700 (PDT) Date: Wed, 24 May 2023 21:15:32 +0800 From: Julien Rouhaud To: Alexey Kachalin Cc: Tom Lane , pgsql-bugs@lists.postgresql.org Subject: Re: Prepared SQL name collision. The name implicitly is truncated by NAMEDATALEN Message-ID: <20230524131532.w44kifs3bbnti6nj@jrouhaud> References: <909619.1684850832@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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.