@@ -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
0 commit comments