Skip site navigation (1) Skip section navigation (2)

WIP: pl/pgsql cleanup

From: Neil Conway <neilc(at)samurai(dot)com>
To: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: WIP: pl/pgsql cleanup
Date: 2005-01-18 04:57:37
Message-ID: 1106024257.22946.121.camel@localhost.localdomain (view raw, whole thread or download thread mbox)
Lists: 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

- 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


Attachment: plpgsql_cleanup-11.patch
Description: text/x-patch (72.6 KB)


pgsql-patches by date

Next:From: Neil ConwayDate: 2005-01-18 05:15:57
Subject: Re: transformExpr() refactor
Previous:From: Alin VaidaDate: 2005-01-18 00:51:15
Subject: Updated translation for Romanian (8.0)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group