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 1p3efG-00088z-5f for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Dec 2022 14:47:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p3eeG-0003Ib-8k for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Dec 2022 14:46:48 +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 1p3eK0-0002yH-DG for pgsql-hackers@lists.postgresql.org; Fri, 09 Dec 2022 14:25:52 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p3eJt-0002sg-Vz for pgsql-hackers@postgresql.org; Fri, 09 Dec 2022 14:25:51 +0000 Received: by mail-oi1-x230.google.com with SMTP id l127so4620864oia.8 for ; Fri, 09 Dec 2022 06:25:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=4Vipn9Oao6eVXgDY5dMF2NOlB+Sc4VnjHGN5NfBbUD8=; b=G6Z8tLhGOBsX8vwpS08z/5dmLsIPNq7K2xsOg2eSF+w+u1WI0gEadAEpHGBfOwcaIk zDb8L1Wcu+4CSVdG2EVGP0d6AzZ493GEKHh1tZsmsiuxQFEBxbCpEaxRbXLcNpqTVcJj +uRpQ2m8PnO345Tel7q879zobsyBBgVYys10O45L7FEE1FwJp/b2XGDTQXPg/hLNmL6g I85XVol1DsO0d0Z9XcIgoi1FMXG+AZama1wSmT7zs45cGIy9VMddRSFpbnf/Tg0jDHzc z5ZMj2RiocC6/U3rpcRrLofL0gaL8kLicBv3K8b54X4Ne6860EBDOB2TuVeoL3jcUZa8 w+hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4Vipn9Oao6eVXgDY5dMF2NOlB+Sc4VnjHGN5NfBbUD8=; b=xR3W5UDpltCyeU4f7ln7fr7wzmP9nApitagsxPpRZJXqedjJqx5Z4Fi0C4xaFrqOpS FcpUaR8vjO2hWqeTmKCcT0aPFD6KUQ7KK3x15Z4zdZqtPBr6Nj6CVZ0NQdHrbvOf5NSj bYNsUp3b4/Z7gYqjCR43A4D6WjgH5C7LdF1fMCChqer1lMC4gROWxXLOsk0lMYEJIAcO hB/jL5SJ83czJ6DNhV1w18Kb/OkQqcv6kUEKrF3ewcNY6V01xPAPIXaP4UXyGUXdov4x h8BR2V2XD0+PlvzMuX1AnMIxQJgqIRy6z8t1B8ofiE6rth14Hao5Da6PTuTvAhCt5LaE ac6Q== X-Gm-Message-State: ANoB5pklJha2e5ApNHMHxqsYGBbmzm5V3f5DBNphXzYLwaZRsHnHZ5yF ls3RriiNfZNAVUWkWsLyGY5SQ0NhJ613ODkQIgg= X-Google-Smtp-Source: AA0mqf5vCledhE4z0m7Ah5yfHg6t8FJdyBrS0VMj4yGfkzE1xwKrvx9Jmp7kS5KQ9dOfQKjZbmDm0X7izy7LVzNEt+c= X-Received: by 2002:a05:6808:254:b0:35e:4a14:8182 with SMTP id m20-20020a056808025400b0035e4a148182mr981619oie.171.1670595945356; Fri, 09 Dec 2022 06:25:45 -0800 (PST) MIME-Version: 1.0 References: <1197371508.4255.1327.camel@ebony.site> <1197660423.1536.8.camel@dell.linuxdev.us.dell.com> <15007.1197674561@sss.pgh.pa.us> <200712141830.16877.trent_shipley@qwest.net> <87k31ftoe0.fsf_-_@commandprompt.com> <686e46d6718f9535bc39fac7cad7408b@oss.nttdata.com> <769423519e16d18a1e7611c6931da58b@oss.nttdata.com> In-Reply-To: From: Danil Anisimow Date: Fri, 9 Dec 2022 21:25:34 +0700 Message-ID: Subject: Re: POC PATCH: copy from ... exceptions to: (was Re: VLDB Features) To: Damir Belyalov Cc: torikoshia , "a.lepikhov@postgrespro.ru" , PostgreSQL Hackers Content-Type: multipart/alternative; boundary="000000000000e2e18105ef65ed8d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e2e18105ef65ed8d Content-Type: text/plain; charset="UTF-8" Hi! I have looked at your patch and have a few questions. 110: static bool SafeCopying(CopyFromState cstate, ExprContext *econtext, 111: TupleTableSlot *myslot); --- 636: bool 637: SafeCopying(CopyFromState cstate, ExprContext *econtext, TupleTableSlot *myslot) Why is there no static keyword in the definition of the SafeCopying() function, but it is in the function declaration. 675: MemoryContext cxt = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory); 676: 677: valid_row = NextCopyFrom(cstate, econtext, myslot->tts_values, myslot->tts_isnull); 678: tuple_is_valid = valid_row; 679: 680: if (valid_row) 681: sfcstate->safeBufferBytes += cstate->line_buf.len; 682: 683: CurrentMemoryContext = cxt; Why are you using a direct assignment to CurrentMemoryContext instead of using the MemoryContextSwitchTo function in the SafeCopying() routine? 1160: /* Standard copying with option "safe copying" enabled by IGNORE_ERRORS. */ 1161: if (!SafeCopying(cstate, econtext, myslot)) 1162: break; I checked with GDB that the CurrentMemoryContext changes when SafeCopying returns. And the target context may be different each time you do a COPY in psql. 1879: cstate->sfcstate->safe_cxt = AllocSetContextCreate(oldcontext, 1880: "Safe_context", 1881: ALLOCSET_DEFAULT_SIZES); When you initialize the cstate->sfcstate structure, you create a cstate->sfcstate->safe_cxt memory context that inherits from oldcontext. Was it intended to use cstate->copycontext as the parent context here? On Wed, Nov 2, 2022 at 11:46 AM Damir Belyalov wrote: > Updated the patch: > - Optimized and simplified logic of IGNORE_ERRORS > - Changed variable names to more understandable ones > - Added an analogue of MAX_BUFFERED_BYTES for safe buffer > > > Regards, > Damir Belyalov > Postgres Professional > Regards, Daniil Anisimov Postgres Professional --000000000000e2e18105ef65ed8d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi!

I have looked at your pa= tch and have a few questions.

110: static bool SafeCopying(CopyFromS= tate cstate, ExprContext *econtext,
111: TupleTableSlot *myslot)= ;
---
636: bool
637: SafeCopying(CopyFromState cstate, ExprContext= *econtext, TupleTableSlot *myslot)

Why is there no static keyword i= n the definition of the SafeCopying() function, but it is in the function d= eclaration.

675: MemoryContext cxt =3D MemoryContextSwitchTo(econtex= t->ecxt_per_tuple_memory);
676:
677: valid_row =3D NextCopyFrom(c= state, econtext, myslot->tts_values, myslot->tts_isnull);
678: tup= le_is_valid =3D valid_row;
679:
680: if (valid_row)
681: sfcstat= e->safeBufferBytes +=3D cstate->line_buf.len;
682:
683: Curren= tMemoryContext =3D cxt;

Why are you using a direct assignment to Cur= rentMemoryContext instead of using the MemoryContextSwitchTo function in th= e SafeCopying() routine?

1160: /* Standard copying with option "= ;safe copying" enabled by IGNORE_ERRORS. */
1161: if (!SafeCopying(= cstate, econtext, myslot))
1162: break;

I checked with GDB that = the CurrentMemoryContext changes when SafeCopying returns. And the target c= ontext may be different each time you do a COPY in psql.

1879: cstat= e->sfcstate->safe_cxt =3D AllocSetContextCreate(oldcontext,
1880: = "Safe_context",
1881: ALLOCSET_DEFAULT_SIZES);=

When you initialize the cstate->sfcstate structure, you create a= cstate->sfcstate->safe_cxt memory context that inherits from oldcont= ext.
Was it intended to use cstate->copycontext as the parent context= here?

On Wed, Nov 2, 2022 at 11:46 AM Damir Belyalov <dam.bel07@gmail.com> wrote:
Updated t= he patch:
- Optimized and simplified logic of IGNORE_ERRORS
=
- Changed variable names to more understandable ones
- Added= an analogue of MAX_BUFFERED_BYTES for safe buffer


Regards,
Damir Belyalov
Postgres P= rofessional

Regards,
Daniil Anisimov
Postgres Professional
--000000000000e2e18105ef65ed8d--