Re: [HACKERS] \x auto and EXPLAIN

2016-03-11 Thread Robert Haas
On Sun, Jan 3, 2016 at 4:36 AM, Andreas Karlsson  wrote:
> psql's "\x auto" is a nice feature, but it is made much less useful in my
> opinion due to the expanded output format making query plans unreadable (and
> query plans often end up using expanded display due to their width). I think
> we should never use the expanded format for EXPLAIN output in the "\x auto"
> mode, since even when the wrapped format is used the query plans are very
> hard to read.
>
> I see two ways to fix this.
>
> 1) Never use expanded display for the case where there is only one column.
> There seems to me like there is little value in using expanded display for
> when you only have one column, but I may be missing some use case here.
>
> 2) Explicitly detect (for example based on the headers) that the result is a
> query plan and if so disable expanded display.
>
> I have attached a trivial patch for each solution.

Committed #1 after updating the comments and adding documentation.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] \x auto and EXPLAIN

2016-01-04 Thread Shulgin, Oleksandr
On Sun, Jan 3, 2016 at 6:43 PM, Tom Lane  wrote:

> Andreas Karlsson  writes:
> > psql's "\x auto" is a nice feature, but it is made much less useful in
> > my opinion due to the expanded output format making query plans
> > unreadable (and query plans often end up using expanded display due to
> > their width). I think we should never use the expanded format for
> > EXPLAIN output in the "\x auto" mode, since even when the wrapped format
> > is used the query plans are very hard to read.
>
> > I see two ways to fix this.
>
> > 1) Never use expanded display for the case where there is only one
> > column. There seems to me like there is little value in using expanded
> > display for when you only have one column, but I may be missing some use
> > case here.
>
> > 2) Explicitly detect (for example based on the headers) that the result
> > is a query plan and if so disable expanded display.
>
> The second of these seems pretty bletcherous --- for one thing, it might
> fall foul of localization attempts.  However, I could see the argument
> for not using expanded mode for any single-column output.
>

+1 to option #1, I sympathize to this as an annoyance that can be easily
fixed.

--
Alex


Re: [HACKERS] \x auto and EXPLAIN

2016-01-04 Thread Andreas Karlsson

On 01/03/2016 06:43 PM, Tom Lane wrote:

I see two ways to fix this.



1) Never use expanded display for the case where there is only one
column. There seems to me like there is little value in using expanded
display for when you only have one column, but I may be missing some use
case here.



2) Explicitly detect (for example based on the headers) that the result
is a query plan and if so disable expanded display.


The second of these seems pretty bletcherous --- for one thing, it might
fall foul of localization attempts.  However, I could see the argument
for not using expanded mode for any single-column output.


I too prefer the first option, and hope I have not missed a case for 
when having "\x auto" give expanded display with a single column is a 
clear gain. For the cases I have seen myself it has always been a 
usability loss (minor or great).


Andreas



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] \x auto and EXPLAIN

2016-01-03 Thread Andreas Karlsson

Hi,

psql's "\x auto" is a nice feature, but it is made much less useful in 
my opinion due to the expanded output format making query plans 
unreadable (and query plans often end up using expanded display due to 
their width). I think we should never use the expanded format for 
EXPLAIN output in the "\x auto" mode, since even when the wrapped format 
is used the query plans are very hard to read.


I see two ways to fix this.

1) Never use expanded display for the case where there is only one 
column. There seems to me like there is little value in using expanded 
display for when you only have one column, but I may be missing some use 
case here.


2) Explicitly detect (for example based on the headers) that the result 
is a query plan and if so disable expanded display.


I have attached a trivial patch for each solution.

Andreas
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 8958903..29061d2 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -818,7 +818,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
 	 * If in expanded auto mode, we have now calculated the expected width, so
 	 * we can now escape to vertical mode if necessary.
 	 */
-	if (cont->opt->expanded == 2 && output_columns > 0 &&
+	if (cont->opt->expanded == 2 && output_columns > 0 && cont->ncolumns > 1 &&
 		(output_columns < total_header_width || output_columns < width_total))
 	{
 		print_aligned_vertical(cont, fout, is_pager);
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 8958903..319ec65 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -614,6 +614,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
 	printTextLineWrap *wrap;	/* Wrap status for each column */
 	int			output_columns = 0;		/* Width of interactive console */
 	bool		is_local_pager = false;
+	bool		is_explain;
 
 	if (cancel_pressed)
 		return;
@@ -814,11 +815,14 @@ print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
 		}
 	}
 
+	is_explain = cont->ncolumns == 1 &&
+	  strcmp(cont->headers[0], "QUERY PLAN") == 0;
+
 	/*
 	 * If in expanded auto mode, we have now calculated the expected width, so
 	 * we can now escape to vertical mode if necessary.
 	 */
-	if (cont->opt->expanded == 2 && output_columns > 0 &&
+	if (cont->opt->expanded == 2 && output_columns > 0 && !is_explain &&
 		(output_columns < total_header_width || output_columns < width_total))
 	{
 		print_aligned_vertical(cont, fout, is_pager);

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] \x auto and EXPLAIN

2016-01-03 Thread Tom Lane
Andreas Karlsson  writes:
> psql's "\x auto" is a nice feature, but it is made much less useful in 
> my opinion due to the expanded output format making query plans 
> unreadable (and query plans often end up using expanded display due to 
> their width). I think we should never use the expanded format for 
> EXPLAIN output in the "\x auto" mode, since even when the wrapped format 
> is used the query plans are very hard to read.

> I see two ways to fix this.

> 1) Never use expanded display for the case where there is only one 
> column. There seems to me like there is little value in using expanded 
> display for when you only have one column, but I may be missing some use 
> case here.

> 2) Explicitly detect (for example based on the headers) that the result 
> is a query plan and if so disable expanded display.

The second of these seems pretty bletcherous --- for one thing, it might
fall foul of localization attempts.  However, I could see the argument
for not using expanded mode for any single-column output.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers