proposal - plpgsql unique statement id

Started by Pavel Stehulealmost 8 years ago11 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

This thread has been committed, so CI has stopped here. Anything below is the last result it produced.

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t39666
psql -h localhost -U postgres

Built from patchset v7 (message #7), July 28, 2026 at 04:44 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t39666_7 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t39666_7 && git checkout t39666_7

Patchset v7 (message #7) is on t39666_7

Jump to latest
#1Pavel Stehule
pavel.stehule@gmail.com

Hi

I am try to enhance plpgsql_check about profiler functionality and I have
to solve how to identify every plpgsql statement across different sessions.
There is lineno, but surely it should not be unique. I propose introduce
stmtid to every statement structure. This number will be unique inside
function.

Comments, notes?

Regards

Pavel

Attachments:

plpgsql-statement-id.patchtext/x-patch; charset=US-ASCII; name=plpgsql-statement-id.patchDownload+71-0
#2Peter Eisentraut
peter_e@gmx.net
In reply to: Pavel Stehule (#1)
Re: proposal - plpgsql unique statement id

On 13/11/2018 14:35, Pavel Stehule wrote:

I am try to enhance plpgsql_check about profiler functionality and I
have to solve how to identify every plpgsql statement across different
sessions. There is lineno, but surely it should not be unique. I propose
introduce stmtid to every statement structure. This number will be
unique inside function.

That seems reasonable enough, although I wouldn't use 0 as a valid stmtid.

A documenting comment near PLpgSQL_stmt might be nice.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Peter Eisentraut (#2)
Re: proposal - plpgsql unique statement id

pá 4. 1. 2019 v 13:58 odesílatel Peter Eisentraut <
peter.eisentraut@2ndquadrant.com> napsal:

On 13/11/2018 14:35, Pavel Stehule wrote:

I am try to enhance plpgsql_check about profiler functionality and I
have to solve how to identify every plpgsql statement across different
sessions. There is lineno, but surely it should not be unique. I propose
introduce stmtid to every statement structure. This number will be
unique inside function.

That seems reasonable enough, although I wouldn't use 0 as a valid stmtid.

done

A documenting comment near PLpgSQL_stmt might be nice.

done

Regards

Pavel

Show quoted text

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

plpgsql-statement-id-02.patchtext/x-patch; charset=US-ASCII; name=plpgsql-statement-id-02.patchDownload+76-0
#4Peter Eisentraut
peter_e@gmx.net
In reply to: Pavel Stehule (#3)
Re: proposal - plpgsql unique statement id

On 04/01/2019 15:07, Pavel Stehule wrote:

pá 4. 1. 2019 v 13:58 odesílatel Peter Eisentraut
<peter.eisentraut@2ndquadrant.com
<mailto:peter.eisentraut@2ndquadrant.com>> napsal:

On 13/11/2018 14:35, Pavel Stehule wrote:

I am try to enhance plpgsql_check about profiler functionality and I
have to solve how to identify every plpgsql statement across different
sessions. There is lineno, but surely it should not be unique. I

propose

introduce stmtid to every statement structure. This number will be
unique inside function.

That seems reasonable enough, although I wouldn't use 0 as a valid
stmtid.

done

Related, should stmtid be unsigned int rather than signed int?

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Peter Eisentraut (#4)
Re: proposal - plpgsql unique statement id

pá 18. 1. 2019 v 8:56 odesílatel Peter Eisentraut <
peter.eisentraut@2ndquadrant.com> napsal:

On 04/01/2019 15:07, Pavel Stehule wrote:

pá 4. 1. 2019 v 13:58 odesílatel Peter Eisentraut
<peter.eisentraut@2ndquadrant.com
<mailto:peter.eisentraut@2ndquadrant.com>> napsal:

On 13/11/2018 14:35, Pavel Stehule wrote:

I am try to enhance plpgsql_check about profiler functionality and

I

have to solve how to identify every plpgsql statement across

different

sessions. There is lineno, but surely it should not be unique. I

propose

introduce stmtid to every statement structure. This number will be
unique inside function.

That seems reasonable enough, although I wouldn't use 0 as a valid
stmtid.

done

Related, should stmtid be unsigned int rather than signed int?

done

Regards

Pavel

Show quoted text

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

plpgsql-statement-id-03.patchtext/x-patch; charset=US-ASCII; name=plpgsql-statement-id-03.patchDownload+76-0
#6Peter Eisentraut
peter_e@gmx.net
In reply to: Pavel Stehule (#5)
Re: proposal - plpgsql unique statement id

There are still a handful of places where a statement is created but no
stmtid is assigned. Can you check those?

src/pl/plpgsql/src/pl_exec.c:2815
src/pl/plpgsql/src/pl_exec.c:4580
src/pl/plpgsql/src/pl_gram.y:907

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#7Pavel Stehule
pavel.stehule@gmail.com
In reply to: Peter Eisentraut (#6)
Re: proposal - plpgsql unique statement id

út 22. 1. 2019 v 14:55 odesílatel Peter Eisentraut <
peter.eisentraut@2ndquadrant.com> napsal:

There are still a handful of places where a statement is created but no
stmtid is assigned. Can you check those?

src/pl/plpgsql/src/pl_exec.c:2815
src/pl/plpgsql/src/pl_exec.c:4580

These statements are "fake" very short life statements without processing
via statement switch. Should not be counted, because are dynamically
created, dropped, and stmtid should be 0 or -1 (that means it should be int
again).
Now, for both cases, the stmtid is 0, due memset to 0.

src/pl/plpgsql/src/pl_gram.y:907

It was missing, fixed, thank you for check

Regards

Pavel

Show quoted text

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

t39666_7
plpgsql-statement-id-04.patchtext/x-patch; charset=US-ASCII; name=plpgsql-statement-id-04.patchDownload+77-0
#8Peter Eisentraut
peter_e@gmx.net
In reply to: Pavel Stehule (#7)
Re: proposal - plpgsql unique statement id

On 22/01/2019 19:04, Pavel Stehule wrote:

It was missing, fixed, thank you for check

committed

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#8)
Re: proposal - plpgsql unique statement id

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

committed

Why didn't this patch modify the dumping logic in pl_funcs.c to print
the IDs? I'm not aware of other cases where we intentionally omit
fields from debug-support printouts.

regards, tom lane

#10Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#9)
Re: proposal - plpgsql unique statement id

čt 24. 1. 2019 v 23:08 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

committed

Why didn't this patch modify the dumping logic in pl_funcs.c to print
the IDs? I'm not aware of other cases where we intentionally omit
fields from debug-support printouts.

I had not a idea, so this field can be useful there. I'll send a patch with
it.

Regards

Pavel

Show quoted text

regards, tom lane

#11Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#9)
Re: proposal - plpgsql unique statement id

čt 24. 1. 2019 v 23:08 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

committed

Why didn't this patch modify the dumping logic in pl_funcs.c to print
the IDs? I'm not aware of other cases where we intentionally omit
fields from debug-support printouts.

Currently we don't print lineno, what is maybe for user more important
information.

I looked to the code, and now I am thinking so it is little bit harder,
than I expected. Any new information can break output formatting

static void
dump_loop(PLpgSQL_stmt_loop *stmt)
{
dump_ind();
printf("LOOP\n");

dump_stmts(stmt->body);

dump_ind();
printf(" ENDLOOP\n");
}

can looks like

static void
dump_loop(PLpgSQL_stmt_loop *stmt, int stmtid_width)
{
dump_ind();
printf("%*d LOOP\n", stmtid_width, stmt->stmtid);

dump_stmts(stmt->body);

dump_ind();
printf(" ENDLOOP\n");
}

It is some what do you expect ?

Regards

Maybe more simple

static void
dump_loop(PLpgSQL_stmt_loop *stmt, int stmtid_width)
{
dump_ind();
printf("LOOP {%d}\n",stmt->stmtid);

dump_stmts(stmt->body);

dump_ind();
printf(" ENDLOOP\n");
}

Pavel

Show quoted text

regards, tom lane