* ExecutorStart hook: start up logging if needed */
| 267 | * ExecutorStart hook: start up logging if needed |
| 268 | */ |
| 269 | static void |
| 270 | explain_ExecutorStart(QueryDesc *queryDesc, int eflags) |
| 271 | { |
| 272 | /* |
| 273 | * At the beginning of each top-level statement, decide whether we'll |
| 274 | * sample this statement. If nested-statement explaining is enabled, |
| 275 | * either all nested statements will be explained or none will. |
| 276 | * |
| 277 | * When in a parallel worker, we should do nothing, which we can implement |
| 278 | * cheaply by pretending we decided not to sample the current statement. |
| 279 | * If EXPLAIN is active in the parent session, data will be collected and |
| 280 | * reported back to the parent, and it's no business of ours to interfere. |
| 281 | */ |
| 282 | if (nesting_level == 0) |
| 283 | { |
| 284 | if (auto_explain_log_min_duration >= 0 && !IsParallelWorker()) |
| 285 | current_query_sampled = (random() < auto_explain_sample_rate * |
| 286 | ((double) MAX_RANDOM_VALUE + 1)); |
| 287 | else |
| 288 | current_query_sampled = false; |
| 289 | } |
| 290 | |
| 291 | if (auto_explain_enabled()) |
| 292 | { |
| 293 | /* Enable per-node instrumentation iff log_analyze is required. */ |
| 294 | if (auto_explain_log_analyze && (eflags & EXEC_FLAG_EXPLAIN_ONLY) == 0) |
| 295 | { |
| 296 | if (auto_explain_log_timing) |
| 297 | queryDesc->instrument_options |= INSTRUMENT_TIMER; |
| 298 | else |
| 299 | queryDesc->instrument_options |= INSTRUMENT_ROWS; |
| 300 | if (auto_explain_log_buffers) |
| 301 | queryDesc->instrument_options |= INSTRUMENT_BUFFERS; |
| 302 | if (auto_explain_log_wal) |
| 303 | queryDesc->instrument_options |= INSTRUMENT_WAL; |
| 304 | |
| 305 | queryDesc->instrument_options |= INSTRUMENT_CDB; |
| 306 | |
| 307 | if (queryDesc->showstatctx == NULL) |
| 308 | { |
| 309 | instr_time starttime; |
| 310 | INSTR_TIME_SET_CURRENT(starttime); |
| 311 | queryDesc->showstatctx = cdbexplain_showExecStatsBegin( |
| 312 | queryDesc, starttime); |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (prev_ExecutorStart) |
| 318 | prev_ExecutorStart(queryDesc, eflags); |
| 319 | else |
| 320 | standard_ExecutorStart(queryDesc, eflags); |
| 321 | |
| 322 | if (auto_explain_enabled()) |
| 323 | { |
| 324 | /* |
| 325 | * Set up to track total elapsed time in ExecutorRun. Make sure the |
| 326 | * space is allocated in the per-query context so it will go away at |
nothing calls this directly
no test coverage detected