from typing import Dict, Any str_keys = [ "serverless_tenant_id", "serverless_project_id", "serverless_cluster_id", "digest", "plan_digest", "schema_name", "stmt_type", "normalized_sql", "is_internal", # "sample_sql", # "sample_plan", # "sample_binary_plan", ] sum_keys = [ "exec_count", # "commit_count", # "exec_retry_count", # "exec_retry_time", "ru", "rru", "wru", ] max_keys = [ # "end", ] min_keys = [ # "begin", ] def merge_statements(dst: Dict[str, Any], src: Dict[str, Any]): # for k in src.keys(): # if k.startswith("sum_"): # if k not in dst: # dst[k] = 0 # dst[k] += src[k] # elif k.startswith("max_"): # if (k not in dst) or (src[k] > dst[k]): # dst[k] = src[k] # elif k.startswith("min_"): # if (k not in dst) or (src[k] < dst[k]): # dst[k] = src[k] for k in str_keys: if k in src and k not in dst: dst[k] = src[k] for k in sum_keys: if k in src: if k not in dst: dst[k] = 0 dst[k] += src[k] for k in max_keys: if (k in src) and ((k not in dst) or (src[k] > dst[k])): dst[k] = src[k] for k in min_keys: if (k in src) and ((k not in dst) or (src[k] < dst[k])): dst[k] = src[k] class Statement: # begin: int # end: int serverless_tenant_id: str serverless_project_id: str serverless_cluster_id: str # Immutable digest: str plan_digest: str schema_name: str stmt_type: str normalized_sql: str # table_names: str is_internal: bool # Basic sample_sql: str # charset: str # collation: str # prev_sql: str sample_plan: str sample_binary_plan: str # plan_hint: str # index_names: str exec_count: int sum_errors: int sum_warnings: int # Latency sum_latency: int max_latency: int min_latency: int sum_parse_latency: int max_parse_latency: int sum_compile_latency: int max_compile_latency: int # Coprocessor sum_num_cop_tasks: int max_cop_process_time: int max_cop_process_address: int max_cop_wait_time: int max_cop_wait_address: int # TiKV sum_process_time: int max_process_time: int sum_wait_time: int max_wait_time: int sum_backoff_time: int max_backoff_time: int sum_total_keys: int max_total_keys: int sum_processed_keys: int max_processed_keys: int sum_rocksdb_delete_skipped_count: int max_rocksdb_delete_skipped_count: int sum_rocksdb_key_skipped_count: int max_rocksdb_key_skipped_count: int sum_rocksdb_block_cache_hit_count: int max_rocksdb_block_cache_hit_count: int sum_rocksdb_block_read_count: int max_rocksdb_block_read_count: int sum_rocksdb_block_read_byte: int max_rocksdb_block_read_byte: int # Txn commit_count: int sum_get_commit_ts_time: int max_get_commit_ts_time: int sum_prewrite_time: int max_prewrite_time: int sum_commit_time: int max_commit_time: int sum_local_latch_time: int max_local_latch_time: int sum_commit_backoff_time: int max_commit_backoff_time: int sum_resolve_lock_time: int max_resolve_lock_time: int sum_write_keys: int max_write_keys: int sum_write_size: int max_write_size: int sum_prewrite_region_num: int max_prewrite_region_num: int sum_txn_retry: int max_txn_retry: int sum_backoff_times: int # backoff_types: Dict[str, int] # auth_users: Dict[str, Dict] # Other sum_mem: int max_mem: int sum_disk: int max_disk: int sum_affected_rows: int sum_kv_total: int sum_pd_total: int sum_backoff_total: int sum_write_sql_resp_total: int sum_result_rows: int max_result_rows: int min_result_rows: int # prepared: int # Plan cache # plan_in_cache: bool # plan_cache_hits: int # plan_in_binding: bool # Pessimistic execution retry information. exec_retry_count: int exec_retry_time: int # Request Units (RU) ru: float rru: float wru: float # The first time this type of SQL executes. first_seen: str # The last time this type of SQL executes. # last_seen: str