SHOW PROFILES displays the resource usage of the most recent statements sent to the server. SHOW PROFILE is used to view the time distribution across each execution stage (Status) of a specified statement, facilitating performance analysis and bottleneck identification.SET profiling = 1;
SHOW PROFILES;SHOW PROFILE [type [, type] ...] [FOR QUERY n] [LIMIT row_count [OFFSET offset]];type: {ALL| BLOCK IO| CONTEXT SWITCHES| CPU| IPC| MEMORY| PAGE FAULTS| SOURCE| SWAPS}
tdsql > SET profiling = 1;Query OK, 0 rows affected, 1 warning (0.00 sec)tdsql > SELECT COUNT(*) FROM test.t1;+----------+| COUNT(*) |+----------+| 1024 |+----------+1 row in set (0.02 sec)tdsql > SHOW PROFILES;+----------+------------+------------------------------+| Query_ID | Duration | Query |+----------+------------+------------------------------+| 1 | 0.02158725 | SELECT COUNT(*) FROM test.t1 |+----------+------------+------------------------------+1 row in set (0.00 sec)
Query_ID: the ID of a statement in the current session.Duration: the total execution duration of a statement, in seconds.Query: the text of a statement.tdsql > SHOW PROFILE FOR QUERY 1;+-----------------------+----------+| Status | Duration |+-----------------------+----------+| starting | 0.000089 || Executing hook on txn | 0.000005 || starting | 0.000010 || checking permissions | 0.000007 || Opening tables | 0.000038 || init | 0.000034 || System lock | 0.000009 || Wait gts rsp | 0.001235 || Searching range cache | 0.018652 || optimizing | 0.000015 || statistics | 0.000142 || preparing | 0.000023 || executing | 0.001120 || end | 0.000005 || query end | 0.000009 || closing tables | 0.000012 || freeing items | 0.000056 || cleaning up | 0.000017 |+-----------------------+----------+18 rows in set (0.00 sec)
Status: the name of the stage in which a statement is executed.Duration: the time consumed by this stage, in seconds.Wait gts rsp: the time spent waiting for a response from GTS (global timestamp).Searching range cache: the time spent searching the range cache. This status is added by TDSQL Boundless to isolate the time spent searching the range cache from Wait gts rsp, facilitating precise identification of the source of time consumption.System lock: the time spent waiting for a system lock.Opening tables: the time spent opening tables.tdsql > SHOW PROFILE CPU, BLOCK IO FOR QUERY 1;+-----------------------+----------+----------+------------+--------------+---------------+| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |+-----------------------+----------+----------+------------+--------------+---------------+| starting | 0.000089 | 0.000076 | 0.000012 | 0 | 0 || Wait gts rsp | 0.001235 | 0.000080 | 0.000020 | 0 | 0 || Searching range cache | 0.018652 | 0.015230 | 0.003410 | 16 | 0 || executing | 0.001120 | 0.001100 | 0.000018 | 0 | 0 || cleaning up | 0.000017 | 0.000015 | 0.000002 | 0 | 0 |+-----------------------+----------+----------+------------+--------------+---------------+
CPU_user: the CPU time spent in user mode, in seconds.CPU_system: the CPU time spent in kernel mode, in seconds.Block_ops_in: the number of block device read operations.Block_ops_out: the number of block device write operations.SHOW PROFILE supported type options:ALL: displays all information.BLOCK IO: displays the number of block device input and output operations.CONTEXT SWITCHES: displays the number of voluntary and involuntary context switches.CPU: displays the CPU time spent in user mode and kernel mode.IPC: displays the number of messages sent and received.MEMORY: not yet implemented.PAGE FAULTS: displays the number of major and minor page faults.SOURCE: displays the source file name where the function resides, the function name, and the line number.SWAPS: displays the number of swaps.SHOW PROFILES and SHOW PROFILE only display statements executed in the current session. The historical records are lost after the session is disconnected.profiling_history_size, with a default of 15 and a maximum of 100.Performance Schema to obtain more comprehensive performance analysis capabilities.フィードバック