--- mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_client_udfs.cpp	2022-11-03 11:07:25.000000000 +0100
+++ mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_client_udfs.cpp	2023-01-11 10:44:06.424232310 +0100
@@ -97,8 +97,10 @@
     std::string pstr(parameter);
     boost::algorithm::to_lower(pstr);
 
-    if (get_fe_conn_info_ptr() == NULL)
+    if (get_fe_conn_info_ptr() == NULL) {
       set_fe_conn_info_ptr((void*)new cal_connection_info());
+      thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+    }
 
     cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
     idbassert(ci != 0);
@@ -196,8 +198,10 @@
       const char* calgetstats(UDF_INIT* initid, UDF_ARGS* args, char* result, unsigned long* length,
                               char* is_null, char* error)
   {
-    if (get_fe_conn_info_ptr() == NULL)
+    if (get_fe_conn_info_ptr() == NULL) {
       set_fe_conn_info_ptr((void*)new cal_connection_info());
+      thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+    }
 
     cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -246,8 +250,10 @@
 #endif
       long long calsettrace(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* error)
   {
-    if (get_fe_conn_info_ptr() == NULL)
+    if (get_fe_conn_info_ptr() == NULL) {
       set_fe_conn_info_ptr((void*)new cal_connection_info());
+      thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+    }
 
     cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -456,8 +462,10 @@
   {
     THD* thd = current_thd;
 
-    if (get_fe_conn_info_ptr() == NULL)
+    if (get_fe_conn_info_ptr() == NULL) {
       set_fe_conn_info_ptr((void*)new cal_connection_info());
+      thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+    }
 
     cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
     execplan::CalpontSystemCatalog::TableName tableName;
@@ -533,8 +541,10 @@
       const char* calcleartablelock(UDF_INIT* initid, UDF_ARGS* args, char* result, unsigned long* length,
                                     char* is_null, char* error)
   {
-    if (get_fe_conn_info_ptr() == NULL)
+    if (get_fe_conn_info_ptr() == NULL) {
       set_fe_conn_info_ptr((void*)new cal_connection_info());
+      thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+    }
 
     cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
     long long lockID = *reinterpret_cast<long long*>(args->args[0]);
@@ -716,8 +726,10 @@
       }
     }
 
-    if (get_fe_conn_info_ptr() == NULL)
+    if (get_fe_conn_info_ptr() == NULL) {
       set_fe_conn_info_ptr((void*)new cal_connection_info());
+      thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+    }
 
     cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -809,8 +821,10 @@
       const char* calgetsqlcount(UDF_INIT* initid, UDF_ARGS* args, char* result, unsigned long* length,
                                  char* is_null, char* error)
   {
-    if (get_fe_conn_info_ptr() == NULL)
+    if (get_fe_conn_info_ptr() == NULL) {
       set_fe_conn_info_ptr((void*)new cal_connection_info());
+      thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+    }
 
     cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
     idbassert(ci != 0);
--- mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_ddl.cpp	2022-11-03 11:07:25.000000000 +0100
+++ mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_ddl.cpp	2023-01-11 10:47:12.182317826 +0100
@@ -52,6 +52,7 @@
 #include "ha_mcs_sysvars.h"
 #include "idb_mysql.h"
 
+#include "ha_mcs.h"
 #include "ha_mcs_impl_if.h"
 using namespace cal_impl_if;
 
@@ -775,8 +776,10 @@
   int rc = 0;
   parser.Parse(ddlStatement.c_str());
 
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
--- mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_execplan.cpp	2022-11-03 11:07:25.000000000 +0100
+++ mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_execplan.cpp	2023-01-11 10:50:33.268195824 +0100
@@ -1885,8 +1885,10 @@
     }
   }
 
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   if (ifp->functype() == Item_func::BETWEEN)
   {
@@ -2784,8 +2786,10 @@
   thd->raise_error_printf(errcode, errmsg.c_str());
 
   // reset expressionID
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
   ci->expressionId = 0;
@@ -3553,8 +3557,10 @@
 
 ArithmeticColumn* buildArithmeticColumn(Item_func* item, gp_walk_info& gwi, bool& nonSupport)
 {
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -3814,8 +3820,10 @@
 
 ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& nonSupport, bool selectBetweenIn)
 {
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -4412,8 +4420,10 @@
 
 FunctionColumn* buildCaseFunction(Item_func* item, gp_walk_info& gwi, bool& nonSupport)
 {
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -4838,8 +4848,10 @@
   vector<SRCP> orderCols;
   ConstArgParam constArgParam;
 
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
--- mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_impl.cpp	2022-11-03 11:07:25.000000000 +0100
+++ mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_impl.cpp	2023-01-12 22:32:09.174563639 +0100
@@ -775,8 +775,10 @@
 
 uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, const std::vector<COND*>& condStack)
 {
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -2072,8 +2074,10 @@
   query.assign(idb_mysql_query_str(thd));
   caep->data(query);
 
-  if (!get_fe_conn_info_ptr())
+  if (!get_fe_conn_info_ptr()) {
     set_fe_conn_info_ptr(reinterpret_cast<void*>(new cal_connection_info(), thd));
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
   idbassert(ci != 0);
@@ -2268,8 +2272,10 @@
   boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID);
   csc->identity(CalpontSystemCatalog::FE);
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -2592,8 +2598,10 @@
   //    if (MIGR::infinidb_vtable.impossibleWhereOnUnion)
   //        return HA_ERR_END_OF_FILE;
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -2678,6 +2686,7 @@
   {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
     ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
+    thd_set_ha_data(thd, mcs_hton, ci);
   }
 
   if (thd->killed == KILL_QUERY || thd->killed == KILL_QUERY_HARD)
@@ -2775,8 +2784,10 @@
 {
   THD* thd = current_thd;
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -2817,8 +2828,10 @@
   if (!memcmp((uchar*)name, tmp_file_prefix, tmp_file_prefix_length))
     return 0;
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -2880,8 +2893,10 @@
     return ER_CHECK_NOT_IMPLEMENTED;
   }
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -2931,8 +2946,10 @@
 
 int ha_mcs_impl_update_row()
 {
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
   int rc = ci->rc;
@@ -2945,8 +2962,10 @@
 
 int ha_mcs_impl_delete_row()
 {
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
   int rc = ci->rc;
@@ -2964,8 +2983,10 @@
   if (thd->slave_thread && !get_replication_slave(thd))
     return;
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -3518,8 +3539,10 @@
 
   std::string aTmpDir(startup::StartUp::tmpDir());
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -3669,7 +3692,12 @@
         }
         else
         {
-          ha_mcs_impl::log_this(thd, "End SQL statement with error", logging::LOG_TYPE_DEBUG,
+          ostringstream oss;
+          oss << "End SQL statement with error, rc=" << rc
+              << ", aPid=" << aPid
+              << ", WIF=" << WIFEXITED(aStatus)
+              << ", WEXIT=" << WEXITSTATUS(aStatus);
+          ha_mcs_impl::log_this(thd, oss.str().c_str(), logging::LOG_TYPE_DEBUG,
                                 tid2sid(thd->thread_id));
         }
 
@@ -3756,8 +3784,10 @@
 
 int ha_mcs_impl_commit(handlerton* hton, THD* thd, bool all)
 {
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -3789,8 +3819,10 @@
 
 int ha_mcs_impl_rollback(handlerton* hton, THD* thd, bool all)
 {
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -3848,6 +3880,10 @@
     ci->cal_conn_hndl = 0;
   }
 
+  delete ci;
+  set_fe_conn_info_ptr(nullptr, thd);
+  thd_set_ha_data(thd, hton, nullptr);
+
   return rc;
 }
 
@@ -3855,8 +3891,10 @@
 {
   IDEBUG(cout << "ha_mcs_impl_rename_table: " << from << " => " << to << endl);
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -3899,8 +3937,10 @@
   alias.assign(table->alias.ptr(), table->alias.length());
   IDEBUG(cout << "ha_mcs_impl_cond_push: " << alias << endl);
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -4006,8 +4046,10 @@
   alias.assign(table->alias.ptr(), table->alias.length());
   IDEBUG(cout << "external_lock for " << alias << endl);
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -4169,8 +4211,10 @@
   boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID);
   csc->identity(CalpontSystemCatalog::FE);
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -4586,8 +4630,10 @@
   if (isMCSTableUpdate(thd) || isMCSTableDelete(thd))
     return HA_ERR_END_OF_FILE;
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -4667,6 +4713,7 @@
   {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
     ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
+    thd_set_ha_data(thd, mcs_hton, ci);
   }
 
   if (((thd->lex)->sql_command == SQLCOM_INSERT) || ((thd->lex)->sql_command == SQLCOM_INSERT_SELECT))
@@ -4870,8 +4917,10 @@
   boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID);
   csc->identity(CalpontSystemCatalog::FE);
 
-  if (!get_fe_conn_info_ptr())
+  if (!get_fe_conn_info_ptr()) {
     set_fe_conn_info_ptr(reinterpret_cast<void*>(new cal_connection_info(), thd));
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -5271,8 +5320,10 @@
 
   int rc = HA_ERR_END_OF_FILE;
 
-  if (get_fe_conn_info_ptr() == nullptr)
+  if (get_fe_conn_info_ptr() == nullptr) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
--- mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_sysvars.cpp	2022-11-03 11:07:25.000000000 +0100
+++ mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_mcs_sysvars.cpp	2023-01-12 22:32:17.562470314 +0100
@@ -233,12 +233,10 @@
 
 void set_fe_conn_info_ptr(void* ptr, THD* thd)
 {
-  if (current_thd == NULL && thd == NULL)
-  {
-    return;
-  }
+  if (thd == NULL) thd = current_thd;
+  if (thd == NULL) return;
 
-  THDVAR(current_thd, fe_conn_info_ptr) = (uint64_t)(ptr);
+  THDVAR(thd, fe_conn_info_ptr) = (uint64_t)(ptr);
 }
 
 ulonglong get_original_optimizer_flags(THD* thd)
--- mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_pseudocolumn.cpp	2022-11-03 11:07:25.000000000 +0100
+++ mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_pseudocolumn.cpp	2023-01-11 10:37:01.356327071 +0100
@@ -20,6 +20,7 @@
 #include "functor.h"
 #include "functor_str.h"
 
+#include "ha_mcs.h"
 #include "ha_mcs_impl_if.h"
 #include "ha_mcs_sysvars.h"
 using namespace cal_impl_if;
@@ -53,8 +54,10 @@
 
 int64_t idblocalpm()
 {
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -477,8 +480,10 @@
 execplan::ReturnedColumn* buildPseudoColumn(Item* item, gp_walk_info& gwi, bool& nonSupport,
                                             uint32_t pseudoType)
 {
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
--- mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_window_function.cpp	2022-11-03 11:07:25.000000000 +0100
+++ mariadb-10.6.11/storage/columnstore/columnstore/dbcon/mysql/ha_window_function.cpp	2023-01-11 10:39:34.238915057 +0100
@@ -30,6 +30,7 @@
 #include "idb_mysql.h"
 #include "ha_mcs_impl_if.h"
 #include "ha_mcs_sysvars.h"
+#include "ha_mcs.h"
 
 #include "arithmeticcolumn.h"
 #include "arithmeticoperator.h"
@@ -95,8 +96,10 @@
 }
 ReturnedColumn* buildBoundExp(WF_Boundary& bound, SRCP& order, gp_walk_info& gwi)
 {
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
@@ -302,8 +305,10 @@
   // String str;
   // item->print(&str, QT_INFINIDB_NO_QUOTE);
   // cout << str.c_ptr() << endl;
-  if (get_fe_conn_info_ptr() == NULL)
+  if (get_fe_conn_info_ptr() == NULL) {
     set_fe_conn_info_ptr((void*)new cal_connection_info());
+    thd_set_ha_data(current_thd, mcs_hton, get_fe_conn_info_ptr());
+  }
 
   cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(get_fe_conn_info_ptr());
 
