WIP: pl/pgsql cleanup - Mailing list pgsql-patches

From Neil Conway
Subject WIP: pl/pgsql cleanup
Date
Msg-id 1106024257.22946.121.camel@localhost.localdomain
Whole thread Raw
Responses Re: WIP: pl/pgsql cleanup
List pgsql-patches
This patch makes a number of cleanups to PL/PgSQL:

- replaced all uses of malloc/strdup with palloc/pstrdup. Each PL/PgSQL
function now has its own memory context (stored in PLpgSQL_function).
All the compile-time storage for the function is allocated in this
memory context (including the FmgrInfo), so to reclaim that memory we
need only delete/reset the context. This means we can do away with
perm_fmgr_info(), and some other hackery.

(This was surprisingly easy, btw, so I am suspect that I've missed
something fundamental -- hence the patch is marked WIP. Guidance would
be welcome.)

- Replaced the PLpgSQL_stmts and PLpgSQL_exceptions types with List.
This makes for more manageable code, and we get palloc'd storage for
free. On the other hand we lose compile-time type checking, but I think
it's a net win. This can be done in a few more places (e.g. PLpgSQL_ns),
but I think this is good enough for now.

- Remove some redundant code in plpgsql_compile(): there ought to be no
need to check that the plpgsql_HashTable is initialized, since that is
done in plpgsql_init_all() (which is always called before we reach
plpgsql_compile())

- Refactor some duplicated code in pl_exec.c for copying datum values;
instead create a function, copy_plpgsql_datum(), and call it when needed

- Made plpgsql_DumpExecTree a boolean, not an integer (since it was only
assigned 0 or 1)

- Made plpgsql_build_variable() copy its first argument. In practice,
practically every call site of plpgsql_build_variable() was doing a
strdup() to copy the first argument -- this way we can just do a single
pstrdup() in plpgsql_build_variable() itself.

- Fixed a few typos in comments, various other minor cleanups

-Neil


Attachment

pgsql-patches by date:

Previous
From: Alin Vaida
Date:
Subject: Updated translation for Romanian (8.0)
Next
From: Neil Conway
Date:
Subject: Re: transformExpr() refactor