ob_result_set.h 26.9 KB
Newer Older
O
oceanbase-admin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
/**
 * Copyright (c) 2021 OceanBase
 * OceanBase CE is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#ifndef OCEANBASE_SQL_OB_RESULT_SET_H
#define OCEANBASE_SQL_OB_RESULT_SET_H
#include "share/ob_define.h"
#include "lib/container/ob_array.h"
#include "lib/container/ob_fast_array.h"
#include "lib/allocator/ob_mod_define.h"
#include "lib/utility/utility.h"
#include "lib/allocator/ob_malloc.h"
#include "lib/allocator/page_arena.h"
#include "lib/container/ob_2d_array.h"
#include "lib/timezone/ob_timezone_info.h"
#include "rpc/obmysql/ob_mysql_global.h"  // for EMySQLFieldType
#include "common/object/ob_obj_type.h"
#include "common/object/ob_object.h"
#include "common/row/ob_row.h"
#include "common/ob_string_buf.h"
#include "share/ob_srv_rpc_proxy.h"
#include "common/ob_field.h"
#include "share/ob_common_rpc_proxy.h"
#include "sql/optimizer/ob_log_plan_factory.h"
#include "sql/executor/ob_executor.h"
#include "sql/executor/ob_execute_result.h"
#include "sql/executor/ob_executor_rpc_impl.h"
#include "sql/executor/ob_executor_rpc_proxy.h"
#include "sql/executor/ob_cmd_executor.h"
#include "sql/engine/ob_exec_context.h"
#include "sql/ob_sql_trans_control.h"
#include "sql/ob_sql_partition_location_cache.h"

namespace oceanbase {
namespace obmysql {
class ObMySQLField;
}
namespace sql {
class ObSQLSessionInfo;
class ObPhysicalPlan;
class ObLogPlan;
struct ObPsStoreItemValue;
class ObIEndTransCallback;
typedef common::ObFastArray<int64_t, OB_DEFAULT_SE_ARRAY_COUNT> IntFastArray;
typedef common::ObFastArray<uint64_t, OB_DEFAULT_SE_ARRAY_COUNT> UIntFastArray;
typedef common::ObFastArray<ObRawExpr*, OB_DEFAULT_SE_ARRAY_COUNT> RawExprFastArray;
// query result set
class ObResultSet {
G
gm 已提交
57
public:
O
oceanbase-admin 已提交
58
  class ExternalRetrieveInfo {
G
gm 已提交
59
  public:
O
oceanbase-admin 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    ExternalRetrieveInfo(common::ObIAllocator& allocator)
        : allocator_(allocator),
          external_params_(allocator),
          into_exprs_(allocator),
          ref_objects_(allocator),
          route_sql_(),
          is_select_for_update_(false),
          has_hidden_rowid_(false)
    {}
    virtual ~ExternalRetrieveInfo()
    {}

    int build(ObStmt& stmt, ObSQLSessionInfo& session_info,
        common::ObIArray<std::pair<ObRawExpr*, ObConstRawExpr*>>& param_info);
    int check_into_exprs(ObStmt& stmt, ObArray<ObDataType>& basic_types, ObBitSet<>& basic_into);
    const ObIArray<ObRawExpr*>& get_into_exprs() const
    {
      return into_exprs_;
    }
    int recount_dynamic_param_info(ObIArray<std::pair<ObRawExpr*, ObConstRawExpr*>>& param_info);

    common::ObIAllocator& allocator_;
    common::ObFixedArray<ObRawExpr*, common::ObIAllocator> external_params_;
    common::ObFixedArray<ObRawExpr*, common::ObIAllocator> into_exprs_;
    common::ObFixedArray<share::schema::ObSchemaObjVersion, common::ObIAllocator> ref_objects_;
    ObString route_sql_;
    bool is_select_for_update_;
    bool has_hidden_rowid_;
  };

  enum PsMode {
    NO_PS = 0,  // not PS protocol
    SIMPLE_PS,  // only support the pl under mysql mode
    STD_PS,     // The standard PS, work for the oracle mode, and for the ps protocol of the mysql mode
  };

  typedef common::ObFastArray<ObPhysicalPlan*, 8> CandidatePlanArray;

G
gm 已提交
98
public:
O
oceanbase-admin 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
  explicit ObResultSet(ObSQLSessionInfo& session);
  explicit ObResultSet(ObSQLSessionInfo& session, common::ObIAllocator& allocator);
  virtual ~ObResultSet();

  static ObResultSet* alloc(ObSQLSessionInfo& session, common::ObIAllocator& allocator);
  static void free(ObResultSet* rs);
  static ObResultSet* assign(ObResultSet* other);
  /// open and execute the execution plan
  /// @note SHOULD be called for all statement even if there is no result rows
  int sync_open();
  int execute();
  int open();
  /// get the next result row
  /// @return OB_ITER_END when no more data available
  int get_next_row(const common::ObNewRow*& row);
  /// close the result set after get all the rows
  int close(bool need_retry = false);
  /// get number of rows affected by INSERT/UPDATE/DELETE
  int64_t get_affected_rows() const;
  int64_t get_return_rows() const
  {
    return return_rows_;
  }
  /// get warning count during the execution
  int64_t get_warning_count() const;
  /// get statement id
  uint64_t get_statement_id() const;
  int64_t get_sql_id() const
  {
    return sql_id_;
  };
  /// get the server's error message
  const char* get_message() const;
  /// get the server's error code
  int get_errcode() const;
  /**
   * get the row description
   * the row desc should have been valid after open() and before close()
   * @pre call open() first
   */
  int get_row_desc(const common::ObRowDesc*& row_desc) const;
  /// get the field columns
  const common::ColumnsFieldIArray* get_field_columns() const;
  const common::ParamsFieldIArray* get_param_fields() const;

  uint64_t get_field_cnt() const;

  void set_p_param_fileds(common::ParamsFieldIArray* p_param_columns)
  {
    p_param_columns_ = p_param_columns;
  }

  void set_p_column_fileds(common::ColumnsFieldIArray* p_columns_field)
  {
    p_field_columns_ = p_columns_field;
  }
  void set_exec_result(ObIExecuteResult* exec_result)
  {
    exec_result_ = exec_result;
  }
  ExternalRetrieveInfo& get_external_retrieve_info()
  {
    return external_retrieve_info_;
  }
  ObIArray<ObRawExpr*>& get_external_params();
  ObIArray<ObRawExpr*>& get_into_exprs();
  common::ObIArray<share::schema::ObSchemaObjVersion>& get_ref_objects();
  const common::ObIArray<share::schema::ObSchemaObjVersion>& get_ref_objects() const;
  ObString& get_route_sql();
  bool get_is_select_for_update();
  inline bool has_hidden_rowid();
  /// whether the result is with rows (true for SELECT statement)
  bool is_with_rows() const;
  // tell mysql if need to do async end trans
  bool need_end_trans_callback() const;
  bool need_end_trans() const;
  /// get physical plan
  // ObPhysicalPlan *get_physical_plan();
  ObPhysicalPlan*& get_physical_plan();
  /// to string
  int64_t to_string(char* buf, const int64_t buf_len) const;
  /// whether the statement is a prepared statment
  bool is_prepare_stmt() const;
  /// whether the statement is SHOW WARNINGS
  bool is_show_warnings() const;
  bool is_compound_stmt() const;
  bool is_dml_stmt(stmt::StmtType stmt_type) const;
  bool is_pl_stmt(stmt::StmtType stmt_type) const;
  stmt::StmtType get_stmt_type() const;
  stmt::StmtType get_inner_stmt_type() const;
  stmt::StmtType get_literal_stmt_type() const;
  int64_t get_query_string_id() const;
L
lck0 已提交
191
  static void refresh_location_cache(ObTaskExecutorCtx &task_exec_ctx, bool is_nonblock, int err);
O
oceanbase-admin 已提交
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
  int refresh_location_cache(bool is_nonblock);
  int check_and_nonblock_refresh_location_cache();
  bool need_execute_remote_sql_async() const
  {
    return get_exec_context().use_remote_sql() && !is_inner_result_set_;
  }

  ////////////////////////////////////////////////////////////////
  // the following methods are used by the ob_sql module internally
  /// add a field columns
  int init()
  {
    return common::OB_SUCCESS;
  }
  common::ObIAllocator& get_mem_pool()
  {
    return mem_pool_;
  }
  ObExecContext& get_exec_context()
  {
    return exec_ctx_ != nullptr ? *exec_ctx_ : inner_exec_ctx_;
  }
  void set_exec_context(ObExecContext& exec_ctx)
  {
    exec_ctx_ = &exec_ctx;
  }
  const ObExecContext& get_exec_context() const
  {
    return exec_ctx_ != nullptr ? *exec_ctx_ : inner_exec_ctx_;
  }
  int reserve_field_columns(int64_t size)
  {
    return field_columns_.reserve(size);
  };
  int reserve_param_columns(int64_t size)
  {
    return param_columns_.reserve(size);
  };
  int add_field_column(const common::ObField& field);
  int add_param_column(const common::ObField& field);
  int from_plan(const ObPhysicalPlan& phy_plan, const common::ObIArray<ObPCParam*>& raw_params);
  int to_plan(const bool is_ps_mode, ObPhysicalPlan* phy_plan);
  const common::ObString& get_statement_name() const;
  void set_statement_id(const uint64_t stmt_id);
  void set_statement_name(const common::ObString name);
  void set_message(const char* message);
  bool need_rollback(int ret, int errcode, bool is_error_ignored) const;
  void set_errcode(int code);
  void set_affected_rows(const int64_t& affected_rows);
  int set_mysql_info();
  void set_last_insert_id_session(const uint64_t last_insert_id);
  uint64_t get_last_insert_id_session();
  void set_last_insert_id_to_client(const uint64_t last_insert_id);
  uint64_t get_last_insert_id_to_client();
  void set_warning_count(const int64_t& warning_count);
  void set_physical_plan(const CacheRefHandleID ref_handle, ObPhysicalPlan* physical_plan);
  void set_cmd(ObICmd* cmd);
  bool is_end_trans_async();
  void set_end_trans_async(bool is_async);
  void set_mysql_end_trans_callback(ObIEndTransCallback* cb);
  void fields_clear();
  void set_stmt_type(stmt::StmtType stmt_type);
  void set_inner_stmt_type(stmt::StmtType stmt_type);
  void set_literal_stmt_type(stmt::StmtType stmt_type);
  void set_compound_stmt(bool compound);
  ObSQLSessionInfo& get_session()
  {
    return my_session_;
  }
  const ObSQLSessionInfo& get_session() const
  {
    return my_session_;
  };
  void set_ps_transformer_allocator(common::ObArenaAllocator* allocator);
  void set_query_string_id(int64_t query_string_id);
  void set_sql_id(int64_t sql_id)
  {
    sql_id_ = sql_id;
  };
  void set_begin_timestamp(const int64_t begin_ts);
  int start_stmt();
  int end_stmt(const bool is_rollback);
  int start_trans();
  int end_trans(const bool is_rollback);
  int start_participant();
  int end_participant(const bool is_rollback);
  void set_is_from_plan_cache(bool is_from_plan_cache)
  {
    is_from_plan_cache_ = is_from_plan_cache;
  }
  void set_is_inner_result_set(const bool v)
  {
    is_inner_result_set_ = v;
  }
  bool get_is_from_plan_cache() const
  {
    return is_from_plan_cache_;
  }
  const ObICmd* get_cmd() const
  {
    return cmd_;
  }
  ObICmd* get_cmd()
  {
    return cmd_;
  }
  void init_partition_location_cache(share::ObIPartitionLocationCache* loc_cache, common::ObAddr self_addr,
      share::schema::ObSchemaGetterGuard* schema_guard)
  {
    sql_location_cache_.init(loc_cache, self_addr, schema_guard);
    self_addr_ = self_addr;
  }
  ObSqlPartitionLocationCache& get_partition_location_cache()
  {
    return sql_location_cache_;
  }
  void set_has_top_limit(const bool has_limit);
  void set_is_calc_found_rows(const bool is_calc_found_rows);
  bool get_has_top_limit() const;
  bool is_calc_found_rows() const;
  // Determine whether an asynchronous EndTrans request has been submitted.
  // If the request has been submitted, the client needs to wait for the asynchronous response packet.
  // ref: obmp_query.cpp, ob_mysql_end_trans_callback.cpp
  bool is_async_end_trans_submitted() const
  {
    return get_exec_context().get_trans_state().is_end_trans_executed();
  }
  inline TransState& get_trans_state()
  {
    return get_exec_context().get_trans_state();
  }
  inline const TransState& get_trans_state() const
  {
    return get_exec_context().get_trans_state();
  }
  int update_last_insert_id();
  int update_is_result_accurate();
  bool is_ps_protocol() const
  {
    return STD_PS == ps_protocol_;
  };
  void set_ps_protocol()
  {
    ps_protocol_ = STD_PS;
  }
  bool is_simple_ps_protocol() const
  {
    return SIMPLE_PS == ps_protocol_;
  };
  void set_simple_ps_protocol()
  {
    ps_protocol_ = SIMPLE_PS;
  }
  int get_read_consistency(ObConsistencyLevel& consistency);
  void set_has_global_variable(bool has_global_variable)
  {
    has_global_variable_ = has_global_variable;
  }
  bool has_global_variable() const
  {
    return has_global_variable_;
  }
  void set_returning(bool is_returning)
  {
    is_returning_ = is_returning;
  }
  bool is_returning() const
  {
    return is_returning_;
  }
  void set_user_sql(bool is_user_sql)
  {
    is_user_sql_ = is_user_sql;
  }
  bool is_user_sql() const
  {
    return is_user_sql_;
  }

  // Fill parameter information with the field name
  // noted that, except for cname_, the rest of the strings are all copied from the plan.
  // The memory of cname_ is allocated by the allocator of result_set
  int construct_field_name(const common::ObIArray<ObPCParam*>& raw_params, const bool is_first_parse);

  int construct_display_field_name(
      common::ObField& field, const ObIArray<ObPCParam*>& raw_params, const bool is_first_parse);

  // The field columns in the deep copy plan are stored in the field_columns_ member
  int copy_field_columns(const ObPhysicalPlan& plan);
  bool has_implicit_cursor() const;
  int switch_implicit_cursor();
  void reset_implicit_cursor_idx()
  {
    if (get_exec_context().get_physical_plan_ctx() != nullptr)
      get_exec_context().get_physical_plan_ctx()->set_cur_stmt_id(0);
  }
  bool is_cursor_end() const;

  inline void set_ref_handle(const CacheRefHandleID handle_id)
  {
    ref_handle_id_ = handle_id;
  }
  inline CacheRefHandleID get_ref_handle()
  {
    return ref_handle_id_;
  }
  inline bool can_execute_async() const
  {
    return get_exec_context().use_remote_sql() && physical_plan_ != nullptr &&
           physical_plan_->get_location_type() != OB_PHY_PLAN_UNCERTAIN;
    // temporarily prevent the global index plan being executed asynchronously
  }
  void set_is_com_filed_list()
  {
    is_com_filed_list_ = true;
  }
  bool get_is_com_filed_list()
  {
    return is_com_filed_list_;
  }
  void set_wildcard_string(common::ObString string)
  {
    wild_str_ = string;
  }
  common::ObString& get_wildcard_string()
  {
    return wild_str_;
  }
  static void replace_lob_type(const ObSQLSessionInfo& session, const ObField& field, obmysql::ObMySQLField& mfield);

G
gm 已提交
422
private:
O
oceanbase-admin 已提交
423 424 425
  // types and constants
  static const int64_t TRANSACTION_SET_VIOLATION_MAX_RETRY = 3;

G
gm 已提交
426
private:
O
oceanbase-admin 已提交
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
  // disallow copy
  ObResultSet(const ObResultSet& other);
  ObResultSet& operator=(const ObResultSet& other);
  // function members

  int open_plan();
  int open_cmd();
  int do_open_plan(ObExecContext& ctx);
  int do_close_plan(int errcode, ObExecContext& ctx);
  bool transaction_set_violation_and_retry(int& err, int64_t& retry);
  int init_cmd_exec_context(ObExecContext& exec_ctx);
  int on_cmd_execute();
  int auto_start_plan_trans();
  int auto_end_plan_trans(int ret, bool need_retry, bool& async);

  void store_affected_rows(ObPhysicalPlanCtx& plan_ctx);
  void store_found_rows(ObPhysicalPlanCtx& plan_ctx);
  int store_last_insert_id(ObExecContext& ctx);
  int drive_pdml_query();

  // make final field name
  int make_final_field_name(char* src, int64_t len, common::ObString& field_name);
  int prepare_mock_schemas();
  int rm_mock_schemas();
  // delete useless spaces
  static int64_t remove_extra_space(char* buff, int64_t len);

G
gm 已提交
454
protected:
O
oceanbase-admin 已提交
455 456
  bool is_user_sql_;

G
gm 已提交
457
private:
O
oceanbase-admin 已提交
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
  // data members
  common::ObArenaAllocator inner_mem_pool_;
  common::ObIAllocator& mem_pool_;

  uint64_t statement_id_;
  int64_t sql_id_;
  int64_t affected_rows_;  // number of rows affected by INSERT/UPDATE/DELETE
  int64_t return_rows_;
  uint64_t last_insert_id_session_;
  uint64_t last_insert_id_to_client_;
  int64_t warning_count_;
  common::ObString statement_name_;
  char message_[common::MSG_SIZE];  // null terminated message string
  common::ColumnsFieldArray field_columns_;
  common::ParamsFieldArray param_columns_;

  const common::ColumnsFieldIArray* p_field_columns_;
  const common::ParamsFieldIArray* p_param_columns_;
  ObPhysicalPlan* physical_plan_;
  stmt::StmtType stmt_type_;
  // for a prepared SELECT, stmt_type_ is T_PREPARE
  // but in perf stat we want inner info, i.e. SELECT.
  stmt::StmtType inner_stmt_type_;
  stmt::StmtType literal_stmt_type_;
  char external_retrieve_info_buf_[sizeof(ExternalRetrieveInfo)];
  ExternalRetrieveInfo& external_retrieve_info_;
  bool compound_;
  bool has_global_variable_;  // there are global variables
  /*
   * ob_sql.h is the external interface of the SQL module,
   * the outside world does not need to know ObExecContext
   * Therefore, exec_ctx_ is a member of ObResultSet and is not exposed outside of SQL
   */
  int errcode_;
  ObSQLSessionInfo& my_session_;  // The session who owns this result set
  int64_t begin_timestamp_;
  ObIExecuteResult* exec_result_;
  ObICmd* cmd_;
  ObExecContext inner_exec_ctx_;
  ObExecContext* exec_ctx_;
  ObSqlPartitionLocationCache sql_location_cache_;
  bool is_from_plan_cache_;
  bool is_inner_result_set_;  // result set for inner sql execution.
  // mark whether there has limit operator
  bool has_top_limit_;
  bool is_calc_found_rows_;
  PsMode ps_protocol_;
  common::ObAddr self_addr_;
  // executor
  ObExecutor executor_;
  bool is_returning_;
  int64_t worker_count_;

  // physical plan ref handle id
  CacheRefHandleID ref_handle_id_;

  bool is_com_filed_list_;     // used to mark OB_MYSQL_COM_FIELD_LIST
  common::ObString wild_str_;  // uesd to save filed wildcard in OB_MYSQL_COM_FIELD_LIST;
};

// inline ObResultSet *ObResultSet::alloc(ObSQLSessionInfo &session, common::ObIAllocator &allocator)
//{
//  ObResultSet *rs = op_reclaim_alloc_args(ObResultSet, session, allocator);
//  if (rs != nullptr) {
//    rs->inc_ref_count();
//  }
//  return rs;
//}
//
// inline void ObResultSet::free(ObResultSet *rs)
//{
//  if (rs != nullptr) {
//    int64_t ref_count = rs->def_ref_count();
//    if (0 == ref_count) {
//      op_reclaim_free(rs);
//    }
//  }
//}
//
// inline ObResultSet *ObResultSet::assign(ObResultSet *other)
//{
//  if (other != nullptr) {
//    other->inc_ref_count();
//  }
//  return other;
//}

inline ObResultSet::ObResultSet(ObSQLSessionInfo& session, common::ObIAllocator& allocator)
    : is_user_sql_(false),
      inner_mem_pool_(),
      mem_pool_(allocator),
      statement_id_(common::OB_INVALID_ID),
      sql_id_(0),
      affected_rows_(0),
      return_rows_(0),
      last_insert_id_session_(0),
      last_insert_id_to_client_(0),
      warning_count_(0),
      statement_name_(),
      field_columns_(allocator),
      param_columns_(allocator),
      p_field_columns_(&field_columns_),
      p_param_columns_(&param_columns_),
      physical_plan_(NULL),
      stmt_type_(stmt::T_NONE),
      inner_stmt_type_(stmt::T_NONE),
      literal_stmt_type_(stmt::T_NONE),
      external_retrieve_info_(*new (external_retrieve_info_buf_) ExternalRetrieveInfo(allocator)),
      compound_(false),
      has_global_variable_(false),
      errcode_(0),
      my_session_(session),
      begin_timestamp_(0),
      exec_result_(nullptr),
      cmd_(NULL),
      inner_exec_ctx_(allocator),
      exec_ctx_(&inner_exec_ctx_),
      sql_location_cache_(),
      is_from_plan_cache_(false),
      is_inner_result_set_(false),
      has_top_limit_(false),
      is_calc_found_rows_(false),
      ps_protocol_(NO_PS),
      executor_(),
      is_returning_(false),
      worker_count_(0),
      ref_handle_id_(MAX_HANDLE),
      is_com_filed_list_(false),
      wild_str_()
{
  message_[0] = '\0';
}

inline ObResultSet::ObResultSet(ObSQLSessionInfo& session)
    : is_user_sql_(false),
      inner_mem_pool_(common::ObModIds::OB_RESULT_SET, common::OB_MALLOC_NORMAL_BLOCK_SIZE),
      mem_pool_(inner_mem_pool_),
      statement_id_(common::OB_INVALID_ID),
      sql_id_(0),
      affected_rows_(0),
      return_rows_(0),
      last_insert_id_session_(0),
      last_insert_id_to_client_(0),
      warning_count_(0),
      statement_name_(),
      field_columns_(inner_mem_pool_),
      param_columns_(inner_mem_pool_),
      p_field_columns_(&field_columns_),
      p_param_columns_(&param_columns_),
      physical_plan_(NULL),
      stmt_type_(stmt::T_NONE),
      inner_stmt_type_(stmt::T_NONE),
      literal_stmt_type_(stmt::T_NONE),
      external_retrieve_info_(*new (external_retrieve_info_buf_) ExternalRetrieveInfo(inner_mem_pool_)),
      compound_(false),
      has_global_variable_(false),
      errcode_(0),
      my_session_(session),
      begin_timestamp_(0),
      exec_result_(nullptr),
      cmd_(NULL),
      inner_exec_ctx_(),
      exec_ctx_(&inner_exec_ctx_),
      sql_location_cache_(),
      is_from_plan_cache_(false),
      is_inner_result_set_(false),
      has_top_limit_(false),
      is_calc_found_rows_(false),
      ps_protocol_(NO_PS),
      executor_(),
      is_returning_(false),
      worker_count_(0),
      ref_handle_id_(MAX_HANDLE),
      is_com_filed_list_(false),
      wild_str_()
{
  message_[0] = '\0';
}

inline int64_t ObResultSet::get_affected_rows() const
{
  return affected_rows_;
}

inline int64_t ObResultSet::get_warning_count() const
{
  return warning_count_;
}

inline uint64_t ObResultSet::get_statement_id() const
{
  return statement_id_;
}

inline const common::ObString& ObResultSet::get_statement_name() const
{
  return statement_name_;
}

inline const char* ObResultSet::get_message() const
{
  return message_;
}

inline int ObResultSet::get_errcode() const
{
  return errcode_;
}

inline void ObResultSet::set_statement_id(const uint64_t stmt_id)
{
  statement_id_ = stmt_id;
}

inline void ObResultSet::set_message(const char* message)
{
  snprintf(message_, common::MSG_SIZE, "%s", message);
}

inline void ObResultSet::set_errcode(int code)
{
  errcode_ = code;
}

inline int ObResultSet::add_field_column(const common::ObField& field)
{
  return field_columns_.push_back(field);
}

inline int ObResultSet::add_param_column(const common::ObField& param)
{
  return param_columns_.push_back(param);
}

inline const common::ColumnsFieldIArray* ObResultSet::get_field_columns() const
{
  return p_field_columns_;
}

inline const common::ParamsFieldIArray* ObResultSet::get_param_fields() const
{
  return p_param_columns_;
}

inline ObIArray<ObRawExpr*>& ObResultSet::get_external_params()
{
  return external_retrieve_info_.external_params_;
}

inline ObIArray<ObRawExpr*>& ObResultSet::get_into_exprs()
{
  return external_retrieve_info_.into_exprs_;
}

inline const common::ObIArray<share::schema::ObSchemaObjVersion>& ObResultSet::get_ref_objects() const
{
  return external_retrieve_info_.ref_objects_;
}

inline common::ObIArray<share::schema::ObSchemaObjVersion>& ObResultSet::get_ref_objects()
{
  return external_retrieve_info_.ref_objects_;
}

inline ObString& ObResultSet::get_route_sql()
{
  return external_retrieve_info_.route_sql_;
}

inline bool ObResultSet::get_is_select_for_update()
{
  return external_retrieve_info_.is_select_for_update_;
}

inline bool ObResultSet::has_hidden_rowid()
{
  return external_retrieve_info_.has_hidden_rowid_;
}

inline bool ObResultSet::is_with_rows() const
{
  return (p_field_columns_->count() > 0 && !is_prepare_stmt());
}

inline void ObResultSet::set_affected_rows(const int64_t& affected_rows)
{
  affected_rows_ = affected_rows;
}

inline void ObResultSet::set_last_insert_id_session(const uint64_t last_insert_id)
{
  last_insert_id_session_ = last_insert_id;
}
inline uint64_t ObResultSet::get_last_insert_id_session()
{
  return last_insert_id_session_;
}

inline void ObResultSet::set_last_insert_id_to_client(const uint64_t last_insert_id)
{
  last_insert_id_to_client_ = last_insert_id;
}
inline uint64_t ObResultSet::get_last_insert_id_to_client()
{
  return last_insert_id_to_client_;
}

inline void ObResultSet::set_warning_count(const int64_t& warning_count)
{
  warning_count_ = warning_count;
}

inline int64_t ObResultSet::to_string(char* buf, const int64_t buf_len) const
{
  int64_t pos = 0;
  common::databuff_printf(buf, buf_len, pos, "stmt_type=%d ", stmt_type_);
  common::databuff_printf(buf, buf_len, pos, "is_with_rows=%c ", this->is_with_rows() ? 'Y' : 'N');
  common::databuff_printf(buf, buf_len, pos, "affected_rows=%ld ", affected_rows_);
  common::databuff_printf(buf, buf_len, pos, "warning_count=%ld ", warning_count_);
  common::databuff_printf(buf, buf_len, pos, "field_count=%ld ", field_columns_.count());
  common::databuff_printf(buf, buf_len, pos, "message=%s ", message_);
  common::databuff_printf(buf, buf_len, pos, "stmt_id=%lu ", statement_id_);
  common::databuff_printf(buf, buf_len, pos, "stmt_name=%.*s ", statement_name_.length(), statement_name_.ptr());
  common::databuff_printf(buf, buf_len, pos, "sql_id=%lu ", sql_id_);
  return pos;
}

inline void ObResultSet::set_end_trans_async(bool is_async)
{
  get_exec_context().set_end_trans_async(is_async);
}

inline bool ObResultSet::is_end_trans_async()
{
  return get_exec_context().is_end_trans_async();
}

inline void ObResultSet::set_cmd(ObICmd* cmd)
{
  cmd_ = cmd;
}

inline void ObResultSet::set_physical_plan(const CacheRefHandleID ref_handle, ObPhysicalPlan* physical_plan)
{
  physical_plan_ = physical_plan;
  if (NULL != physical_plan) {
    set_ref_handle(ref_handle);
  }
}

inline void ObResultSet::fields_clear()
{
  affected_rows_ = 0;
  return_rows_ = 0;
  warning_count_ = 0;
  message_[0] = '\0';
  field_columns_.reset();
  param_columns_.reset();
  p_field_columns_ = &field_columns_;
  p_param_columns_ = &param_columns_;
}

inline int ObResultSet::get_row_desc(const common::ObRowDesc*& row_desc) const
{
  UNUSED(row_desc);
  return common::OB_SUCCESS;
}

inline bool ObResultSet::is_prepare_stmt() const
{
  return stmt::T_PREPARE == stmt_type_;
}

inline void ObResultSet::set_stmt_type(stmt::StmtType stmt_type)
{
  stmt_type_ = stmt_type;
}

inline void ObResultSet::set_inner_stmt_type(stmt::StmtType stmt_type)
{
  inner_stmt_type_ = stmt_type;
}

inline void ObResultSet::set_compound_stmt(bool compound)
{
  compound_ = compound;
}

inline bool ObResultSet::is_show_warnings() const
{
  return stmt::T_SHOW_WARNINGS == stmt_type_;
}

inline stmt::StmtType ObResultSet::get_stmt_type() const
{
  return stmt_type_;
}

inline stmt::StmtType ObResultSet::get_inner_stmt_type() const
{
  return inner_stmt_type_;
}

inline stmt::StmtType ObResultSet::get_literal_stmt_type() const
{
  return literal_stmt_type_;
}

inline void ObResultSet::set_literal_stmt_type(stmt::StmtType stmt_type)
{
  literal_stmt_type_ = stmt_type;
}

inline bool ObResultSet::is_compound_stmt() const
{
  return compound_;
}

inline bool ObResultSet::is_dml_stmt(stmt::StmtType stmt_type) const
{
  return (stmt::T_SELECT == stmt_type || stmt::T_INSERT == stmt_type || stmt::T_REPLACE == stmt_type ||
          stmt::T_MERGE == stmt_type || stmt::T_DELETE == stmt_type || stmt::T_UPDATE == stmt_type);
}

inline bool ObResultSet::is_pl_stmt(stmt::StmtType stmt_type) const
{
  return (stmt::T_CALL_PROCEDURE == stmt_type || stmt::T_ANONYMOUS_BLOCK == stmt_type);
}

inline void ObResultSet::set_begin_timestamp(const int64_t begin_ts)
{
  begin_timestamp_ = begin_ts;
}

inline void ObResultSet::set_has_top_limit(const bool has_limit)
{
  has_top_limit_ = has_limit;
}

inline void ObResultSet::set_is_calc_found_rows(const bool is_calc_found_rows)
{
  is_calc_found_rows_ = is_calc_found_rows;
}

inline bool ObResultSet::get_has_top_limit() const
{
  return has_top_limit_;
}

inline bool ObResultSet::is_calc_found_rows() const
{
  return is_calc_found_rows_;
}

inline ObPhysicalPlan*& ObResultSet::get_physical_plan()
{
  return physical_plan_;
}

}  // end namespace sql
}  // end namespace oceanbase

#endif /* OCEANBASE_SQL_OB_RESULT_SET_H */