Re: pgbench - allow backslash-continuations in custom scripts

From: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>
To: coelho(at)cri(dot)ensmp(dot)fr
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, andres(at)anarazel(dot)de, hlinnaka(at)iki(dot)fi, josh(at)agliodbs(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pgbench - allow backslash-continuations in custom scripts
Date: 2015-07-24 03:15:14
Message-ID: 20150724.121514.70011563.horiguchi.kyotaro@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

> If you feel that this feature only deserve a lexer solution, then the
> patch should be "returned with feedback".

It's unfortunate to abandon this idea so I tried this and made it
run with psql's parser. I think it works as expected.

The attached files are as follwoing.

- 0001-Prepare-for-share-psqlscan-with-pgbench.patch
A patch to modify psql so that psqlscan can be shared with other modules.

- 0002-Make-use-of-psqlscan-in-pgbench.patch
A patch to use psqlscan in pgbench.

- hoge.sql
A sample custom script including multilne statement and line comment

I can't judge wheter this is a new version of Febien's patch
following Tom's suggestion or brand-new one. Anyway I'd like to
post on this thread.

======
At Fri, 17 Jul 2015 21:26:44 +0200 (CEST), Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> wrote in <alpine(dot)DEB(dot)2(dot)10(dot)1507172113080(dot)31314(at)sto>
> > Pgbench variable substitution is performed when the script is run, not
> > while the file is being processed for being split, which is when a
> > lexer would be used. The situation is not the same with psql. The most
> > it could do would be to keep track of what substitution are done in
> > queries.
> >
> >> So this is looking *eminently* doable.
> >
> > Possibly. How much more effort would be involved compared to the
> > quick patch I did, I wonder:-)

The patch set consists of two parts.

The first modifies psqlscan.l to work in pgbench. Almost along on
Tom's suggestion.

- Eliminate direct reading of pset and store them into
PsqlScanState in psql_scan_setup.

- variables, common, settings and prompt in pgbench are the
shrinked version from that of psql.

The second part modifies pgbench to use the modified version of
psqlscan.l. As the result,

- Multiline SQLs (not backslash continuation) in custom script is
allowed. (also for builtins but it's no use).

- backslash commands is handled as the same as before: multiline
is not allowed.

A sample script is also attached.

Suggestions? Opinions?

I don't have idea how to deal with the copy of psqlscan.[lh] from
psql. Currently they are simply the dead copies of those of psql.

- Modifying psqlscan in psql requires consideration on how it is
used in pgbench.

- They are rather small but common, variables, prompt are
essentially needeless files..

reagsrds,

--
Kyotaro Horiguchi
NTT Open Source Software Center

Attachment Content-Type Size
0001-Prepare-for-share-psqlscan-with-pgbench.patch text/x-patch 7.0 KB
0002-Make-use-of-psqlscan-in-pgbench.patch text/x-patch 71.4 KB
unknown_filename text/plain 178 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2015-07-24 04:26:25 Re: RFC: replace pg_stat_activity.waiting with something more descriptive
Previous Message Alvaro Herrera 2015-07-24 01:14:04 Re: BRIN index and aborted transaction