create or replace function f_pl01(cnt int) returns int language plpgsql as $$
declare
i int;
begin
i:=0;
LOOP
i = i + 1;
EXIT WHEN i >= cnt;
END LOOP;
return i;
end;
$$;
create function f_lua01(cnt int) returns int language pllua as $$
local i=0
while( i < cnt ) do
i = i+1
end
return i
$$;
postgres=# \timing
Timing is on.
postgres=# select f_pl01(10000000);
f_pl01
----------
10000000
(1 row)
Time: 6482.846 ms (00:06.483)
postgres=# select f_lua01(10000000);
f_lua01
----------
10000000
(1 row)
Time: 556.831 ms
create or replace function f_py01(cnt int) returns int language plpython3u as $$
i = 0
while i < cnt:
i = i + 1
return i
$$;
postgres=# select f_py01(10000000);
f_py01
----------
10000000
(1 row)
Time: 1008.750 ms (00:01.009)
create or replace function f_pl02(cnt int) returns int language plpgsql as $$
declare
i int;
myarr text[];
s1 text;
begin
i:=0;
s1 := lpad('', 2048, 'helloosdba');
LOOP
myarr := array_append(myarr, s1);
i = i + 1;
EXIT WHEN i >= cnt;
END LOOP;
return array_length(myarr, 1);
end;
$$;
create or replace function f_lua02(cnt int) returns int language pllua as $$
local i=0
local myarr = {}
local s1 = string.rep('helloosdba', 2048)
while( i < cnt ) do
i = i+1
myarr[i] = s1
end
return #myarr
$$;
postgres=# select f_pl02(100000);
f_pl02
--------
100000
(1 row)
Time: 756.772 ms
postgres=# select f_lua02(100000);
f_lua02
---------
100000
(1 row)
Time: 10.731 ms
create or replace function f_py02(cnt int) returns int language plpython3u as $$
i = 0
myarr = []
s1 = 'helloosdba'*2048
while i < cnt:
i = i+1
myarr.append(s1)
return len(myarr)
$$;
postgres=# select f_py02(100000);
f_py02
--------
100000
(1 row)
Time: 23.459 ms
cd /usr/src
curl -R -O http://www.lua.org/ftp/lua-5.3.5.tar.gz
tar xvf lua-5.3.5.tar.gz
/usr/bin/ld: /usr/local/lib/liblua.a(loadlib.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
-fPIC
:CFLAGS= -fPIC -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS)
make install
cd /usr/src
git clone https://github.com/pllua/pllua-ng.git
cd pllua-ng
make PG_CONFIG=/usr/pgsql-11/bin/pg_config
make PG_CONFIG=/usr/pgsql-11/bin/pg_config install
create extension pllua;
扫描钉钉直播群二维码 关注我们免费看直播
联系客服