Обсуждение: [GENERAL] Is PL-PGSQL interpreted or complied?

Поиск
Список
Период
Сортировка

[GENERAL] Is PL-PGSQL interpreted or complied?

От
Tim Uckun
Дата:
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?

Also would it be possible to extract PL-PGSQL into a standalone (albeit crippled) language? Is the interpreter/compiler modular like that?

Thanks.

Re: [GENERAL] Is PL-PGSQL interpreted or complied?

От
John R Pierce
Дата:
On 7/5/2017 5:10 PM, Tim Uckun wrote:
> 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?
>

plpgsql is interpreted directly, I don't believe its even pre-tokenized.

> How does this work with other languages?

that varies with the language..  PLJava is compiled to java byte codes
by the javac compiler even before its loaded (as you load the
precompiled .jar file with the pljava loader),   plpython uses .pyc
files, same as if python is run from the command line,  plperl is direct
interpreted, same as perl normally.   embedded C is precompiled to
machine language as you just load the DLL/SO files into postgres.... etc
etc.

> Also would it be possible to extract PL-PGSQL into a standalone
> (albeit crippled) language? Is the interpreter/compiler modular like that?


the interpreter *IS* SQL, which is the whole database server.   I don't
think a standalone plpgsql without SQL would be of much use.


--
john r pierce, recycling bits in santa cruz



Re: [GENERAL] Is PL-PGSQL interpreted or complied?

От
Pavel Stehule
Дата:


2017-07-06 2:10 GMT+02:00 Tim Uckun <timuckun@gmail.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.


Regards

Pavel



Thanks.

Re: [GENERAL] Is PL-PGSQL interpreted or complied?

От
Tim Uckun
Дата:
Interesting, thank you.  I was curious to know how it worked.

Cheers.