The database parses each received SQL text string and generates an internal parsing tree. The database traverses the parsing tree and ignores constant values in the parsing tree. In this case, an integer value is calculated using a certain algorithm. This integer is used as the Unique SQL ID to uniquely identify this type of SQL. SQLs with the same Unique SQL ID are called Unique SQLs.
Assume that the user enters the following SQL statements in sequence:
select * from t1 where id = 1; select * from t1 where id = 2;
The statistics of the two SQL statements are aggregated to the same Unique SQL statement.
select * from t1 where id = ?;
The GS_INSTR_UNIQUE_SQL view displays the execution information about the Unique SQL statements collected by the current node, including:
The Unique SQL statistics function has the following restrictions:
When a common user accesses the GS_INSTR_UNIQUE_SQL view, only the Unique SQL information about the user is displayed. When an administrator accesses the GS_INSTR_UNIQUE_SQL view, all Unique SQL information about the current node is displayed. The GS_INSTR_UNIQUE_SQL view can be queried on both CNs and DNs. The DN displays the Unique SQL statistics of the local node, and the CN displays the complete Unique SQL statistics of the local node. That is, the CN collects the Unique SQL execution information of the CN from other CNs and DNs and displays the information. You can query the GS_INSTR_UNIQUE_SQL view to locate the top SQL statements that consume different resources, providing a basis for cluster performance optimization and maintenance.
Name |
Type |
Description |
---|---|---|
node_name |
name |
Name of the CN that receives SQL statements |
node_id |
integer |
Node ID, which is the same as the value of node_id in the pgxc_node table |
user_name |
name |
Username |
user_id |
oid |
User ID |
unique_sql_id |
bigint |
Normalized Unique SQL ID |
query |
text |
Normalized SQL text. The maximum length is equal to the value of the GUC parameter track_activity_query_size. |
n_calls |
bigint |
Number of successful execution times |
min_elapse_time |
bigint |
Minimum running time of the SQL statement in the database (unit: μs) |
max_elapse_time |
bigint |
Maximum running time of SQL statements in the database (unit: μs) |
total_elapse_time |
bigint |
Total running time of SQL statements in the database (unit: μs) |
n_returned_rows |
bigint |
Row activity - Number of rows in the result set returned by the SELECT statement |
n_tuples_fetched |
bigint |
Row activity - Randomly scan rows (column-store tables/foreign tables are not counted.) |
n_tuples_returned |
bigint |
Row activity - Sequential scan rows (Column-store tables/foreign tables are not counted.) |
n_tuples_inserted |
bigint |
Row activity - Inserted rows |
n_tuples_updated |
bigint |
Row activity - Updated rows |
n_tuples_deleted |
bigint |
Row activity - Deleted rows |
n_blocks_fetched |
bigint |
Block access times of the buffer, that is, physical read/I/O |
n_blocks_hit |
bigint |
Block hits of the buffer, that is, logical read/cache |
n_soft_parse |
bigint |
Number of soft parsing times (cache plan) |
n_hard_parse |
bigint |
Number of hard parsing times (generation plan) |
db_time |
bigint |
Valid DB execution time, including the waiting time and network sending time. If multiple threads are involved in query execution, the value of DB_TIME is the sum of DB_TIME of multiple threads (unit: μs). |
cpu_time |
bigint |
CPU execution time, excluding the sleep time (unit: μs) |
execution_time |
bigint |
SQL execution time in the query executor, DDL statements, and statements (such as Copy statements) that are not executed by the executor are not counted (unit: μs). |
parse_time |
bigint |
SQL parsing time (unit: μs) |
plan_time |
bigint |
SQL generation plan time (unit: μs) |
rewrite_time |
bigint |
SQL rewriting time (unit: μs) |
pl_execution_time |
bigint |
Execution time of the plpgsql procedural language function (unit: μs) |
pl_compilation_time |
bigint |
Compilation time of the plpgsql procedural language function (unit: μs) |
net_send_time |
bigint |
Network time, including the time spent by the CN in sending data to the client and the time spent by the DN in sending data to the CN (unit: μs) |
data_io_time |
bigint |
File I/O time (unit: μs) |