The end-to-end diagnostics feature of OceanBase Database records the time consumed in each stage of the trace from a client to an OceanBase Database Proxy (ODP) and then to an OBServer node, and records the trace information related to component diagnostics.
OceanBase Connector/J supports the Show Trace feature based on the end-to-end tracing feature. You can run the Show Trace command to obtain the end-to-end trace of the last task in the session.
When you use OceanBase Connector/J to connect to a database, you can specify enableFullLinkTrace=true in the URL to enable the end-to-end tracing feature, and specify SET ob_enable_show_trace = TRUE; in the SQL statement to enable the Show Trace feature.
Here is an example:
Connection conn = setConnection("&enableFullLinkTrace=true");
Statement stmt = conn.createStatement();
stmt.execute("set ob_enable_show_trace = true");
createTable("test_trace", "c1 int");
stmt.execute("insert into test_trace values (111)");
ResultSet rs = stmt.executeQuery("select * from test_trace");
Assert.assertTrue(rs.next());
Assert.assertEquals(111, rs.getInt(1));
Assert.assertFalse(rs.next());
rs = stmt.executeQuery("show trace");
while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
}
Note
OceanBase Database V4.1.0 provides the ob_enable_show_trace variable. This system variable allows you to enable or disable the Show Trace feature during end-to-end diagnostics. If you connect to OceanBase Database V4.0.0 or earlier, you still need to use the ob_enable_trace_log variable to enable or disable the Show Trace feature.
The following example shows the result set of the Show Trace command:
oceanbase_jdbc 2023-02-10 10:32:20.167 60000 µs
└── com_query_process 2023-02-10 10:32:20.32195 51117 µs
└── mpquery_single_stmt 2023-02-10 10:32:20.321953 51103 µs
├── sql_compile 2023-02-10 10:32:20.321961 50749 µs
│ ├── pc_get_plan 2023-02-10 10:32:20.321962 4 µs
│ └── hard_parse 2023-02-10 10:32:20.321991 50711 µs
│ ├── parse 2023-02-10 10:32:20.321992 19 µs
│ ├── resolve 2023-02-10 10:32:20.322028 93 µs
│ ├── rewrite 2023-02-10 10:32:20.322158 183 µs
│ ├── optimize 2023-02-10 10:32:20.322356 2048 µs
│ │ ├── inner_execute_read 2023-02-10 10:32:20.322902 1296 µs
│ │ │ ├── sql_compile 2023-02-10 10:32:20.322914 1176 µs
│ │ │ │ ├── pc_get_plan 2023-02-10 10:32:20.322916 7 µs
│ │ │ │ └── hard_parse 2023-02-10 10:32:20.322948 1134 µs
│ │ │ │ ├── parse 2023-02-10 10:32:20.322949 56 µs
│ │ │ │ ├── resolve 2023-02-10 10:32:20.323024 184 µs
│ │ │ │ ├── rewrite 2023-02-10 10:32:20.323246 287 µs
│ │ │ │ ├── optimize 2023-02-10 10:32:20.323549 356 µs
│ │ │ │ ├── code_generate 2023-02-10 10:32:20.323922 76 µs
│ │ │ │ └── pc_add_plan 2023-02-10 10:32:20.324033 37 µs
│ │ │ ├── open 2023-02-10 10:32:20.3241 26 µs
│ │ │ ├── get_das_id 2023-02-10 10:32:20.324141 1 µs
│ │ │ └── do_local_das_task 2023-02-10 10:32:20.324152 24 µs
│ │ └── close 2023-02-10 10:32:20.32421 38 µs
│ │ ├── close_das_task 2023-02-10 10:32:20.324213 4 µs
│ │ └── end_transaction 2023-02-10 10:32:20.324229 2 µs
│ ├── code_generate 2023-02-10 10:32:20.324419 59 µs
│ └── pc_add_plan 2023-02-10 10:32:20.372656 28 µs
└── sql_execute 2023-02-10 10:32:20.372722 302 µs
├── open 2023-02-10 10:32:20.372722 15 µs
├── response_result 2023-02-10 10:32:20.372747 125 µs
│ ├── get_das_id 2023-02-10 10:32:20.372749 1 µs
│ └── do_local_das_task 2023-02-10 10:32:20.37276 27 µs
└── close 2023-02-10 10:32:20.372882 116 µs
├── close_das_task 2023-02-10 10:32:20.372883 7 µs
└── end_transaction 2023-02-10 10:32:20.372974 3 µs