@@ -1978,8 +1978,6 @@ CopyFrom(CopyState cstate)
1978
1978
* ROLLBACK TO save;
1979
1979
* COPY ...
1980
1980
*
1981
- * However this is OK since at worst we will fail to make the optimization.
1982
- *
1983
1981
* Also, if the target file is new-in-transaction, we assume that checking
1984
1982
* FSM for free space is a waste of time, even if we must use WAL because
1985
1983
* of archiving. This could possibly be wrong, but it's unlikely.
@@ -1991,6 +1989,7 @@ CopyFrom(CopyState cstate)
1991
1989
* no additional work to enforce that.
1992
1990
*----------
1993
1991
*/
1992
+ /* createSubid is creation check, newRelfilenodeSubid is truncation check */
1994
1993
if (cstate -> rel -> rd_createSubid != InvalidSubTransactionId ||
1995
1994
cstate -> rel -> rd_newRelfilenodeSubid != InvalidSubTransactionId )
1996
1995
{
@@ -2006,18 +2005,27 @@ CopyFrom(CopyState cstate)
2006
2005
* after xact cleanup. Note that the stronger test of exactly
2007
2006
* which subtransaction created it is crucial for correctness
2008
2007
* of this optimisation.
2009
- *
2010
- * As noted above rd_newRelfilenodeSubid is not set in all cases
2011
- * where we can apply the optimization, so in those rare cases
2012
- * where we cannot honour the request we do so silently.
2013
2008
*/
2014
- if (cstate -> freeze &&
2015
- ThereAreNoPriorRegisteredSnapshots () &&
2016
- ThereAreNoReadyPortals () &&
2017
- (cstate -> rel -> rd_newRelfilenodeSubid == GetCurrentSubTransactionId () ||
2018
- cstate -> rel -> rd_createSubid == GetCurrentSubTransactionId ()))
2019
- hi_options |= HEAP_INSERT_FROZEN ;
2009
+ if (cstate -> freeze )
2010
+ {
2011
+ if (!ThereAreNoPriorRegisteredSnapshots () || !ThereAreNoReadyPortals ())
2012
+ ereport (ERROR ,
2013
+ (ERRCODE_INVALID_TRANSACTION_STATE ,
2014
+ errmsg ("cannot perform FREEZE because of prior transaction activity" )));
2015
+
2016
+ if (cstate -> rel -> rd_createSubid == GetCurrentSubTransactionId () ||
2017
+ cstate -> rel -> rd_newRelfilenodeSubid == GetCurrentSubTransactionId ())
2018
+ hi_options |= HEAP_INSERT_FROZEN ;
2019
+ else
2020
+ ereport (ERROR ,
2021
+ (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ,
2022
+ errmsg ("cannot perform FREEZE because of transaction activity after table creation or truncation" )));
2023
+ }
2020
2024
}
2025
+ else if (cstate -> freeze )
2026
+ ereport (ERROR ,
2027
+ (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ,
2028
+ errmsg ("cannot perform FREEZE because the table was not created or truncated in the current transaction" )));
2021
2029
2022
2030
/*
2023
2031
* We need a ResultRelInfo so we can use the regular executor's
0 commit comments