@@ -4210,15 +4210,32 @@ bool PgSQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
42104210
42114211 int idx = PGSQL_NAME_LAST_HIGH_WM;
42124212 for (int i = 0 ; i < PGSQL_NAME_LAST_HIGH_WM; i++) {
4213+ // skip low water mark
4214+ if (i == PGSQL_NAME_LAST_LOW_WM) continue ;
4215+
42134216 if (variable_name_exists (pgsql_tracked_variables[i], var.c_str ()) == true ) {
42144217 idx = i;
42154218 break ;
42164219 }
42174220 }
42184221 if (idx != PGSQL_NAME_LAST_HIGH_WM) {
4219-
4222+ uint32_t current_hash = pgsql_variables. client_get_hash ( this , idx);
42204223 if ((value1.size () == sizeof (" DEFAULT" ) - 1 ) && strncasecmp (value1.c_str (), (char *)" DEFAULT" ,sizeof (" DEFAULT" )-1 ) == 0 ) {
4221- std::tie (value1, std::ignore) = client_myds->myconn ->get_startup_parameter_and_hash ((enum pgsql_variable_name)idx);
4224+ auto [value, hash] = client_myds->myconn ->get_startup_parameter_and_hash ((enum pgsql_variable_name)idx);
4225+ if (hash == 0 ) {
4226+ if (current_hash != 0 ) {
4227+ proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Resetting connection variable %s to DEFAULT\n " , var.c_str ());
4228+ pgsql_variables.client_reset_value (this , idx, true );
4229+ }
4230+ client_myds->DSS = STATE_QUERY_SENT_NET;
4231+ unsigned int nTrx = NumActiveTransactions ();
4232+ const char trx_state = (nTrx ? ' T' : ' I' );
4233+ client_myds->myprot .generate_ok_packet (true , true , NULL , 0 , dig, trx_state, NULL , param_status);
4234+ RequestEnd (NULL );
4235+ l_free (pkt->size , pkt->ptr );
4236+ return true ;
4237+ }
4238+ value1 = value;
42224239 }
42234240
42244241 char * transformed_value = nullptr ;
@@ -4259,10 +4276,10 @@ bool PgSQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
42594276 return true ;
42604277 }
42614278 }
4262-
4263- proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Changing connection %s to %s\n " , var.c_str (), value1.c_str ());
4279+
42644280 uint32_t var_hash_int = SpookyHash::Hash32 (value1.c_str (), value1.length (), 10 );
4265- if (pgsql_variables.client_get_hash (this , idx) != var_hash_int) {
4281+ if (current_hash != var_hash_int) {
4282+ proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Changing connection %s to %s\n " , var.c_str (), value1.c_str ());
42664283 if (!pgsql_variables.client_set_value (this , idx, value1.c_str (), true )) {
42674284 return false ;
42684285 }
@@ -4445,8 +4462,7 @@ bool PgSQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
44454462 std::string value1 = *values;
44464463 proxy_debug (PROXY_DEBUG_MYSQL_COM, 5 , " Processing SET %s value %s\n " , var.c_str (), value1.c_str ());
44474464#endif // DEBUG
4448- }
4449- else {
4465+ } else {
44504466 // At this point the variable is unknown to us, or it's a user variable
44514467 // prefixed by '@', in both cases, we should fail to parse. We don't
44524468 // fail inmediately so we can anyway keep track of the other variables
@@ -4638,10 +4654,10 @@ bool PgSQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
46384654
46394655 const char * name = pgsql_tracked_variables[idx].set_variable_name ;
46404656 auto [value, hash] = client_myds->myconn ->get_startup_parameter_and_hash ((enum pgsql_variable_name)idx);
4641-
4642- proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Changing connection %s to %s \n " , name, value );
4643- uint32_t var_hash_int = ((hash != 0 ) ? hash : SpookyHash::Hash32 (value, strlen (value), 10 ));
4644- if (pgsql_variables. client_get_hash ( this , idx) != var_hash_int) {
4657+ // hash can never be 0 for critical variables
4658+ uint32_t current_hash = pgsql_variables. client_get_hash ( this , idx );
4659+ if (current_hash != hash) {
4660+ proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Changing connection %s to %s \n " , name, value);
46454661 if (!pgsql_variables.client_set_value (this , idx, value, false )) {
46464662 return false ;
46474663 }
@@ -4652,21 +4668,19 @@ bool PgSQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
46524668 }
46534669
46544670 for (int idx : client_myds->myconn ->dynamic_variables_idx ) {
4655- assert (idx < PGSQL_NAME_LAST_HIGH_WM);
46564671 const char * name = pgsql_tracked_variables[idx].set_variable_name ;
46574672 auto [value, hash] = client_myds->myconn ->get_startup_parameter_and_hash ((enum pgsql_variable_name)idx);
4658- proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Changing connection %s to %s\n " , name, value);
4659- uint32_t var_hash_int = ((hash != 0 ) ? hash : SpookyHash::Hash32 (value, strlen (value), 10 ));
4660- if (pgsql_variables.client_get_hash (this , idx) != var_hash_int) {
4673+ uint32_t current_hash = pgsql_variables.client_get_hash (this , idx);
4674+ if (hash == 0 && current_hash != 0 ) {
4675+ proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Resetting connection variable %s to DEFAULT\n " , name);
4676+ pgsql_variables.client_reset_value (this , idx, false );
4677+ } else if (hash != 0 && current_hash != hash) {
4678+ proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Changing connection %s to %s\n " , name, value);
46614679 if (!pgsql_variables.client_set_value (this , idx, value, false )) {
46624680 return false ;
46634681 }
4664- if (IS_PGTRACKED_VAR_OPTION_SET_PARAM_STATUS (pgsql_tracked_variables[idx])) {
4665- param_status.emplace_back (name, value);
4666- }
46674682 }
46684683 }
4669-
46704684 client_myds->myconn ->reorder_dynamic_variables_idx ();
46714685
46724686 } else if (std::find (pgsql_variables.ignore_vars .begin (), pgsql_variables.ignore_vars .end (), nq) != pgsql_variables.ignore_vars .end ()) {
@@ -4675,10 +4689,8 @@ bool PgSQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
46754689 proxy_debug (PROXY_DEBUG_MYSQL_COM, 5 , " Processing RESET %s\n " , nq.c_str ());
46764690#endif // DEBUG
46774691 } else {
4678-
46794692 int idx = PGSQL_NAME_LAST_HIGH_WM;
46804693 for (int i = 0 ; i < PGSQL_NAME_LAST_HIGH_WM; i++) {
4681-
46824694 if (i == PGSQL_NAME_LAST_LOW_WM)
46834695 continue ;
46844696
@@ -4687,18 +4699,20 @@ bool PgSQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
46874699 break ;
46884700 }
46894701 }
4690-
46914702 if (idx != PGSQL_NAME_LAST_HIGH_WM) {
46924703 const char * name = pgsql_tracked_variables[idx].set_variable_name ;
46934704 auto [value, hash] = client_myds->myconn ->get_startup_parameter_and_hash ((enum pgsql_variable_name)idx);
4694-
4695- uint32_t var_hash_int = ((hash != 0 ) ? hash : SpookyHash::Hash32 (value, strlen (value), 10 ));
4696- if (pgsql_variables.client_get_hash (this , idx) != var_hash_int) {
4705+ uint32_t current_hash = pgsql_variables.client_get_hash (this , idx);
4706+ // Reset to default if hash is zero, means startup parameter is not set
4707+ if (hash == 0 && current_hash != 0 ) {
4708+ proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Resetting connection variable %s to DEFAULT\n " , name);
4709+ pgsql_variables.client_reset_value (this , idx, true );
4710+ } else if (hash != 0 && current_hash != hash) {
4711+ proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Changing connection %s to %s\n " , name, value);
46974712 if (!pgsql_variables.client_set_value (this , idx, value, true )) {
46984713 return false ;
46994714 }
47004715 if (IS_PGTRACKED_VAR_OPTION_SET_PARAM_STATUS (pgsql_tracked_variables[idx])) {
4701- proxy_debug (PROXY_DEBUG_MYSQL_COM, 8 , " Changing connection %s to %s\n " , name, value);
47024716 param_status.emplace_back (name, value);
47034717 }
47044718 }
0 commit comments