- Notifications
You must be signed in to change notification settings - Fork5.1k
Commit27da1a7
committed
Improve psql's ability to select pager mode accurately.
We try to use the pager only when more than a screenful's worth ofdata is to be printed. However, the code in print.c that's concernedwith counting the number of lines that will be needed missed a lot ofedge cases:* While plain aligned mode accounted for embedded newlines in columnheaders and table cells, unaligned and vertical output modes did not.* In particular, since vertical mode repeats the headers for eachrecord, we need to account for embedded newlines in the headers foreach record.* Multi-line table titles were not accounted for.* tuples_only mode (where headers aren't printed) wasn't accountedfor.* Footers were accounted for as one line per footer, again missingthe possibility of multi-line footers. (In some cases such as"\d+" on a view, there can be many lines in a footer.) Also,we failed to account for the default footer.To fix, move the entire responsibility for counting lines intoIsPagerNeeded (or actually, into a new subroutine count_table_lines),and then expand the logic as appropriate. Also restructure to make itperhaps a bit easier to follow. It's still only completely accuratefor ALIGNED/WRAPPED/UNALIGNED formats, but the other formats are nottypically used with interactive output.Arrange to not run count_table_lines at all unless we will useits result, and teach it to quit early as soon as it's proventhat the output is long enough to require use of the pager.When dealing with large tables this should save a noticeableamount of time, since pg_wcssize() isn't exactly cheap.In passing, move the "flog" output step to the bottom of printTable(),rather than running it when we've already opened the pager in somemodes. In principle it shouldn't interfere with the pager becauseflog should always point to a non-interactive file; but it seems sillyto risk any interference, especially when the existing positioningseems to have been chosen with the aid of a dartboard.Also add a TAP test to exercise pager mode. Up to now, we have hadzero test coverage of these code paths, because they aren't reachedunless isatty(stdout). We do have the test infrastructure to improvethat situation, though. Following the lead of 010_tab_completion.pl,set up an interactive psql and feed it some test cases. To detectwhether it really did invoke the pager, point PSQL_PAGER to "wc -l".The test is skipped if that utility isn't available.Author: Erik Wienhold <ewie@ewie.name>Test-authored-by: Tom Lane <tgl@sss.pgh.pa.us>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/2dd2430f-dd20-4c89-97fd-242616a3d768@ewie.name1 parent8c49a48 commit27da1a7
3 files changed
+382
-84
lines changedOriginal file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
77 | 77 |
| |
78 | 78 |
| |
79 | 79 |
| |
| 80 | + | |
80 | 81 |
| |
81 | 82 |
| |
82 | 83 |
| |
|
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + |
0 commit comments
Comments
(0)