Re: Perform COPY FROM encoding conversions in larger chunks

Heikki Linnakangas <hlinnaka@iki.fi>

From: Heikki Linnakangas <hlinnaka@iki.fi>
To: John Naylor <john.naylor@enterprisedb.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2021-02-07T18:13:28Z
Lists: pgsql-hackers

Attachments

On 02/02/2021 23:42, John Naylor wrote:
> Although a new patch is likely forthcoming, I did take a brief look and 
> found the following:
> 
> 
> In copyfromparse.c, this is now out of date:
> 
>   * Read the next input line and stash it in line_buf, with conversion to
>   * server encoding.
> 
> 
> One of your FIXME comments seems to allude to this, but if we really 
> need a difference here, maybe it should be explained:
> 
> +#define INPUT_BUF_SIZE 65536 /* we palloc INPUT_BUF_SIZE+1 bytes */
> 
> +#define RAW_BUF_SIZE 65536 /* allocated size of the buffer */

We do in fact still need the +1 for the NUL terminator. It was missing 
from the last patch version, but that was wrong; my fuzz testing 
actually uncovered a bug caused by that. Fixed.

Attached are new patch versions. The first patch is same as before, but 
rebased, pgindented, and with a couple of tiny fixes where conversion 
functions were still missing the "if (noError) break;" checks.

I've hacked on the second patch more, doing more refactoring and 
commenting for readability. I think it's in pretty good shape now.

- Heikki

Commits

  1. Do COPY FROM encoding conversion/verification in larger chunks.

  2. Add 'noError' argument to encoding conversion functions.

  3. Add direct conversion routines between EUC_TW and Big5.

  4. Add mbverifystr() functions specific to each encoding.