Unix Technical Forum

statement logging / extended query protocol issues

This is a discussion on statement logging / extended query protocol issues within the pgsql Hackers forums, part of the PostgreSQL category; --> On Thu, 2005-09-08 at 13:14 +1200, Oliver Jowett wrote: > Simon Riggs wrote: > > Oliver, would it be ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

 

LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 04-11-2008, 06:41 AM
Simon Riggs
 
Posts: n/a
Default Re: statement logging / extended query protocol issues

On Thu, 2005-09-08 at 13:14 +1200, Oliver Jowett wrote:
> Simon Riggs wrote:
> > Oliver, would it be possible to show a simplified call sequence and what
> > you would like to see logged for each call?


These are good: Maybe it should even be in the docs for the driver?
It would be good if it could be written as a test within the driver, so
we can expand it and test the logging.

> The JDBC driver generates one of these sequences:
>
> (1)
> Parse (unnamed statement) "SELECT 1"
> Bind (unnamed statement -> unnamed portal)
> Execute (unnamed portal, no row limit)
>
> (2)
> Parse (named statement S_1) "SELECT 1"
> repeatedly:
> Bind (named statement S_1 -> unnamed portal)
> Execute (unnamed portal, no row limit)
>
> (3)
> Parse (named statement S_2) "SELECT 1"
> repeatedly:
> Bind (named statement S_2 -> named portal C_2)
> repeatedly:
> Execute (named portal C_2, row limit 42)


Are we sure there is just 3 cases?

> Ideal output is:
>
> (1) LOG: statement: SELECT 1
>
> (2) LOG: statement: SELECT 1
> LOG: statement: SELECT 1
> LOG: statement: SELECT 1
>
> (3) LOG: statement: SELECT 1
> LOG: statement: SELECT 1
> LOG: statement: SELECT 1
>
> In case (3), that's one log line per repeat of the outer loop,
> regardless of how many Executes are sent in the inner loop.


> Note that case (1) is the most common case for application queries via
> the JDBC driver, and case (2) is the most common for internally
> generated statements like BEGIN.


Even if case (3) is not that common, I still want to know it is
occurring, to see what effect or overhead it has.

> As you can see from the output I'd like, I don't think that synthesizing
> FETCH / EXECUTE queries that don't actually exist [is a]
> useful thing to do, at least at the Joe Average User
> level.


Your original point at the top of this thread was valid: a get-next-rows
shouldn't look like a re-execute. We can call it something else if you
like, as long as we can tell the difference.

We'll only see the output for case (3) when someone has programmed
things that way by using setFetchSize.

> Also note that the JDBC driver doesn't exercise all of the extended
> protocol -- for example it's possible to re-Bind the same unnamed
> statement repeatedly, or have multiple Executes on an unnamed portal
> with a row limit, but the JDBC driver never does that.


I agree there's not much gained from displaying the BIND statement as it
is. I argued previously against including the BIND parameters. Now I
would say we should either include them or leave out BIND altogether.

Here's a new suggestion and patch that brings together
- Oliver and Simon's wish to remove BIND from normal logging
- Oliver's suggestion to remove the PREPARE logging for unnamed
statements, which would otherwise double-up logging for case(1)
- Bruce and Simon's view to keep some form of FETCH logging
- Tom's view to rationalise the way ROWS is mentioned

(lines beginning jdbc don't show in the log, but are just there to show
clearly the time sequence of activities and what gets subsequently
logged)

(1)
> Parse (unnamed statement) "SELECT * from pg_proc"
> Bind (unnamed statement -> unnamed portal)
> Execute (unnamed portal, no row limit)


(1)
jdbc parse
jdbc bind
jdbc execute
LOG: statement: SELECT * from pg_proc

jdbc parse
jdbc bind
jdbc execute
LOG: statement: SELECT * from pg_proc

jdbc parse
jdbc bind
jdbc execute
LOG: statement: SELECT * from pg_proc


Notice that the parse of the unnamed statement does *not* now generate a
log record.

(2)
> Parse (named statement S_1) "SELECT * from pg_proc"
> repeatedly:
> Bind (named statement S_1 -> unnamed portal)
> Execute (unnamed portal, no row limit)


(2)
jdbc parse S_1
LOG: statement: PREPARE S_1 AS SELECT * from pg_proc
(perhaps this should be logged at BIND time, just like the
optimization?)

jdbc bind S_1
jdbc execute
LOG: statement: EXECUTE <unnamed> [PREPARE: SELECT * from pg_proc]

jdbc bind S_1
jdbc execute
LOG: statement: EXECUTE <unnamed> [PREPARE: SELECT * from pg_proc]

jdbc bind S_1
jdbc execute
LOG: statement: EXECUTE <unnamed> [PREPARE: SELECT * from pg_proc]


....I wonder if <unnamed> just confuses what is going on here? I've left
it in for now, but suggest that we take that out again?

(3)
> Parse (named statement S_2) "SELECT * from pg_proc"
> repeatedly:
> Bind (named statement S_2 -> named portal C_2)
> repeatedly:
> Execute (named portal C_2, row limit 42)


(3)
jdbc prepare S_2
LOG: statement: PREPARE S_2 AS SELECT * from pg_proc

jdbc bind S_2 to C_2
jdbc execute C_2
LOG: statement: EXECUTE C_2 ROWS 42 [PREPARE: SELECT * from pg_proc]
jdbc next (after cache has run out on 42nd row)
v3 protocol sends E for Execute, execution halts at 49 rows for this set
of bind parameters
LOG: statement: FETCH C_2 ROWS 7

jdbc bind S_2 to C_2
jdbc execute C_2
LOG: statement: EXECUTE C_2 ROWS 42 [PREPARE: SELECT * from pg_proc]
jdbc next (after cache has run out on 42nd row)
v3 protocol sends E for Execute
LOG: statement: FETCH C_2 ROWS 42
jdbc next (after cache has run out on 84th row)
v3 protocol sends E for Execute, execution halts at 95 rows for this set
of bind parameters
LOG: statement: FETCH C_2 ROWS 11

Note: log_min_duration_statement logs after execution so can give
accurate row counts of what was retrieved for first execute and
subsequent fetches. In that case we log using the word ROWS.
log_statement=all logs before execution and so only knows what the
maximum number of rows requested is, not what the actual number of rows
retrieved will be. In that case we log using the word MAXROWS.
ROWS and MAXROWS are *not* mentioned unless we specifically set max_rows
in the execute request using the v3 protocol.

If we agree, I'd suggest this goes into the docs...

I've not written a comprehensive test program that covers all of the
different settings of v2/v3, named/unnamed, allrows/restricted rows,
log_statement=all/log_min_duration_statement. I'm not sure that will fit
within the existing test framework. So this patch is still prototype.

Comments?

Best Regards, Simon Riggs


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 04-11-2008, 06:43 AM
Oliver Jowett
 
Posts: n/a
Default Re: statement logging / extended query protocol issues

Simon Riggs wrote:

> Are we sure there is just 3 cases?


I haven't exhaustively checked, but I think those are the main cases.

> Even if case (3) is not that common, I still want to know it is
> occurring, to see what effect or overhead it has.


I don't want it to be more verbose than the other cases when I set
log_statement = all.

> We'll only see the output for case (3) when someone has programmed
> things that way by using setFetchSize.


Can we put extra output in this case into log_statement = verbose only
please?

> (1)
> jdbc parse
> jdbc bind
> jdbc execute
> LOG: statement: SELECT * from pg_proc


> Notice that the parse of the unnamed statement does *not* now generate a
> log record.


What about the syntax error case?

> (2)
> jdbc parse S_1
> LOG: statement: PREPARE S_1 AS SELECT * from pg_proc
> (perhaps this should be logged at BIND time, just like the
> optimization?)
>
> jdbc bind S_1
> jdbc execute
> LOG: statement: EXECUTE <unnamed> [PREPARE: SELECT * from pg_proc]


I do not like logging queries that the driver never sent (the driver
sends neither PREPARE nor EXECUTE).

I also don't see why it's useful to log the statement and portal names.

Can we reword this to what I suggested previously?

LOG: parse statement: SELECT * from pg_proc
LOG: execute statement: SELECT * from pg_proc

> (3)
> jdbc prepare S_2
> LOG: statement: PREPARE S_2 AS SELECT * from pg_proc
>
> jdbc bind S_2 to C_2
> jdbc execute C_2
> LOG: statement: EXECUTE C_2 ROWS 42 [PREPARE: SELECT * from pg_proc]
> jdbc next (after cache has run out on 42nd row)
> v3 protocol sends E for Execute, execution halts at 49 rows for this set
> of bind parameters
> LOG: statement: FETCH C_2 ROWS 7


Again I do not like logging synthetic queries that the driver never sent
(PREPARE / EXECUTE / FETCH). BTW, if you do it this way, you could get
the bizarre "PREPARE S_2 AS PREPARE xyz AS SELECT .." result if the
application used PREPARE itself.

I think that logging the second and subsequent Executes is not normally
useful and shouldn't happen when log_statement = all. In that case you
don't need to log the portal name either.

So for the normal case:

LOG: parse statement: SELECT * from pg_proc
LOG: execute statement: SELECT * from pg_proc

and for the verbose case perhaps something like:

LOG: parse statement: SELECT * from pg_proc
LOG: execute statement (C_2, 42 rows): SELECT * from pg_proc
LOG: fetch statement results (C_2, 7 rows)

-O

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 04-11-2008, 06:46 AM
Bruce Momjian
 
Posts: n/a
Default Re: statement logging / extended query protocol issues


Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------


Simon Riggs wrote:
> On Thu, 2005-09-08 at 13:14 +1200, Oliver Jowett wrote:
> > Simon Riggs wrote:
> > > Oliver, would it be possible to show a simplified call sequence and what
> > > you would like to see logged for each call?

>
> These are good: Maybe it should even be in the docs for the driver?
> It would be good if it could be written as a test within the driver, so
> we can expand it and test the logging.
>
> > The JDBC driver generates one of these sequences:
> >
> > (1)
> > Parse (unnamed statement) "SELECT 1"
> > Bind (unnamed statement -> unnamed portal)
> > Execute (unnamed portal, no row limit)
> >
> > (2)
> > Parse (named statement S_1) "SELECT 1"
> > repeatedly:
> > Bind (named statement S_1 -> unnamed portal)
> > Execute (unnamed portal, no row limit)
> >
> > (3)
> > Parse (named statement S_2) "SELECT 1"
> > repeatedly:
> > Bind (named statement S_2 -> named portal C_2)
> > repeatedly:
> > Execute (named portal C_2, row limit 42)

>
> Are we sure there is just 3 cases?
>
> > Ideal output is:
> >
> > (1) LOG: statement: SELECT 1
> >
> > (2) LOG: statement: SELECT 1
> > LOG: statement: SELECT 1
> > LOG: statement: SELECT 1
> >
> > (3) LOG: statement: SELECT 1
> > LOG: statement: SELECT 1
> > LOG: statement: SELECT 1
> >
> > In case (3), that's one log line per repeat of the outer loop,
> > regardless of how many Executes are sent in the inner loop.

>
> > Note that case (1) is the most common case for application queries via
> > the JDBC driver, and case (2) is the most common for internally
> > generated statements like BEGIN.

>
> Even if case (3) is not that common, I still want to know it is
> occurring, to see what effect or overhead it has.
>
> > As you can see from the output I'd like, I don't think that synthesizing
> > FETCH / EXECUTE queries that don't actually exist [is a]
> > useful thing to do, at least at the Joe Average User
> > level.

>
> Your original point at the top of this thread was valid: a get-next-rows
> shouldn't look like a re-execute. We can call it something else if you
> like, as long as we can tell the difference.
>
> We'll only see the output for case (3) when someone has programmed
> things that way by using setFetchSize.
>
> > Also note that the JDBC driver doesn't exercise all of the extended
> > protocol -- for example it's possible to re-Bind the same unnamed
> > statement repeatedly, or have multiple Executes on an unnamed portal
> > with a row limit, but the JDBC driver never does that.

>
> I agree there's not much gained from displaying the BIND statement as it
> is. I argued previously against including the BIND parameters. Now I
> would say we should either include them or leave out BIND altogether.
>
> Here's a new suggestion and patch that brings together
> - Oliver and Simon's wish to remove BIND from normal logging
> - Oliver's suggestion to remove the PREPARE logging for unnamed
> statements, which would otherwise double-up logging for case(1)
> - Bruce and Simon's view to keep some form of FETCH logging
> - Tom's view to rationalise the way ROWS is mentioned
>
> (lines beginning jdbc don't show in the log, but are just there to show
> clearly the time sequence of activities and what gets subsequently
> logged)
>
> (1)
> > Parse (unnamed statement) "SELECT * from pg_proc"
> > Bind (unnamed statement -> unnamed portal)
> > Execute (unnamed portal, no row limit)

>
> (1)
> jdbc parse
> jdbc bind
> jdbc execute
> LOG: statement: SELECT * from pg_proc
>
> jdbc parse
> jdbc bind
> jdbc execute
> LOG: statement: SELECT * from pg_proc
>
> jdbc parse
> jdbc bind
> jdbc execute
> LOG: statement: SELECT * from pg_proc
>
>
> Notice that the parse of the unnamed statement does *not* now generate a
> log record.
>
> (2)
> > Parse (named statement S_1) "SELECT * from pg_proc"
> > repeatedly:
> > Bind (named statement S_1 -> unnamed portal)
> > Execute (unnamed portal, no row limit)

>
> (2)
> jdbc parse S_1
> LOG: statement: PREPARE S_1 AS SELECT * from pg_proc
> (perhaps this should be logged at BIND time, just like the
> optimization?)
>
> jdbc bind S_1
> jdbc execute
> LOG: statement: EXECUTE <unnamed> [PREPARE: SELECT * from pg_proc]
>
> jdbc bind S_1
> jdbc execute
> LOG: statement: EXECUTE <unnamed> [PREPARE: SELECT * from pg_proc]
>
> jdbc bind S_1
> jdbc execute
> LOG: statement: EXECUTE <unnamed> [PREPARE: SELECT * from pg_proc]
>
>
> ...I wonder if <unnamed> just confuses what is going on here? I've left
> it in for now, but suggest that we take that out again?
>
> (3)
> > Parse (named statement S_2) "SELECT * from pg_proc"
> > repeatedly:
> > Bind (named statement S_2 -> named portal C_2)
> > repeatedly:
> > Execute (named portal C_2, row limit 42)

>
> (3)
> jdbc prepare S_2
> LOG: statement: PREPARE S_2 AS SELECT * from pg_proc
>
> jdbc bind S_2 to C_2
> jdbc execute C_2
> LOG: statement: EXECUTE C_2 ROWS 42 [PREPARE: SELECT * from pg_proc]
> jdbc next (after cache has run out on 42nd row)
> v3 protocol sends E for Execute, execution halts at 49 rows for this set
> of bind parameters
> LOG: statement: FETCH C_2 ROWS 7
>
> jdbc bind S_2 to C_2
> jdbc execute C_2
> LOG: statement: EXECUTE C_2 ROWS 42 [PREPARE: SELECT * from pg_proc]
> jdbc next (after cache has run out on 42nd row)
> v3 protocol sends E for Execute
> LOG: statement: FETCH C_2 ROWS 42
> jdbc next (after cache has run out on 84th row)
> v3 protocol sends E for Execute, execution halts at 95 rows for this set
> of bind parameters
> LOG: statement: FETCH C_2 ROWS 11
>
> Note: log_min_duration_statement logs after execution so can give
> accurate row counts of what was retrieved for first execute and
> subsequent fetches. In that case we log using the word ROWS.
> log_statement=all logs before execution and so only knows what the
> maximum number of rows requested is, not what the actual number of rows
> retrieved will be. In that case we log using the word MAXROWS.
> ROWS and MAXROWS are *not* mentioned unless we specifically set max_rows
> in the execute request using the v3 protocol.
>
> If we agree, I'd suggest this goes into the docs...
>
> I've not written a comprehensive test program that covers all of the
> different settings of v2/v3, named/unnamed, allrows/restricted rows,
> log_statement=all/log_min_duration_statement. I'm not sure that will fit
> within the existing test framework. So this patch is still prototype.
>
> Comments?
>
> Best Regards, Simon Riggs


[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings


--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 04-11-2008, 06:46 AM
Bruce Momjian
 
Posts: n/a
Default Re: statement logging / extended query protocol issues

Oliver Jowett wrote:
> Simon Riggs wrote:
>
> > Are we sure there is just 3 cases?

>
> I haven't exhaustively checked, but I think those are the main cases.
>
> > Even if case (3) is not that common, I still want to know it is
> > occurring, to see what effect or overhead it has.

>
> I don't want it to be more verbose than the other cases when I set
> log_statement = all.


I think it is more verbose because no FETCH is logged in this type of
prepare/execute. The goal, I think, is for these type of queries to
look as similar to normal PREPARE/EXECUTE and DECLARE/FETCH as possible.

> > We'll only see the output for case (3) when someone has programmed
> > things that way by using setFetchSize.

>
> Can we put extra output in this case into log_statement = verbose only
> please?


We don't have a log_statement = verbose mode.

> > (1)
> > jdbc parse
> > jdbc bind
> > jdbc execute
> > LOG: statement: SELECT * from pg_proc

>
> > Notice that the parse of the unnamed statement does *not* now generate a
> > log record.

>
> What about the syntax error case?


Good point, but when do we parse? Could you set log_min_error_statement
to error? I don't think that would work either.

> > (2)
> > jdbc parse S_1
> > LOG: statement: PREPARE S_1 AS SELECT * from pg_proc
> > (perhaps this should be logged at BIND time, just like the
> > optimization?)
> >
> > jdbc bind S_1
> > jdbc execute
> > LOG: statement: EXECUTE <unnamed> [PREPARE: SELECT * from pg_proc]

>
> I do not like logging queries that the driver never sent (the driver
> sends neither PREPARE nor EXECUTE).
>
> I also don't see why it's useful to log the statement and portal names.
>
> Can we reword this to what I suggested previously?
>
> LOG: parse statement: SELECT * from pg_proc
> LOG: execute statement: SELECT * from pg_proc


The problem here is that scripts that look for "LOG: statement:" would
now need to look for additional words at the start. It also makes this
type of prepare/execute look different in the logs, while internally it
is quite similar.

> > (3)
> > jdbc prepare S_2
> > LOG: statement: PREPARE S_2 AS SELECT * from pg_proc
> >
> > jdbc bind S_2 to C_2
> > jdbc execute C_2
> > LOG: statement: EXECUTE C_2 ROWS 42 [PREPARE: SELECT * from pg_proc]
> > jdbc next (after cache has run out on 42nd row)
> > v3 protocol sends E for Execute, execution halts at 49 rows for this set
> > of bind parameters
> > LOG: statement: FETCH C_2 ROWS 7

>
> Again I do not like logging synthetic queries that the driver never sent
> (PREPARE / EXECUTE / FETCH). BTW, if you do it this way, you could get
> the bizarre "PREPARE S_2 AS PREPARE xyz AS SELECT .." result if the
> application used PREPARE itself.
>
> I think that logging the second and subsequent Executes is not normally
> useful and shouldn't happen when log_statement = all. In that case you
> don't need to log the portal name either.
>
> So for the normal case:
>
> LOG: parse statement: SELECT * from pg_proc
> LOG: execute statement: SELECT * from pg_proc
>
> and for the verbose case perhaps something like:
>
> LOG: parse statement: SELECT * from pg_proc
> LOG: execute statement (C_2, 42 rows): SELECT * from pg_proc
> LOG: fetch statement results (C_2, 7 rows)


We don't have a verbose case. Why should it look different from
client-side stuff?

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 04-11-2008, 06:46 AM
Oliver Jowett
 
Posts: n/a
Default Re: statement logging / extended query protocol issues

Bruce Momjian wrote:

> We don't have a log_statement = verbose mode.


Please see my earlier email where I suggested adding one if you really
wanted all this protocol-level detail logged.

-O

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 04-11-2008, 06:46 AM
Oliver Jowett
 
Posts: n/a
Default Re: statement logging / extended query protocol issues

Bruce Momjian wrote:

> I think it is more verbose because no FETCH is logged in this type of
> prepare/execute. The goal, I think, is for these type of queries to
> look as similar to normal PREPARE/EXECUTE and DECLARE/FETCH as possible.


I do not understand why this is a useful thing to do as part of
log_statement.

My point is that given JDBC code like this:

Statement s = connection.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM pg_proc");
while (rs.next()) {
// Process results
}

it seems that the least surprising thing to get logged is simply "SELECT
* FROM pg_proc".

I don't see how logging a synthetic PREPARE/EXECUTE/FETCH sequence (and
DECLARE, now?) is useful. They're not necessarily syntactically correct,
and they're certainly not queries that were actually sent to the
backend. I thought log_statement was meant to answer the question "what
queries were submitted to the backend?", rather than to provide a trace
of protocol-level activity..

-O

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 04-11-2008, 06:47 AM
Bruce Momjian
 
Posts: n/a
Default Re: statement logging / extended query protocol issues

Oliver Jowett wrote:
> Bruce Momjian wrote:
>
> > We don't have a log_statement = verbose mode.

>
> Please see my earlier email where I suggested adding one if you really
> wanted all this protocol-level detail logged.


We can't add that in feature freeze/beta, at least.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 04-11-2008, 06:47 AM
Bruce Momjian
 
Posts: n/a
Default Re: statement logging / extended query protocol issues

Oliver Jowett wrote:
> Bruce Momjian wrote:
>
> > I think it is more verbose because no FETCH is logged in this type of
> > prepare/execute. The goal, I think, is for these type of queries to
> > look as similar to normal PREPARE/EXECUTE and DECLARE/FETCH as possible.

>
> I do not understand why this is a useful thing to do as part of
> log_statement.
>
> My point is that given JDBC code like this:
>
> Statement s = connection.createStatement();
> ResultSet rs = s.executeQuery("SELECT * FROM pg_proc");
> while (rs.next()) {
> // Process results
> }
>
> it seems that the least surprising thing to get logged is simply "SELECT
> * FROM pg_proc".
>
> I don't see how logging a synthetic PREPARE/EXECUTE/FETCH sequence (and
> DECLARE, now?) is useful. They're not necessarily syntactically correct,
> and they're certainly not queries that were actually sent to the
> backend. I thought log_statement was meant to answer the question "what
> queries were submitted to the backend?", rather than to provide a trace
> of protocol-level activity..


Well, from the application writer perspective, you are right it doesn't
make sense, but this is only because jdbc is using prepare internally.
If you were to have written it in libpq, it would make sense, I think,
and internally, this is what is happening. We can't assume only
interface libraries like jdbc are using this feature.

As far as I understand things, the protocol-level prepare/execute is
identical to the SQL-level prepare/execute, except that there is no need
to parse the execute, so it should log like the SQL-level statements, if
possible.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 04-11-2008, 06:47 AM
Oliver Jowett
 
Posts: n/a
Default Re: statement logging / extended query protocol issues

Bruce Momjian wrote:

> Well, from the application writer perspective, you are right it doesn't
> make sense,


This is exactly what the end user is going to say.

> but this is only because jdbc is using prepare internally.


Isn't this mostly irrelevant to the result we want to see? It's a detail
of how the interface layer chooses to execute its queries, and 90% of
the time the end user is not going to know or care about it.

> If you were to have written it in libpq, it would make sense, I think,
> and internally, this is what is happening. We can't assume only
> interface libraries like jdbc are using this feature.


Wait, so is the extended query protocol the poor cousin of "what libpq
does", or what? You can do Parse/Bind using libpq, can't you?

The *meaning* of the Parse/Bind/Execute sequence is quite clear
regardless of what interface library is used. I still think that logging
just the queries that were actually executed, once per execution, is the
sensible thing to do here. I can't see a sequence of protocol messages
that would produce a strange result if we used the rules I suggested --
do you have an example where it breaks?

> As far as I understand things, the protocol-level prepare/execute is
> identical to the SQL-level prepare/execute, except that there is no need
> to parse the execute, so it should log like the SQL-level statements, if
> possible.


You can Parse any SQL statement, but you can't PREPARE any SQL
statement. So, no, they're not equivalent. That's one aspect of what I
meant about generating synthetic statements that weren't syntactially
correct (the strange FETCH syntax with ROWS/MAXROWS that Simon was
suggesting is another case).

-O

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 04-11-2008, 06:48 AM
Bruce Momjian
 
Posts: n/a
Default Re: statement logging / extended query protocol issues

Oliver Jowett wrote:
> Bruce Momjian wrote:
>
> > Well, from the application writer perspective, you are right it doesn't
> > make sense,

>
> This is exactly what the end user is going to say.
>
> > but this is only because jdbc is using prepare internally.

>
> Isn't this mostly irrelevant to the result we want to see? It's a detail
> of how the interface layer chooses to execute its queries, and 90% of
> the time the end user is not going to know or care about it.


Right, but have no way to know if the user is using an interface that
hides prepares from them, or they are using prepares visibly in their
applications. For this reason, we should just display whatever the
backend is doing. If all interfaces used prepares invisibly like jdbc,
we would be right to suppress the log information.

> > If you were to have written it in libpq, it would make sense, I think,
> > and internally, this is what is happening. We can't assume only
> > interface libraries like jdbc are using this feature.

>
> Wait, so is the extended query protocol the poor cousin of "what libpq
> does", or what? You can do Parse/Bind using libpq, can't you?


Sure.

> The *meaning* of the Parse/Bind/Execute sequence is quite clear
> regardless of what interface library is used. I still think that logging
> just the queries that were actually executed, once per execution, is the
> sensible thing to do here. I can't see a sequence of protocol messages
> that would produce a strange result if we used the rules I suggested --
> do you have an example where it breaks?


I have no idea.

> > As far as I understand things, the protocol-level prepare/execute is
> > identical to the SQL-level prepare/execute, except that there is no need
> > to parse the execute, so it should log like the SQL-level statements, if
> > possible.

>
> You can Parse any SQL statement, but you can't PREPARE any SQL
> statement. So, no, they're not equivalent. That's one aspect of what I
> meant about generating synthetic statements that weren't syntactially
> correct (the strange FETCH syntax with ROWS/MAXROWS that Simon was
> suggesting is another case).


I am hesitant to add another log syntax to be used just for
protocol-level prepare. I think it adds complexity with little benefit,
particularly for people reading those logs with automated tools.

Simon's page is in the patches queue. What would you like changed,
exactly?

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:34 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com