Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcD5f-0007u9-4n for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Jun 2019 18:07:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hcD5d-0001Lb-Fy for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Jun 2019 18:07:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcD5c-0001LT-SW for pgsql-hackers@lists.postgresql.org; Sat, 15 Jun 2019 18:07:45 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcD5V-00059i-R6 for pgsql-hackers@lists.postgresql.org; Sat, 15 Jun 2019 18:07:43 +0000 Received: by mail-pg1-x541.google.com with SMTP id v9so3401111pgr.13 for ; Sat, 15 Jun 2019 11:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=97yktruFCALMYgqfVT26z/tbSacTZ1yhSKYVI8b/bcs=; b=RNWgC6yk7JlvWQuAI/uLMeimeBwP4vR6o/KvkFMFea8jas2g0VEuN/PNKuqdyJp5it JSANW5G7G+AS8eKSj0ZQQ5NnJS+B/bOLbai8UDQLLxCdc5a06aw4yKKAvl+KRi/CUEue s6ikJ/O17OhYN1oo+gDjuUS9exV5Wed/mTlVk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=97yktruFCALMYgqfVT26z/tbSacTZ1yhSKYVI8b/bcs=; b=GGGw1RhobGkWDeEGk3OkJc+yMNQSQi3H92PdL2dUN+zrUJsM69pfLlU78L8QTV2Mqf 58n0/U7hSQhra9d+u0K3SnGCVtfU5vBQ6h0rAGb4fEUE3pBOXjBiDdiOoqlMcJZhivwf 85mD0jp8IYOk2TuAzesieBFxwliD+To86vCHGEOxTu3o+kwl0g7Lnowj7eM9ggSX3c3G 4WM1MoNxO/oojEB1azXyViIEe9bxaYOIdPr6nimwF0VSQU8q8StcOzDMLPjHAPQbqrju jgpHx7InCXen4rXC8hLi1Sib6Xw3zaqfiwZaBDQgDLaMYIH6WBthiG09ySkV94GUe0lr kcuw== X-Gm-Message-State: APjAAAUi/QlH0wylzKGccLuXJg992cfgHCh05+4hoGVP9vOgdv1WmfUB EqpMU8QF30uRO8uJ9AJZfuKB3/ga/1U= X-Google-Smtp-Source: APXvYqxQxQZU+FsWsY9S/WOr5hGPpB+/2DC60PqCqBsnTuhVHjeA1Lu2ks6Sqhzzbnp2TiFeQi+uBg== X-Received: by 2002:a63:1b56:: with SMTP id b22mr39799069pgm.87.1560622055877; Sat, 15 Jun 2019 11:07:35 -0700 (PDT) Received: from rfd.leadboat.com (108-233-125-46.lightspeed.sntcca.sbcglobal.net. [108.233.125.46]) by smtp.gmail.com with ESMTPSA id l7sm7928904pfl.9.2019.06.15.11.07.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jun 2019 11:07:35 -0700 (PDT) Date: Sat, 15 Jun 2019 11:07:32 -0700 From: Noah Misch To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Dead encoding conversion functions Message-ID: <20190615180732.GA239428@rfd.leadboat.com> References: <41163.1559156593@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41163.1559156593@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, May 29, 2019 at 03:03:13PM -0400, Tom Lane wrote: > Pursuant to today's discussion at PGCon about code coverage, I went > nosing into some of the particularly under-covered subdirectories > in our tree, and immediately tripped over an interesting factoid: > the ASCII<->MIC and ASCII<->UTF8 encoding conversion functions are > untested ... not because the regression tests don't try, but because > those conversions are unreachable. pg_do_encoding_conversion() and > its sister functions have hard-wired fast paths for any conversion > in which the source or target encoding is SQL_ASCII, so that an > encoding conversion function declared for such a case will never > be used. > This situation seems kinda silly. My inclination is to delete > these functions as useless, but I suppose another approach is > to suppress the fast paths if there's a declared conversion function. > (Doing so would likely require added catalog lookups in places we > might not want them...) Removing the fast paths to make ascii_to_utf8() reachable would cause ERROR when server_encoding=SQL_ASCII, client_encoding=UTF8, and a query would otherwise send the client any character outside 7-bit ASCII. That's fairly defensible, but doing it for only UTF8 and MULE_INTERNAL is not. So if we like the ascii_to_utf8() behavior, I think the action would be to replace the fast path with an encoding-independent verification that all bytes are 7-bit ASCII. (The check would not apply when both server_encoding and client_encoding are SQL_ASCII, of course.) Alternately, one might prefer to replace the fast path with an encoding verification; in the SQL_ASCII-to-UTF8 case, we'd allow byte sequences that are valid UTF8, even though the validity may be a coincidence and mojibake may ensue. SQL_ASCII is for being casual about encoding, so it's not clear to me whether or not either prospective behavior change would be an improvement. However, I do find it clear to delete ascii_to_utf8() and ascii_to_mic(). > If we do delete them as useless, it might also be advisable to change > CreateConversionCommand() to refuse creation of conversions to/from > SQL_ASCII, to prevent future confusion. Sounds good.