1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Rework wrap-width calculation in psql's print_aligned_vertical() function.

This area was rather heavily whacked around in 6513633b9 and follow-on
commits, and it was showing it, because the logic to calculate the
allowable data width in wrapped expanded mode had only the vaguest
relationship to the logic that was actually printing the data.  It was
not very close to being right about the conditions requiring overhead
columns to be added.  Aside from being wrong, it was pretty unreadable
and under-commented.  Rewrite it so it corresponds to what the printing
code actually does.

In passing, remove a couple of dead tests in the printing logic, too.

Per a complaint from Jeff Janes, though this doesn't look much like his
patch because it fixes a number of other corner-case bogosities too.
One such fix that's visible in the regression test results is that
although the code was attempting to enforce a minimum data width of
3 columns, it sometimes left less space than that available.
This commit is contained in:
Tom Lane
2015-11-30 17:53:32 -05:00
parent 3690dc6b03
commit 0e0776bc99
3 changed files with 514 additions and 157 deletions

View File

@ -1185,6 +1185,338 @@ execute q;
+--------------------+-----------------+
(10 rows)
\pset expanded on
\pset columns 30
\pset border 0
\pset format unaligned
execute q;
0123456789abcdef|xx
0123456789|yyyyyyyyyyyyyyyyyy
0123456789abcdef|xxxx
0123456789|yyyyyyyyyyyyyyyy
0123456789abcdef|xxxxxx
0123456789|yyyyyyyyyyyyyy
0123456789abcdef|xxxxxxxx
0123456789|yyyyyyyyyyyy
0123456789abcdef|xxxxxxxxxx
0123456789|yyyyyyyyyy
0123456789abcdef|xxxxxxxxxxxx
0123456789|yyyyyyyy
0123456789abcdef|xxxxxxxxxxxxxx
0123456789|yyyyyy
0123456789abcdef|xxxxxxxxxxxxxxxx
0123456789|yyyy
0123456789abcdef|xxxxxxxxxxxxxxxxxx
0123456789|yy
0123456789abcdef|xxxxxxxxxxxxxxxxxxxx
0123456789|
\pset format aligned
execute q;
* Record 1
0123456789abcdef xx
0123456789 yyyyyyyyyyyyyyyyyy
* Record 2
0123456789abcdef xxxx
0123456789 yyyyyyyyyyyyyyyy
* Record 3
0123456789abcdef xxxxxx
0123456789 yyyyyyyyyyyyyy
* Record 4
0123456789abcdef xxxxxxxx
0123456789 yyyyyyyyyyyy
* Record 5
0123456789abcdef xxxxxxxxxx
0123456789 yyyyyyyyyy
* Record 6
0123456789abcdef xxxxxxxxxxxx
0123456789 yyyyyyyy
* Record 7
0123456789abcdef xxxxxxxxxxxxxx
0123456789 yyyyyy
* Record 8
0123456789abcdef xxxxxxxxxxxxxxxx
0123456789 yyyy
* Record 9
0123456789abcdef xxxxxxxxxxxxxxxxxx
0123456789 yy
* Record 10
0123456789abcdef xxxxxxxxxxxxxxxxxxxx
0123456789
\pset format wrapped
execute q;
* Record 1
0123456789abcdef xx
0123456789 yyyyyyyyyyyy.
.yyyyyy
* Record 2
0123456789abcdef xxxx
0123456789 yyyyyyyyyyyy.
.yyyy
* Record 3
0123456789abcdef xxxxxx
0123456789 yyyyyyyyyyyy.
.yy
* Record 4
0123456789abcdef xxxxxxxx
0123456789 yyyyyyyyyyyy
* Record 5
0123456789abcdef xxxxxxxxxx
0123456789 yyyyyyyyyy
* Record 6
0123456789abcdef xxxxxxxxxxxx
0123456789 yyyyyyyy
* Record 7
0123456789abcdef xxxxxxxxxxxx.
.xx
0123456789 yyyyyy
* Record 8
0123456789abcdef xxxxxxxxxxxx.
.xxxx
0123456789 yyyy
* Record 9
0123456789abcdef xxxxxxxxxxxx.
.xxxxxx
0123456789 yy
* Record 10
0123456789abcdef xxxxxxxxxxxx.
.xxxxxxxx
0123456789
\pset border 1
\pset format unaligned
execute q;
0123456789abcdef|xx
0123456789|yyyyyyyyyyyyyyyyyy
0123456789abcdef|xxxx
0123456789|yyyyyyyyyyyyyyyy
0123456789abcdef|xxxxxx
0123456789|yyyyyyyyyyyyyy
0123456789abcdef|xxxxxxxx
0123456789|yyyyyyyyyyyy
0123456789abcdef|xxxxxxxxxx
0123456789|yyyyyyyyyy
0123456789abcdef|xxxxxxxxxxxx
0123456789|yyyyyyyy
0123456789abcdef|xxxxxxxxxxxxxx
0123456789|yyyyyy
0123456789abcdef|xxxxxxxxxxxxxxxx
0123456789|yyyy
0123456789abcdef|xxxxxxxxxxxxxxxxxx
0123456789|yy
0123456789abcdef|xxxxxxxxxxxxxxxxxxxx
0123456789|
\pset format aligned
execute q;
-[ RECORD 1 ]----+---------------------
0123456789abcdef | xx
0123456789 | yyyyyyyyyyyyyyyyyy
-[ RECORD 2 ]----+---------------------
0123456789abcdef | xxxx
0123456789 | yyyyyyyyyyyyyyyy
-[ RECORD 3 ]----+---------------------
0123456789abcdef | xxxxxx
0123456789 | yyyyyyyyyyyyyy
-[ RECORD 4 ]----+---------------------
0123456789abcdef | xxxxxxxx
0123456789 | yyyyyyyyyyyy
-[ RECORD 5 ]----+---------------------
0123456789abcdef | xxxxxxxxxx
0123456789 | yyyyyyyyyy
-[ RECORD 6 ]----+---------------------
0123456789abcdef | xxxxxxxxxxxx
0123456789 | yyyyyyyy
-[ RECORD 7 ]----+---------------------
0123456789abcdef | xxxxxxxxxxxxxx
0123456789 | yyyyyy
-[ RECORD 8 ]----+---------------------
0123456789abcdef | xxxxxxxxxxxxxxxx
0123456789 | yyyy
-[ RECORD 9 ]----+---------------------
0123456789abcdef | xxxxxxxxxxxxxxxxxx
0123456789 | yy
-[ RECORD 10 ]---+---------------------
0123456789abcdef | xxxxxxxxxxxxxxxxxxxx
0123456789 |
\pset format wrapped
execute q;
-[ RECORD 1 ]----+-----------
0123456789abcdef | xx
0123456789 | yyyyyyyyyy.
|.yyyyyyyy
-[ RECORD 2 ]----+-----------
0123456789abcdef | xxxx
0123456789 | yyyyyyyyyy.
|.yyyyyy
-[ RECORD 3 ]----+-----------
0123456789abcdef | xxxxxx
0123456789 | yyyyyyyyyy.
|.yyyy
-[ RECORD 4 ]----+-----------
0123456789abcdef | xxxxxxxx
0123456789 | yyyyyyyyyy.
|.yy
-[ RECORD 5 ]----+-----------
0123456789abcdef | xxxxxxxxxx
0123456789 | yyyyyyyyyy
-[ RECORD 6 ]----+-----------
0123456789abcdef | xxxxxxxxxx.
|.xx
0123456789 | yyyyyyyy
-[ RECORD 7 ]----+-----------
0123456789abcdef | xxxxxxxxxx.
|.xxxx
0123456789 | yyyyyy
-[ RECORD 8 ]----+-----------
0123456789abcdef | xxxxxxxxxx.
|.xxxxxx
0123456789 | yyyy
-[ RECORD 9 ]----+-----------
0123456789abcdef | xxxxxxxxxx.
|.xxxxxxxx
0123456789 | yy
-[ RECORD 10 ]---+-----------
0123456789abcdef | xxxxxxxxxx.
|.xxxxxxxxxx
0123456789 |
\pset border 2
\pset format unaligned
execute q;
0123456789abcdef|xx
0123456789|yyyyyyyyyyyyyyyyyy
0123456789abcdef|xxxx
0123456789|yyyyyyyyyyyyyyyy
0123456789abcdef|xxxxxx
0123456789|yyyyyyyyyyyyyy
0123456789abcdef|xxxxxxxx
0123456789|yyyyyyyyyyyy
0123456789abcdef|xxxxxxxxxx
0123456789|yyyyyyyyyy
0123456789abcdef|xxxxxxxxxxxx
0123456789|yyyyyyyy
0123456789abcdef|xxxxxxxxxxxxxx
0123456789|yyyyyy
0123456789abcdef|xxxxxxxxxxxxxxxx
0123456789|yyyy
0123456789abcdef|xxxxxxxxxxxxxxxxxx
0123456789|yy
0123456789abcdef|xxxxxxxxxxxxxxxxxxxx
0123456789|
\pset format aligned
execute q;
+-[ RECORD 1 ]-----+----------------------+
| 0123456789abcdef | xx |
| 0123456789 | yyyyyyyyyyyyyyyyyy |
+-[ RECORD 2 ]-----+----------------------+
| 0123456789abcdef | xxxx |
| 0123456789 | yyyyyyyyyyyyyyyy |
+-[ RECORD 3 ]-----+----------------------+
| 0123456789abcdef | xxxxxx |
| 0123456789 | yyyyyyyyyyyyyy |
+-[ RECORD 4 ]-----+----------------------+
| 0123456789abcdef | xxxxxxxx |
| 0123456789 | yyyyyyyyyyyy |
+-[ RECORD 5 ]-----+----------------------+
| 0123456789abcdef | xxxxxxxxxx |
| 0123456789 | yyyyyyyyyy |
+-[ RECORD 6 ]-----+----------------------+
| 0123456789abcdef | xxxxxxxxxxxx |
| 0123456789 | yyyyyyyy |
+-[ RECORD 7 ]-----+----------------------+
| 0123456789abcdef | xxxxxxxxxxxxxx |
| 0123456789 | yyyyyy |
+-[ RECORD 8 ]-----+----------------------+
| 0123456789abcdef | xxxxxxxxxxxxxxxx |
| 0123456789 | yyyy |
+-[ RECORD 9 ]-----+----------------------+
| 0123456789abcdef | xxxxxxxxxxxxxxxxxx |
| 0123456789 | yy |
+-[ RECORD 10 ]----+----------------------+
| 0123456789abcdef | xxxxxxxxxxxxxxxxxxxx |
| 0123456789 | |
+------------------+----------------------+
\pset format wrapped
execute q;
+-[ RECORD 1 ]-----+---------+
| 0123456789abcdef | xx |
| 0123456789 | yyyyyyy.|
| |.yyyyyyy.|
| |.yyyy |
+-[ RECORD 2 ]-----+---------+
| 0123456789abcdef | xxxx |
| 0123456789 | yyyyyyy.|
| |.yyyyyyy.|
| |.yy |
+-[ RECORD 3 ]-----+---------+
| 0123456789abcdef | xxxxxx |
| 0123456789 | yyyyyyy.|
| |.yyyyyyy |
+-[ RECORD 4 ]-----+---------+
| 0123456789abcdef | xxxxxxx.|
| |.x |
| 0123456789 | yyyyyyy.|
| |.yyyyy |
+-[ RECORD 5 ]-----+---------+
| 0123456789abcdef | xxxxxxx.|
| |.xxx |
| 0123456789 | yyyyyyy.|
| |.yyy |
+-[ RECORD 6 ]-----+---------+
| 0123456789abcdef | xxxxxxx.|
| |.xxxxx |
| 0123456789 | yyyyyyy.|
| |.y |
+-[ RECORD 7 ]-----+---------+
| 0123456789abcdef | xxxxxxx.|
| |.xxxxxxx |
| 0123456789 | yyyyyy |
+-[ RECORD 8 ]-----+---------+
| 0123456789abcdef | xxxxxxx.|
| |.xxxxxxx.|
| |.xx |
| 0123456789 | yyyy |
+-[ RECORD 9 ]-----+---------+
| 0123456789abcdef | xxxxxxx.|
| |.xxxxxxx.|
| |.xxxx |
| 0123456789 | yy |
+-[ RECORD 10 ]----+---------+
| 0123456789abcdef | xxxxxxx.|
| |.xxxxxxx.|
| |.xxxxxx |
| 0123456789 | |
+------------------+---------+
\pset expanded on
\pset columns 20
\pset border 0
@ -1254,115 +1586,88 @@ execute q;
\pset format wrapped
execute q;
* Record 1
* Record 1
0123456789abcdef xx
0123456789 yy.
.yy.
.yy.
.yy.
.yy.
.yy.
.yy.
.yy.
0123456789 yyy.
.yyy.
.yyy.
.yyy.
.yyy.
.yyy
* Record 2
0123456789abcdef xxx.
.x
0123456789 yyy.
.yyy.
.yyy.
.yyy.
.yyy.
.y
* Record 3
0123456789abcdef xxx.
.xxx
0123456789 yyy.
.yyy.
.yyy.
.yyy.
.yy
* Record 2
0123456789abcdef xx.
* Record 4
0123456789abcdef xxx.
.xxx.
.xx
0123456789 yy.
.yy.
.yy.
.yy.
.yy.
.yy.
.yy.
0123456789 yyy.
.yyy.
.yyy.
.yyy
* Record 5
0123456789abcdef xxx.
.xxx.
.xxx.
.x
0123456789 yyy.
.yyy.
.yyy.
.y
* Record 6
0123456789abcdef xxx.
.xxx.
.xxx.
.xxx
0123456789 yyy.
.yyy.
.yy
* Record 3
0123456789abcdef xx.
.xx.
.xx
0123456789 yy.
.yy.
.yy.
.yy.
.yy.
.yy.
.yy
* Record 4
0123456789abcdef xx.
.xx.
.xx.
.xx
0123456789 yy.
.yy.
.yy.
.yy.
.yy.
.yy
* Record 5
0123456789abcdef xx.
.xx.
.xx.
.xx.
.xx
0123456789 yy.
.yy.
.yy.
.yy.
.yy
* Record 6
0123456789abcdef xx.
.xx.
.xx.
.xx.
.xx.
.xx
0123456789 yy.
.yy.
.yy.
.yy
* Record 7
0123456789abcdef xx.
.xx.
.xx.
.xx.
.xx.
.xx.
.xx
0123456789 yy.
.yy.
.yy
* Record 8
0123456789abcdef xx.
.xx.
.xx.
.xx.
.xx.
.xx.
.xx.
.xx
0123456789 yy.
.yy
* Record 9
0123456789abcdef xx.
.xx.
.xx.
.xx.
.xx.
.xx.
.xx.
.xx.
* Record 7
0123456789abcdef xxx.
.xxx.
.xxx.
.xxx.
.xx
0123456789 yyy.
.yyy
* Record 8
0123456789abcdef xxx.
.xxx.
.xxx.
.xxx.
.xxx.
.x
0123456789 yyy.
.y
* Record 9
0123456789abcdef xxx.
.xxx.
.xxx.
.xxx.
.xxx.
.xxx
0123456789 yy
* Record 10
0123456789abcdef xx.
.xx.
.xx.
.xx.
.xx.
.xx.
.xx.
.xx.
.xx.
* Record 10
0123456789abcdef xxx.
.xxx.
.xxx.
.xxx.
.xxx.
.xxx.
.xx
0123456789

View File

@ -193,6 +193,33 @@ execute q;
\pset format wrapped
execute q;
\pset expanded on
\pset columns 30
\pset border 0
\pset format unaligned
execute q;
\pset format aligned
execute q;
\pset format wrapped
execute q;
\pset border 1
\pset format unaligned
execute q;
\pset format aligned
execute q;
\pset format wrapped
execute q;
\pset border 2
\pset format unaligned
execute q;
\pset format aligned
execute q;
\pset format wrapped
execute q;
\pset expanded on
\pset columns 20