Re: Counting lines correctly in psql help displays

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Counting lines correctly in psql help displays
Date: 2015-09-09 04:23:07
Message-ID: 55EFB42B.6020306@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 09/05/2015 12:55 PM, Tom Lane wrote:
> I wrote:
>> BTW, I noticed that the PageOutput line counts for psql's usage(),
>> slashUsage(), and helpVariables() were all three wrong, which I'm afraid
>> has been their usual state in the past too. Since commit 07c8651dd91d5aea
>> there's been a pretty easy way to check them, which I added comments
>> about; but I don't hold much hope that that will fix anything. I wonder
>> whether there's some way to not need to maintain those counts manually.
> I seem to recall past proposals to fix that by putting the lines into
> static char * arrays, which foundered on the fact that the output's not
> necessarily constant. But it suddenly strikes me that there's an easy
> fix. We can generate the output into a PQExpBuffer, which is just as
> flexible as fprintf() is today, then count the lines and finally print.
>
> Ordinarily I might think that was overkill, but given the number of times
> that we've failed to update those counts in the past, I think this is
> definitely a worthwhile investment in maintainability.
>
> Or we could just give up and replace the counts by INT_MAX, forcing use
> of the pager unless you've turned it off. All of those outputs are long
> enough now that it's hard to believe there are any common screen layouts
> where you don't end up invoking the pager anyway. (usage() is 60 lines,
> the others are more.) This is probably the reason why we've seldom
> noticed they're wrong --- it barely matters anymore.
>
> One way or the other I think it's past time to get out of the business
> of maintaining these counts. I'm willing to do the work of using a
> PQExpBuffer if people think it's worth the trouble to have an accurate
> count, but it may not be worth the code space.
>
> Thoughts?
>
>

I'm not terribly happy about the INT_MAX idea. Counting lines in a
PGExpBuffer seems OK. That way we could honor pager_min_lines, I hope.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2015-09-09 06:01:36 Re: Use pg_rewind when target timeline was switched
Previous Message Pavel Stehule 2015-09-09 03:33:00 Re: proposal: function parse_ident