B compatibility support sql_mode NO_AUTO_VALUE_ON_ZERO

This commit is contained in:
JulianZhang
2024-10-28 11:10:32 +08:00
parent ff7d85b395
commit e3f4fcd52b
4 changed files with 19 additions and 4 deletions

View File

@ -33380,8 +33380,11 @@ static int128 EvaluateAutoIncrement(Relation rel, TupleDesc desc, AttrNumber att
autoinc = datum2autoinc(cons_autoinc, *value);
modify_value = (autoinc == 0);
}
/* When datum is NULL/0, auto increase */
if (autoinc == 0) {
/*
* By default, when datum is NULL/0, auto increase;
* If NO_AUTO_VALUE_ON_ZERO is set, auto increase only when datum is NULL.
*/
if (*is_null || (autoinc == 0 && !CheckPluginNoAutoValueOnZero())) {
if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP) {
autoinc = tmptable_autoinc_nextval(rel->rd_rel->relfilenode, cons_autoinc->next);
} else {

View File

@ -1669,8 +1669,11 @@ Tuple ExecAutoIncrement(Relation rel, EState* estate, TupleTableSlot* slot, Tupl
autoinc = datum2autoinc(cons_autoinc, datum);
modify_tuple = (autoinc == 0);
}
/* When datum is NULL/0, auto increase */
if (autoinc == 0) {
/* By default, when datum is NULL/0, auto increase;
* If NO_AUTO_VALUE_ON_ZERO is set, auto increase only when datum is NULL.
*/
if (is_null || (autoinc == 0 && !CheckPluginNoAutoValueOnZero())) {
if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP) {
autoinc = tmptable_autoinc_nextval(rel->rd_rel->relfilenode, cons_autoinc->next);
} else {

View File

@ -746,6 +746,14 @@ extern inline bool CheckPluginReplaceNull()
((replaceNullOrNotFunc)(u_sess->hook_cxt.replaceNullOrNotHook))() : false;
}
typedef bool (*noAutoValueOnZeroFunc)();
extern inline bool CheckPluginNoAutoValueOnZero()
{
return u_sess->hook_cxt.noAutoValueOnZeroHook != NULL ?
((noAutoValueOnZeroFunc)(u_sess->hook_cxt.noAutoValueOnZeroHook))() : false;
}
// AutoMutexLock
// Auto object for non-recursive pthread_mutex_t lock
//

View File

@ -2959,6 +2959,7 @@ typedef struct knl_u_hook_context {
void *pluginPlannerHook;
void *groupingplannerHook;
void *replaceNullOrNotHook;
void *noAutoValueOnZeroHook;
void *nullsMinimalPolicyHook;
void *getIgnoreKeywordTokenHook;
void *modifyTypeForPartitionKeyHook;