proposal: parentid and naturalid for plpgsql nodes - Mailing list pgsql-hackers

From Pavel Stehule
Subject proposal: parentid and naturalid for plpgsql nodes
Date
Msg-id CAFj8pRDwT=5UV9cKzCGxpo9ksYghcTm_h+8t_cWebaJDrN0vww@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hi

I propose two enhancing of PLpgSQL_stmt structure

1. parentid

This is the id (stmtid) of the near outer statement. Why do I need it? Inside the plpgsql_check profiler I need to handle exceptions. Exceptions are not supported by the plpgsql debug API, so I need to hold a stack of executed statements. When any statements start, I need to check this stack and sometimes (after a handled exception) I need to reduce this stack until I find a statement that has the same parenid as the parentid of the current statement. 

Currently I hold an array with parentid outside, but it is not practical and increases the complexity of plpgsql_check.

2. naturalid

stmtid is assigned by the plpgsql parser. It is unique, but has a little bit of a messy order, and when something like a statement id is displayed in some reports, then it is confusing for users. I propose extra id (that is unique too), but with order based on searching statements tree 

example

BEGIN --> stmtid = 3
  PERFORM --> stmtid = 1
  PERFORM --> stmtid = 2

BEGIN --> naturalid = 1
  PERFORM --> naturalid = 2
  PERFORM --> naturalid = 3

Maybe the ordering of stmtid can be changed, and then naturalid can be useless. 

Proposed change can reduce complexity of plpgsql_check, but I believe it can help with other exceptions that use pl debug api.

Comments, notes?

Regards

Pavel


pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: Re: Fix accidentally cast away qualifiers
Next
From: Antonin Houska
Date:
Subject: Re: Adding REPACK [concurrently]