Re: pgbench - allow backslash-continuations in custom scripts

From: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: robertmhaas(at)gmail(dot)com, coelho(at)cri(dot)ensmp(dot)fr, michael(dot)paquier(at)gmail(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pgbench - allow backslash-continuations in custom scripts
Date: 2016-03-22 10:14:33
Message-ID: 20160322.191433.230703771.horiguchi.kyotaro@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

First, thank you all involved, and thank you for polishing this
and committing, Tom.

At Mon, 21 Mar 2016 17:15:18 -0400, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote in <1596(dot)1458594918(at)sss(dot)pgh(dot)pa(dot)us>
> So I looked into this, and found that persuading psql to let backslash
> commands cross line boundaries is a much bigger deal than just fixing the
> lexer. The problem is that MainLoop would need to grow an understanding
> of having received only a partial backslash command and needing to go back
> to readline() for another line. And probably HandleSlashCmds would need
> to be changed to stop parsing and back out without doing anything when it
> hits backslash-newline. It's do-able no doubt, but it's not going to be a
> small and simple patch.

I agree.

> However, since pgbench is already set up to slurp the entire file and
> lex it in one go, it is just a trivial adjustment to the lexer rules in
> that program. The only thing I found that made it complicated is that
> syntax_error() had too simplistic an understanding of how to position
> the error cursor usefully, so that needed a bit of work.

The modified lexer treats {backslash}{newline} as the same with
whitespace and it looks ok for me.

> /test.sql:6: syntax error, unexpected FUNCTION, expecting $end in command "set"
> \set naccounts\
> 10x0
> ^ error found here

The error message seems fine. (The mysterious message would be
another problem.) But it prints the lines after the error indicator.

> \set naccounts\
> 10x0\
> ^ error found here
> * :scale

I suppose that the trailing lines might be better not be
printed. (gcc doesn't seem to do so.)

> I think it'd be okay to commit this without fixing psql at the same time;
> if you try it in psql you get an error, so on that side it's unimplemented
> behavior rather than an actual incompatibility. Perhaps somebody will be
> motivated to fix it later, but I'm not going to spend that kind of time
> on it right now.
>
> I've not written a docs update, but otherwise I think this is committable.
> Comments?
>
> regards, tom lane

regards,

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexey Grishchenko 2016-03-22 10:15:16 Re: Endless loop calling PL/Python set returning functions
Previous Message Fabien COELHO 2016-03-22 10:09:38 Re: checkpointer continuous flushing