From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Tim Uckun <timuckun(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Is PL-PGSQL interpreted or complied? |
Date: | 2017-07-06 04:55:57 |
Message-ID: | CAFj8pRAtJ=7zcc+Rx0ijGf=nV-F0S-adVoddT565T-KDysSxWQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2017-07-06 2:10 GMT+02:00 Tim Uckun <timuckun(at)gmail(dot)com>:
> I am curious about the stored proc languages inside of postgres. When I
> write a stored proc is it compiled to some internal representation or just
> interpreted? How does this work with other languages?
>
The PLpgSQL proc are saved in original form - you can see the content of
system table pg_proc. Before saving a syntax checking is processed. When
PLpgSQL function is executed first time in session, then source code is
loaded from pg_proc, and parsed to AST (Abstract syntax tree). AST is
stored in session cache. Next, the AST is directly interpreted, repeatedly.
>
> Also would it be possible to extract PL-PGSQL into a standalone (albeit
> crippled) language? Is the interpreter/compiler modular like that?
>
Probably it is possible, but it requires some work - PLpgSQL is just glue
for SQL or for SQL expressions. There are not mathematical unit, there are
not some like basic library. All is shared with Postgres SQL engine. This
feature is very specific for PLpgSQL. Every expression in PLpgSQL is
translated to SELECT - some simple SELECTs are executed in special mode,
faster, than usual queries.
PLpgSQL source code
https://github.com/postgres/postgres/tree/master/src/pl/plpgsql/src
Regards
Pavel
> Thanks.
>
From | Date | Subject | |
---|---|---|---|
Next Message | Yong Zhang | 2017-07-06 08:10:53 | pg_rewind could not find previous WAL record at 0/4B000060: invalid record length at 0/4B000060: wanted 24, got 0 |
Previous Message | dandl | 2017-07-06 01:23:28 | Re: Imperative Query Languages |