Skip to content

Commit fc69fd6

Browse files
authored
fix: support explain with pgsql (#1207)
* fix: support explain with pgsql * fix: record driver in transactions
1 parent d3ba4f6 commit fc69fd6

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/DataCollector/QueryCollector.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public function addQuery($query, $bindings, $time, $connection)
185185
'source' => $source,
186186
'explain' => $explainResults,
187187
'connection' => $connection->getDatabaseName(),
188+
'driver' => $connection->getConfig('driver'),
188189
'hints' => $this->showHints ? $hints : null,
189190
'show_copy' => $this->showCopyButton,
190191
];
@@ -453,6 +454,7 @@ public function collectTransactionEvent($event, $connection)
453454
'source' => $source,
454455
'explain' => [],
455456
'connection' => $connection->getDatabaseName(),
457+
'driver' => $connection->getConfig('driver'),
456458
'hints' => null,
457459
'show_copy' => false,
458460
];
@@ -493,14 +495,27 @@ public function collect()
493495
];
494496

495497
// Add the results from the explain as new rows
496-
foreach ($query['explain'] as $explain) {
497-
$statements[] = [
498-
'sql' => " - EXPLAIN # {$explain->id}: `{$explain->table}` ({$explain->select_type})",
499-
'type' => 'explain',
500-
'params' => $explain,
501-
'row_count' => $explain->rows,
502-
'stmt_id' => $explain->id,
503-
];
498+
if ($query['driver'] === 'pgsql') {
499+
$explainer = trim(implode("\n", array_map(function ($explain) {
500+
return $explain->{'QUERY PLAN'};
501+
}, $query['explain'])));
502+
503+
if ($explainer) {
504+
$statements[] = [
505+
'sql' => " - EXPLAIN: {$explainer}",
506+
'type' => 'explain',
507+
];
508+
}
509+
} else {
510+
foreach ($query['explain'] as $explain) {
511+
$statements[] = [
512+
'sql' => " - EXPLAIN # {$explain->id}: `{$explain->table}` ({$explain->select_type})",
513+
'type' => 'explain',
514+
'params' => $explain,
515+
'row_count' => $explain->rows,
516+
'stmt_id' => $explain->id,
517+
];
518+
}
504519
}
505520
}
506521

src/LaravelDebugbar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ protected function addServerTimingHeaders(Response $response)
11371137

11381138
$headers = [];
11391139
foreach ($collector->collect()['measures'] as $k => $m) {
1140-
$headers[] = sprintf('app;desc="%s";dur=%F', str_replace('"', "'", $m['label']), $m['duration'] * 1000);
1140+
$headers[] = sprintf('app;desc="%s";dur=%F', str_replace(array("\n", "\r"), ' ', str_replace('"', "'", $m['label'])), $m['duration'] * 1000);
11411141
}
11421142

11431143
$response->headers->set('Server-Timing', $headers, false);

0 commit comments

Comments
 (0)