Purpose
GV$OB_SQL_AUDIT displays the statistics of each SQL request on all OBServer nodes, such as its source and execution status. This view is tenant-specific, and only the sys tenant can query this view in other tenants.
Fields
| Field | Type | Nullable | Description |
|---|---|---|---|
| SVR_IP | varchar(46) | NO | The IP address. |
| SVR_PORT | bigint(20) | NO | The port number. |
| REQUEST_ID | bigint(20) | NO | The ID of the request. |
| SQL_EXEC_ID | bigint(20) | NO | The ID of the current execution. |
| TRACE_ID | varchar(128) | NO | The trace ID of the statement. |
| SID | bigint(20) unsigned | NO | The ID of the session connection. |
| CLIENT_IP | varchar(46) | NO | |
| CLIENT_PORT | bigint(20) | NO | The port number of the client that sent the request. |
| TENANT_ID | bigint(20) | NO | The ID of the tenant that sent the request. |
| TENANT_NAME | varchar(64) | NO | The name of the tenant that sent the request. |
| EFFECTIVE_TENANT_ID | bigint(20) | NO | The ID of the tenant. |
| USER_ID | bigint(20) | NO | The ID of the user that sent the request. |
| USER_NAME | varchar(64) | NO | The name of the user that sent the request. |
| USER_GROUP | bigint(20) | YES | The ID of the resource group to which the user belongs. |
| USER_CLIENT_IP | varchar(46) | NO | The IP address of the client that sent the request. |
| DB_ID | bigint(20) unsigned | NO | The ID of the database. |
| DB_NAME | varchar(128) | NO | The name of the database. |
| SQL_ID | varchar(32) | NO | The ID of the SQL statement. |
| QUERY_SQL | longtext | NO | The actual SQL statement. |
| PLAN_ID | bigint(20) | NO | The ID of the execution plan. |
| AFFECTED_ROWS | bigint(20) | NO | The number of rows affected. |
| RETURN_ROWS | bigint(20) | NO | Returned Rows |
| PARTITION_CNT | bigint(20) | NO | The number of partitions scanned by the request. |
| RET_CODE | bigint(20) | NO | The return code of the execution. |
| QC_ID | bigint(20) unsigned | NO | The ID of the scheduler in the parallel execution scenario. |
| DFO_ID | bigint(20) | NO | The ID of the sub-plan being executed in the parallel execution scenario. |
| SQC_ID | bigint(20) | NO | The ID of the local coordinator in the parallel execution scenario. |
| WORKER_ID | bigint(20) | NO | The ID of the worker thread in the parallel execution scenario. |
| EVENT | varchar(64) | NO | The name of the wait event with the longest wait time. |
| P1TEXT | varchar(64) | NO | The first parameter of the wait event. |
| P1 | bigint(20) unsigned | NO | The value of the first parameter of the wait event. |
| P2TEXT | varchar(64) | NO | The second parameter of the wait event. |
| P2 | bigint(20) unsigned | NO | The value of the second parameter of the wait event. |
| P3TEXT | varchar(64) | NO | The third parameter of the wait event. |
| P3 | bigint(20) unsigned | NO | The value of the third parameter of the wait event. |
| LEVEL | bigint(20) | NO | The level of the wait event. |
| WAIT_CLASS_ID | bigint(20) | NO | The ID of the class to which the wait event belongs. |
| WAIT_CLASS# | bigint(20) | NO | The subscript of the class to which the wait event belongs. |
| WAIT_CLASS | varchar(64) | NO | The name of the class to which the wait event belongs. |
| STATE | varchar(19) | NO | The state of the wait event. |
| WAIT_TIME_MICRO | bigint(20) | NO | The wait time of the wait event in microseconds. |
| TOTAL_WAIT_TIME_MICRO | bigint(20) | NO | The total wait time in microseconds during execution. |
| TOTAL_WAITS | bigint(20) | NO | The total number of waits during the execution. |
| RPC_COUNT | bigint(20) | NO | The number of remote procedure calls (RPCs) sent. |
| PLAN_TYPE | bigint(20) | NO | The type of the execution plan. Valid values: 1: indicates a local execution plan2: indicates a remote execution plan3: indicates a distributed execution plan |
| IS_INNER_SQL | tinyint(4) | NO | Indicates whether the request is an internal SQL request. |
| IS_EXECUTOR_RPC | tinyint(4) | NO | Indicates whether the current request is an RPC request. |
| IS_HIT_PLAN | tinyint(4) | NO | Indicates whether the plan cache is hit. |
| REQUEST_TIME | bigint(20) | NO | The time when the execution starts. |
| ELAPSED_TIME | bigint(20) | NO | The amount of time elapsed from when the request was received to when the execution of the request ended. |
| NET_TIME | bigint(20) | NO | The amount of time elapsed from when the RPC was sent to when the request was received. |
| NET_WAIT_TIME | bigint(20) | NO | The amount of time elapsed from when the request was received to when it entered the queue. |
| QUEUE_TIME | bigint(20) | NO | The time that the request waits in the queue. |
| DECODE_TIME | bigint(20) | NO | The time spent on decoding the request after it left the queue. |
| GET_PLAN_TIME | bigint(20) | NO | The amount of time elapsed from when the processing started to when the plan was obtained. |
| EXECUTE_TIME | bigint(20) | NO | The time consumed for plan execution. |
| APPLICATION_WAIT_TIME | bigint(20) unsigned | NO | The total amount of time spent on waiting for events of the application class. |
| CONCURRENCY_WAIT_TIME | bigint(20) unsigned | NO | The total amount of time spent on waiting for events of the concurrency class. |
| USER_IO_WAIT_TIME | bigint(20) unsigned | NO | The total amount of time spent on waiting for events of the user_io class. |
| SCHEDULE_TIME | bigint(20) unsigned | NO | The total amount of time spent on events of the schedule class. |
| ROW_CACHE_HIT | bigint(20) | NO | The number of row cache hits. |
| BLOOM_FILTER_CACHE_HIT | bigint(20) | NO | The number of Bloom filter cache hits. |
| BLOCK_CACHE_HIT | bigint(20) | NO | The number of block cache hits. |
| BLOCK_INDEX_CACHE_HIT | bigint(20) | NO | The number of block index cache hits. |
| DISK_READS | bigint(20) | NO | The number of physical reads. |
| RETRY_CNT | bigint(20) | NO | Retries |
| TABLE_SCAN | tinyint(4) | NO | Indicates whether the request contains a full table scan. |
| CONSISTENCY_LEVEL | bigint(20) | NO | The consistency level. |
| MEMSTORE_READ_ROW_COUNT | bigint(20) | NO | The number of rows read in the MemStore. |
| SSSTORE_READ_ROW_COUNT | bigint(20) | NO | The number of rows consecutively read in the SSStore. |
| REQUEST_MEMORY_USED | bigint(20) | NO | The memory consumed by the request. |
| EXPECTED_WORKER_COUNT | bigint(20) | NO | The number of worker threads expected by the request. |
| USED_WORKER_COUNT | bigint(20) | NO | The number of worker threads used by the request. |
| SCHED_INFO | varchar(16384) | YES | The scheduling information of the request. |
| FUSE_ROW_CACHE_HIT | bigint(20) | NO | At present, this field is not supported and is NULL by default. |
| PS_STMT_ID | bigint(20) | NO | The ID of the PREPARE statement corresponding to the request. -1: indicates that the prepared statement (PS) protocol is not used in the SQL statement.-1: indicates that the PS protocol is used in the SQL statement, and indicates the unique identifier returned by the PS protocol for the statement. |
| TRANSACTION_HASH | bigint(20) unsigned | NO | The hash value of the transaction corresponding to the request. |
| REQUEST_TYPE | bigint(20) | NO | The type of the request. Valid values: |
| IS_BATCHED_MULTI_STMT | tinyint(4) | NO | Indicates whether optimization has been performed for batch execution of multiple statements. |
| OB_TRACE_INFO | varchar(4096) | NO | The trace information configured by the user. |
| PLAN_HASH | bigint(20) unsigned | NO | The hash value of the execution plan. |
| LOCK_FOR_READ_TIME | bigint(20) | NO | The time in microseconds spent on waiting for locked data to be unlocked before it can be read. |
| WAIT_TRX_MIGRATE_TIME | bigint(20) | NO | When wait events must be frozen due to the inner compaction mechanism during data writes, unfinished transactions must be migrated. This field indicates the time in microseconds required for migrating the unfinished transactions. |
| PARAMS_VALUE | longtext | NO | The PS-bound parameter value. |
General SQL information
SQL routing information
In OceanBase Database, SQL plans are divided into the following four types:
Local plans: The transaction session and the Leader of the partitions involved in the SQL statement are on the same OBServer node. The SQL statement may involve multiple partitions, but a table cannot contain multiple partitions.
Remote plans: The transaction session and the Leader of the partitions involved in the SQL statement are on different OBServer nodes. The SQL statement may involve multiple partitions, but a table cannot contain multiple partitions.
Distributed plans: The SQL statement involves operations on multiple partitions. The partitions can be in one or more OBServer nodes.
Uncertain plans: The number of partitions involved cannot be determined when the SQL statement is executed. These SQL execution plans typically exist in scenarios with global indexes and foreign keys.
Local transactions are committed more efficiently than cross-OBServer transactions. Therefore, you need to check whether the percentages of different types of SQL execution plans are as expected. To collect statistics on SQL plans by type, run the following statement:
select plan_type, count(1) from gv$sql_audit where tenant_id = xxx and request_time > time_to_usec('2021-10-08 12:00:00') group by plan_type;
The value of plan_type can be 1, 2, 3, or 4, indicating local plans, remote plans, distributed plans, or uncertain plans, respectively.
Slow SQL statistics
You can query the SQL statements whose execution time exceeds the specified threshold during a period, and thereby optimize the SQL plans based on the query result.
select tenant_id, elapsed_time, usec_to_time(request_time), substr(query_sql, 1, 50) from gv$sql_audit where tenant_id=1001 and elapsed_time > 100000 and request_time > time_to_usec('2021-10-08 12:00:00') order by elapsed_time desc limit 40;
SQL statistics within a transaction
Each SQL statement entry in sql_audit records the unique identifier of the current SQL transaction in transaction_hash. You can check this field to find all SQL information about the current transaction. Then, you can determine whether the transaction model, including single-SQL transaction and multi-SQL transaction, in business stress testing meets your expectation.
select tenant_id, substr(query_sql,1,50) from gv$sql_audit where tenant_id=1002 and transaction_hash='xxx' order by request_time;
SQL statements executed in the same session
You can query all business requests by the SID to analyze the business model.
select tenant_id, substr(query_sql,1,50) from gv$sql_audit where tenant_id=1002 and sid=1001 and request_time > time_to_usec('2021-10-08 12:00:00') order by request_time;