void ob_dec_phy_operator_stat(ObPhyOperatorType type)
 {
   OB_ASSERT(type >= PHY_INVALID && type < PHY_END);
   TBSYS_LOG(DEBUG, "ob_dec_phy_operator_stat %s num=%lu",
       ob_phy_operator_type_str(type), PHY_OP_STAT[type]);
   atomic_dec(&PHY_OP_STAT[type]);
 }
Пример #2
0
 int ObStatManager::set_value(const uint64_t mod_id, const uint64_t table_id, const int32_t index, const int64_t value)
 {
   int ret = OB_ERROR;
   bool need_add_new = true;
   OB_ASSERT(mod_id < OB_MAX_MOD_NUMBER);
   for (int32_t i = 0; table_id != OB_INVALID_ID && mod_id != OB_INVALID_ID && i < table_stats_[mod_id].get_array_index(); i++)
   {
     if (data_holder_[mod_id][i].get_table_id() == table_id)
     {
       need_add_new = false;
       ret = data_holder_[mod_id][i].set_value(index, value);
     }
   }
   if (need_add_new && table_id != OB_INVALID_ID && mod_id != OB_INVALID_ID)
   {
     ObStat stat;
     stat.set_mod_id(mod_id);
     stat.set_table_id(table_id);
     ret = stat.set_value(index, value);
     if (OB_SUCCESS == ret)
     {
       if ((ret = add_new_stat(stat)) == OB_ENTRY_EXIST)
       {
         ret = set_value(mod_id, table_id, index, value);
       }
     }
   }
   return ret;
 }
Пример #3
0
        /**************************************************
        Funtion     :   make_exec_plan_unit_string
        Author      :   qinbo
        Date        :   2013.12.9
        Description :   make select sql
        Input       :   ResultPlan& result_plan, 
                        string &where_conditions, 
                        vector<schema_shard*> shard_info,
                        string &assembled_sql
                        
        Output      :   
         **************************************************/
        int64_t ObDeleteStmt::make_exec_plan_unit_string(ResultPlan& result_plan, string where_conditions, vector<schema_shard*> &shard_info,string &assembled_sql)
        {
            int& ret = result_plan.err_stat_.err_code_ = OB_SUCCESS;
            ObLogicalPlan* logical_plan = static_cast<ObLogicalPlan*> (result_plan.plan_tree_);
            OB_ASSERT(NULL != logical_plan);

            assembled_sql.append("DELETE FROM ");
            string table_name = ObStmt::get_table_item_by_id(table_id_)->table_name_ ;
            if (table_name != shard_info.at(0)->get_table_name())
            {
                assembled_sql.append(shard_info.at(0)->get_shard_name());
            }
            else
            {
                assembled_sql.append(table_name);
            }

            if (where_conditions.empty())
            {
                make_delete_where_string(result_plan, assembled_sql);
            }
            else
            {
                assembled_sql.append(where_conditions);
                assembled_sql.append(" ");
            }
            return ret;
        }
Пример #4
0
 static int mtime_bool(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObModifyTimeType);
     out.set_bool(static_cast<bool> (in.get_mtime()));
     return OB_SUCCESS;
 }
Пример #5
0
 static int ctime_float(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObCreateTimeType);
     out.set_float(static_cast<float> (in.get_ctime()));
     return OB_SUCCESS;
 }
Пример #6
0
 static int bool_ctime(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObBoolType);
     out.set_ctime(static_cast<ObCreateTime> (in.get_bool()));
     return OB_SUCCESS;
 }
Пример #7
0
 static int mtime_pdatetime(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObModifyTimeType);
     out.set_precise_datetime(static_cast<ObPreciseDateTime> (in.get_mtime()));
     return OB_SUCCESS;
 }
Пример #8
0
 static int ctime_datetime(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObCreateTimeType);
     out.set_datetime(static_cast<ObDateTime> (in.get_ctime() / 1000000L));
     return OB_SUCCESS;
 }
Пример #9
0
 static int double_int(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDoubleType);
     out.set_int(static_cast<int64_t> (in.get_double()));
     return OB_SUCCESS;
 }
Пример #10
0
 static int double_mtime(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDoubleType);
     out.set_mtime(static_cast<ObModifyTime> (in.get_double()));
     return OB_SUCCESS;
 }
Пример #11
0
 static int decimal_bool(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDecimalType);
     out.set_bool(!in.get_decimal().is_zero());
     return OB_SUCCESS;
 }
Пример #12
0
 static int float_double(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObFloatType);
     out.set_double(static_cast<double> (in.get_float()));
     return OB_SUCCESS;
 }
Пример #13
0
 static int int_datetime(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObIntType);
     out.set_datetime(static_cast<ObDateTime> (in.get_int()));
     return OB_SUCCESS;
 }
Пример #14
0
 static int bool_float(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObBoolType);
     out.set_float(static_cast<float> (in.get_bool()));
     return OB_SUCCESS;
 }
Пример #15
0
 static int int_varchar(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObIntType);
     ret = varchar_printf(out, "%ld", in.get_int());
     return ret;
 }
Пример #16
0
 static int int_decimal(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObIntType);
     ObNumber num;
     num.from(in.get_int());
     out.set_decimal(num); // @todo optimize
     return OB_SUCCESS;
 }
Пример #17
0
 static int mtime_decimal(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObModifyTimeType);
     ObNumber num;
     num.from(static_cast<int64_t> (in.get_mtime()));
     out.set_decimal(num);
     return OB_SUCCESS;
 }
Пример #18
0
 static int datetime_varchar(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDateTimeType);
     time_t t = static_cast<time_t> (in.get_datetime());
     struct tm gtm;
     localtime_r(&t, &gtm);
     ret = varchar_printf(out, "%04d-%02d-%02d %02d:%02d:%02d",
             gtm.tm_year + 1900, gtm.tm_mon + 1, gtm.tm_mday,
             gtm.tm_hour, gtm.tm_min, gtm.tm_sec);
     return ret;
 }
Пример #19
0
        /**************************************************
        Funtion     :   make_delete_table_string
        Author      :   qinbo
        Date        :   2013.10.31
        Description :   make select sql
        Input       :   ResultPlan& result_plan,
                        string &assembled_sql
        Output      :   
         **************************************************/
        int64_t ObDeleteStmt::make_delete_table_string(ResultPlan& result_plan, string &assembled_sql)
        {
            int& ret = result_plan.err_stat_.err_code_ = OB_SUCCESS;
            string assembled_sql_tmp;

            ObLogicalPlan* logical_plan = static_cast<ObLogicalPlan*> (result_plan.plan_tree_);
            OB_ASSERT(NULL != logical_plan);

            assembled_sql.append("DELETE FROM ");
            assembled_sql.append(ObStmt::get_table_item_by_id(table_id_)->table_name_);

            return ret;
        }
Пример #20
0
 static int varchar_datetime(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObVarcharType);
     int year = 0;
     int month = 0;
     int day = 0;
     int hour = 0;
     int minute = 0;
     int second = 0;
     ret = varchar_scanf(in, 6, "%4d-%2d-%2d %2d:%2d:%2d",
             &year, &month, &day,
             &hour, &minute, &second);
     if (OB_SUCCESS != ret)
     {
         year = month = day = hour = minute = second = 0;
         ret = varchar_scanf(in, 3, "%4d-%2d-%2d",
                 &year, &month, &day);
     }
     if (OB_SUCCESS != ret)
     {
         year = month = day = hour = minute = second = 0;
         ret = varchar_scanf(in, 3, "%2d:%2d:%2d",
                 &hour, &minute, &second);
     }
     if (OB_SUCCESS == ret)
     {
         struct tm gtm;
         memset(&gtm, 0, sizeof (gtm));
         gtm.tm_year = year - 1900;
         gtm.tm_mon = month - 1;
         gtm.tm_mday = day;
         gtm.tm_hour = hour;
         gtm.tm_min = minute;
         gtm.tm_sec = second;
         time_t t = mktime(&gtm);
         out.set_datetime(static_cast<ObDateTime> (t));
     }
     else
     {
         const string& varchar = in.get_varchar();
         jlog(WARNING, "failed to convert string `%.*s' to datetime type",
                 varchar.length(), varchar.data());
         out.set_datetime(static_cast<ObDateTime> (0));
         ret = OB_SUCCESS;
     }
     return ret;
 }
Пример #21
0
 static int bool_varchar(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObBoolType);
     string varchar;
     if (in.get_bool())
     {
         varchar.assign("true");
     }
     else
     {
         varchar.assign("false");
     }
     out.set_varchar(varchar);
     return OB_SUCCESS;
 }
Пример #22
0
 static int decimal_mtime(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDecimalType);
     int64_t i64 = 0;
     if (OB_SUCCESS != (ret = in.get_decimal().cast_to_int64(i64)))
     {
         jlog(WARNING, "failed to cast to int64, err=%d", ret);
     }
     else
     {
         out.set_mtime(static_cast<ObModifyTime> (i64));
     }
     return ret;
 }
Пример #23
0
 static int varchar_double(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObVarcharType);
     double value = 0.0;
     ret = varchar_scanf(in, 1, "%lf", &value);
     if (OB_SUCCESS == ret)
     {
         out.set_double(value);
     }
     else
     {
         out.set_double(0.0);
         ret = OB_SUCCESS;
     }
     return ret;
 }
Пример #24
0
 static int varchar_decimal(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObVarcharType);
     const string &varchar = in.get_varchar();
     ObNumber num;
     if (OB_SUCCESS != (ret = num.from(varchar.data(), varchar.length())))
     {
         jlog(WARNING, "failed to convert varchar to decimal, err=%d varchar=%.*s",
                 ret, varchar.length(), varchar.data());
     }
     else
     {
         out.set_decimal(num); // @todo optimize
     }
     return OB_SUCCESS;
 }
Пример #25
0
 static int decimal_double(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDecimalType);
     // decimal -> string -> float
     char buf[ObNumber::MAX_PRINTABLE_SIZE];
     memset(buf, 0, ObNumber::MAX_PRINTABLE_SIZE);
     in.get_decimal().to_string(buf, ObNumber::MAX_PRINTABLE_SIZE);
     double v = 0.0;
     if (1 == sscanf(buf, "%lf", &v))
     {
         out.set_double(v);
     }
     else
     {
         out.set_double(0.0);
     }
     return OB_SUCCESS;
 }
Пример #26
0
 static int decimal_varchar(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDecimalType);
     string varchar = out.get_varchar();
     if (varchar.length() < ObNumber::MAX_PRINTABLE_SIZE)
     {
         jlog(WARNING, "output buffer for varchar not enough, buf_len=%d", varchar.length());
         ret = OB_INVALID_ARGUMENT;
     }
     else
     {
         int64_t length = in.get_decimal().to_string((char*) varchar.data(), varchar.length());
         string varchar2(varchar);
         out.set_varchar(varchar2);
     }
     return ret;
 }
Пример #27
0
 static int double_decimal(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDoubleType);
     static const int64_t MAX_DOUBLE_PRINT_SIZE = 64;
     char buf[MAX_DOUBLE_PRINT_SIZE];
     snprintf(buf, MAX_DOUBLE_PRINT_SIZE, "%f", in.get_double());
     ObNumber num;
     if (OB_SUCCESS != (ret = num.from(buf)))
     {
         jlog(WARNING, "failed to convert float to decimal, err=%d", ret);
     }
     else
     {
         out.set_decimal(num);
     }
     return ret;
 }
Пример #28
0
 static int varchar_mtime(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObVarcharType);
     int64_t timestamp = 0;
     ret = varchar_timestamp(in, timestamp);
     if (OB_SUCCESS == ret)
     {
         out.set_mtime(static_cast<ObModifyTime> (timestamp));
     }
     else
     {
         const string& varchar = in.get_varchar();
         jlog(WARNING, "failed to convert string `%.*s' to modifytime type",
                 varchar.length(), varchar.data());
         out.set_mtime(static_cast<ObModifyTime> (0));
         ret = OB_SUCCESS;
     }
     return ret;
 }
Пример #29
0
        /**************************************************
        Funtion     :   make_delete_where_string
        Author      :   qinbo
        Date        :   2013.10.31
        Description :   make select sql
        Input       :   ResultPlan& result_plan,
                        string &assembled_sql
        Output      :   
         **************************************************/
        int64_t ObDeleteStmt::make_delete_where_string(ResultPlan& result_plan, string &assembled_sql)
        {
            uint32_t i = 0;
            int& ret = result_plan.err_stat_.err_code_ = OB_SUCCESS;
            string assembled_sql_tmp;
            ObSqlRawExpr* sql_expr = NULL;

            ObLogicalPlan* logical_plan = static_cast<ObLogicalPlan*> (result_plan.plan_tree_);
            OB_ASSERT(NULL != logical_plan);
            
            vector<uint64_t>& where_exprs = ObStmt::get_where_exprs();

            if (where_exprs.size() > 0)
            {
                assembled_sql.append(" WHERE ");
                for (i = 0; i < where_exprs.size(); i++)
                {
                    sql_expr = logical_plan->get_expr_by_id(where_exprs[i]);
                    if (NULL == sql_expr)
                    {
                        ret = JD_ERR_LOGICAL_PLAN_FAILD;
                        jlog(WARNING, "where expr error!!!");
                        return ret;
                    }

                    sql_expr->to_string(result_plan, assembled_sql_tmp);
                    assembled_sql.append(assembled_sql_tmp);
                    if (i != where_exprs.size() - 1)
                    {
                        assembled_sql.append(" AND ");
                    }
                    else
                    {
                        assembled_sql.append(" ");
                    }
                }
            }

            return ret;
        }
Пример #30
0
 static int varchar_bool(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObVarcharType);
     const string &varchar = in.get_varchar();
     bool value = false;
     if (varchar.data() != NULL && varchar.length() > 0)
     {
         static const int64_t len_true = strlen("true");
         static const int64_t len_t = strlen("T");
         static const int64_t len_yes = strlen("yes");
         static const int64_t len_y = strlen("y");
         if (varchar.length() == len_true
                 && 0 == strncasecmp(varchar.data(), "true", len_true))
         {
             value = true;
         }
         else if (varchar.length() == len_t
                 && 0 == strncasecmp(varchar.data(), "T", len_t))
         {
             value = true;
         }
         else if (varchar.length() == len_yes
                 && 0 == strncasecmp(varchar.data(), "yes", len_yes))
         {
             value = true;
         }
         else if (varchar.length() == len_y
                 && 0 == strncasecmp(varchar.data(), "y", len_y))
         {
             value = true;
         }
     }
     out.set_bool(value);
     return OB_SUCCESS;
 }