Skip to content

Commit

Permalink
[#25044] YSQL: Ignore FREEZE option in COPY
Browse files Browse the repository at this point in the history
Summary:
### Issue first observed in

```
./bin/pgbench  -i -s 10  -U yugabyte -h 127.0.0.1 -p 5433 yugabyte
dropping old tables...
NOTICE:  table "pgbench_accounts" does not exist, skipping
NOTICE:  table "pgbench_branches" does not exist, skipping
NOTICE:  table "pgbench_history" does not exist, skipping
NOTICE:  table "pgbench_tellers" does not exist, skipping
creating tables...
WARNING:  storage parameter fillfactor is unsupported, ignoring
WARNING:  storage parameter fillfactor is unsupported, ignoring
WARNING:  storage parameter fillfactor is unsupported, ignoring
generating data (client-side)...
1000000 of 1000000 tuples (100%) done (elapsed 0.45 s, remaining 0.00 s)
ERROR:  cannot perform COPY FREEZE because the table was not created or truncated in the current subtransaction
pgbench: error: PQendcopy failed
```

with read committed isolation level.

### Root Cause

pgbench fetches server version and uses COPY with FREEZE option if available

```name=pgbench.c
	/*
	 * accounts is big enough to be worth using COPY and tracking runtime
	 */
	/* use COPY with FREEZE on v14 and later without partitioning */
	if (partitions == 0 && PQserverVersion(con) >= 140000)
		copy_statement = "copy pgbench_accounts from stdin with (freeze on)";
	else
		copy_statement = "copy pgbench_accounts from stdin";
```

this triggers an assert condition because of our savepoint logic in read committed.

### Objective

DocDB does not support FREEZE. So, we introduce the following semantics with FREEZE on COPY FROM command

1. When yb_ignore_freeze_with_copy = true, display a NOTICE saying that FREEZE is unsupported.
2. When  yb_ignore_freeze_with_copy = false, raise an error.

```
dropping old tables...
NOTICE:  table "pgbench_accounts" does not exist, skipping
NOTICE:  table "pgbench_branches" does not exist, skipping
NOTICE:  table "pgbench_history" does not exist, skipping
NOTICE:  table "pgbench_tellers" does not exist, skipping
creating tables...
WARNING:  storage parameter fillfactor is unsupported, ignoring
WARNING:  storage parameter fillfactor is unsupported, ignoring
WARNING:  storage parameter fillfactor is unsupported, ignoring
generating data (client-side)...
1000000 of 1000000 tuples (100%) done (elapsed 0.52 s, remaining 0.00 s)
ERROR:  cannot perform COPY FREEZE on a YugaByte table
```

Ignore FREEZE with COPY FROM by default for pg compatibility.

Fixes #25044.
Jira: DB-14178

Test Plan:
Jenkins

Added a simple test to yb_feature_copy.sql.
```
./yb_build.sh --java-test TestPgRegressFeature
```

Reviewers: pjain, smishra

Reviewed By: pjain

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D40477
  • Loading branch information
pao214 committed Dec 20, 2024
1 parent 885131f commit f1df1b8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/postgres/src/backend/commands/copyfrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

/* Yugabyte includes */
#include "executor/ybcModifyTable.h"
#include "pg_yb_utils.h"
#include "utils/builtins.h"

/*
Expand Down Expand Up @@ -625,8 +626,10 @@ CopyFrom(CopyFromState cstate)
* scan or command tolerates false negatives. FREEZE causes other sessions
* to see rows they would not see under MVCC, and a false negative merely
* spreads that anomaly to the current session.
*
* YB: We don't support COPY FREEZE on YB tables.
*/
if (cstate->opts.freeze)
if (!IsYugaByteEnabled() && cstate->opts.freeze)
{
/*
* We currently disallow COPY FREEZE on partitioned tables. The
Expand Down Expand Up @@ -667,6 +670,11 @@ CopyFrom(CopyFromState cstate)
ti_options |= TABLE_INSERT_FROZEN;
}

if (IsYugaByteEnabled() && cstate->opts.freeze)
ereport(yb_ignore_freeze_with_copy ? NOTICE : ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot perform COPY FREEZE on a YugaByte table")));

/*
* We need a ResultRelInfo so we can use the regular executor's
* index-entry-making machinery. (There used to be a huge amount of code
Expand Down
10 changes: 10 additions & 0 deletions src/postgres/src/backend/utils/misc/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3070,6 +3070,16 @@ static struct config_bool ConfigureNamesBool[] =
},
&yb_enable_advisory_locks,
false,
},

{
{"yb_ignore_freeze_with_copy", PGC_USERSET, ERROR_HANDLING_OPTIONS,
gettext_noop("Ignore the FREEZE flag on COPY FROM command."),
NULL,
GUC_NOT_IN_SAMPLE
},
&yb_ignore_freeze_with_copy,
true,
NULL, NULL, NULL
},

Expand Down
1 change: 1 addition & 0 deletions src/postgres/src/backend/utils/misc/pg_yb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,7 @@ bool yb_enable_fkey_catcache = true;
bool yb_enable_nop_alter_role_optimization = true;
bool yb_enable_inplace_index_update = true;
bool yb_enable_advisory_locks = false;
bool yb_ignore_freeze_with_copy = true;

YBUpdateOptimizationOptions yb_update_optimization_options = {
.has_infra = true,
Expand Down
5 changes: 5 additions & 0 deletions src/postgres/src/include/pg_yb_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@ extern bool yb_enable_fkey_catcache;
*/
extern bool yb_enable_nop_alter_role_optimization;

/*
* Compatibility option to ignore FREEZE with COPY FROM.
*/
extern bool yb_ignore_freeze_with_copy;

//------------------------------------------------------------------------------
// GUC variables needed by YB via their YB pointers.
extern int StatementTimeout;
Expand Down
14 changes: 14 additions & 0 deletions src/postgres/src/test/regress/expected/yb_feature_copy.out
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,20 @@ select * from main_table order by a;
5 | 5
(5 rows)

-- FREEZE
truncate copy_options;
copy copy_options from stdin with (format csv, freeze);
NOTICE: cannot perform COPY FREEZE on a YugaByte table
select * from copy_options order by a;
a | b
---+---
1 | 1
2 | 2
3 | 3
4 | 4
5 | 5
(5 rows)

-- clean up
DROP TABLE forcetest;
DROP TABLE x;
Expand Down
12 changes: 12 additions & 0 deletions src/postgres/src/test/regress/sql/yb_feature_copy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ copy main_table from stdin with (format csv, disable_fk_check);

select * from main_table order by a;

-- FREEZE
truncate copy_options;
copy copy_options from stdin with (format csv, freeze);
1,1
2,2
3,3
4,4
5,5
\.

select * from copy_options order by a;

-- clean up
DROP TABLE forcetest;
DROP TABLE x;
Expand Down

0 comments on commit f1df1b8

Please sign in to comment.