!6569 GMS_COMPRESS高级包特性兼容

Merge pull request !6569 from 王平云/master
This commit is contained in:
opengauss_bot
2024-11-08 01:59:48 +00:00
committed by Gitee
19 changed files with 2301 additions and 0 deletions

View File

@ -104,6 +104,7 @@ install:
@if test -d contrib/age; then $(MAKE) -C contrib/age $@; fi
@if test -d contrib/datavec; then $(MAKE) -C contrib/datavec clean; fi
@if test -d contrib/datavec; then $(MAKE) -C contrib/datavec $@; fi
@if test -d contrib/gms_compress; then $(MAKE) -C contrib/gms_compress $@; fi
@if test -d contrib/gms_stats; then $(MAKE) -C contrib/gms_stats $@; fi
@if test -d contrib/gms_tcp; then $(MAKE) -C contrib/gms_tcp $@; fi
@if test -d contrib/gms_profiler; then $(MAKE) -C contrib/gms_profiler $@; fi

View File

@ -49,6 +49,8 @@
./share/postgresql/extension/dolphin--2.0.1--2.0.sql
./share/postgresql/extension/dolphin--4.0--4.0.1.sql
./share/postgresql/extension/dolphin--4.0.1--4.0.sql
./share/postgresql/extension/gms_compress--1.0.sql
./share/postgresql/extension/gms_compress.control
./share/postgresql/extension/openGauss_expr_dolphin.ir
./share/postgresql/extension/file_fdw--1.0.sql
./share/postgresql/extension/plpgsql.control
@ -757,6 +759,7 @@
./lib/postgresql/proc_srclib
./lib/postgresql/security_plugin.so
./lib/postgresql/dolphin.so
./lib/postgresql/gms_compress.so
./lib/postgresql/pg_upgrade_support.so
./lib/postgresql/latin2_and_win1250.so
./lib/postgresql/euc2004_sjis2004.so

View File

@ -121,6 +121,8 @@
./share/postgresql/extension/dblink--1.0.sql
./share/postgresql/extension/dblink--unpackaged--1.0.sql
./share/postgresql/extension/dblink.control
./share/postgresql/extension/gms_compress--1.0.sql
./share/postgresql/extension/gms_compress.control
./share/postgresql/extension/gms_output--1.0.sql
./share/postgresql/extension/gms_output.control
./share/postgresql/extension/gms_lob--1.0.sql
@ -836,6 +838,7 @@
./lib/postgresql/dblink.so
./lib/postgresql/pgoutput.so
./lib/postgresql/assessment.so
./lib/postgresql/gms_compress.so
./lib/postgresql/gms_output.so
./lib/postgresql/gms_lob.so
./lib/postgresql/gms_stats.so

View File

@ -45,6 +45,8 @@
./share/postgresql/extension/plpgsql.control
./share/postgresql/extension/dist_fdw.control
./share/postgresql/extension/dist_fdw--1.0.sql
./share/postgresql/extension/gms_compress--1.0.sql
./share/postgresql/extension/gms_compress.control
./share/postgresql/extension/hstore--1.1.sql
./share/postgresql/extension/plpgsql--unpackaged--1.0.sql
./share/postgresql/extension/file_fdw.control
@ -726,6 +728,7 @@
./lib/postgresql/utf8_and_sjis.so
./lib/postgresql/utf8_and_cyrillic.so
./lib/postgresql/hstore.so
./lib/postgresql/gms_compress.so
./lib/postgresql/packages.so
./lib/postgresql/utf8_and_euc_kr.so
./lib/postgresql/ascii_and_mic.so

View File

@ -97,6 +97,8 @@
./share/postgresql/extension/mot_fdw.control
./share/postgresql/extension/postgres_fdw--1.0.sql
./share/postgresql/extension/postgres_fdw.control
./share/postgresql/extension/gms_compress--1.0.sql
./share/postgresql/extension/gms_compress.control
./share/postgresql/extension/dblink--1.0.sql
./share/postgresql/extension/dblink--unpackaged--1.0.sql
./share/postgresql/extension/dblink.control
@ -775,6 +777,7 @@
./lib/postgresql/pg_upgrade_support.so
./lib/postgresql/java/pljava.jar
./lib/postgresql/postgres_fdw.so
./lib/postgresql/gms_compress.so
./lib/postgresql/dblink.so
./lib/postgresql/pgoutput.so
./lib/postgresql/assessment.so

View File

@ -79,6 +79,8 @@
./share/postgresql/extension/gsredistribute--unpackaged--1.0.sql
./share/postgresql/extension/postgres_fdw--1.0.sql
./share/postgresql/extension/postgres_fdw.control
./share/postgresql/extension/gms_compress--1.0.sql
./share/postgresql/extension/gms_compress.control
./share/postgresql/extension/dblink--1.0.sql
./share/postgresql/extension/dblink--unpackaged--1.0.sql
./share/postgresql/extension/dblink.control
@ -767,6 +769,7 @@
./lib/postgresql/pg_upgrade_support.so
./lib/postgresql/java/pljava.jar
./lib/postgresql/postgres_fdw.so
./lib/postgresql/gms_compress.so
./lib/postgresql/dblink.so
./lib/postgresql/gms_output.so
./lib/postgresql/gms_stats.so

View File

@ -109,6 +109,8 @@
./share/postgresql/extension/dblink--1.0.sql
./share/postgresql/extension/dblink--unpackaged--1.0.sql
./share/postgresql/extension/dblink.control
./share/postgresql/extension/gms_compress--1.0.sql
./share/postgresql/extension/gms_compress.control
./share/postgresql/extension/gms_output--1.0.sql
./share/postgresql/extension/gms_output.control
./share/postgresql/extension/gms_lob--1.0.sql
@ -806,6 +808,7 @@
./lib/postgresql/java/pljava.jar
./lib/postgresql/postgres_fdw.so
./lib/postgresql/dblink.so
./lib/postgresql/gms_compress.so
./lib/postgresql/gms_output.so
./lib/postgresql/gms_lob.so
./lib/postgresql/gms_stats.so

View File

@ -49,6 +49,8 @@
./share/postgresql/extension/dolphin--2.0.1--2.0.sql
./share/postgresql/extension/dolphin--4.0--4.0.1.sql
./share/postgresql/extension/dolphin--4.0.1--4.0.sql
./share/postgresql/extension/gms_compress--1.0.sql
./share/postgresql/extension/gms_compress.control
./share/postgresql/extension/openGauss_expr_dolphin.ir
./share/postgresql/extension/file_fdw--1.0.sql
./share/postgresql/extension/plpgsql.control
@ -756,6 +758,7 @@
./lib/postgresql/proc_srclib
./lib/postgresql/security_plugin.so
./lib/postgresql/dolphin.so
./lib/postgresql/gms_compress.so
./lib/postgresql/pg_upgrade_support.so
./lib/postgresql/latin2_and_win1250.so
./lib/postgresql/euc2004_sjis2004.so

View File

@ -121,6 +121,8 @@
./share/postgresql/extension/dblink--1.0.sql
./share/postgresql/extension/dblink--unpackaged--1.0.sql
./share/postgresql/extension/dblink.control
./share/postgresql/extension/gms_compress--1.0.sql
./share/postgresql/extension/gms_compress.control
./share/postgresql/extension/gms_output--1.0.sql
./share/postgresql/extension/gms_output.control
./share/postgresql/extension/gms_lob--1.0.sql
@ -839,6 +841,7 @@
./lib/postgresql/gms_tcp.so
./lib/postgresql/pgoutput.so
./lib/postgresql/assessment.so
./lib/postgresql/gms_compress.so
./lib/postgresql/gms_output.so
./lib/postgresql/gms_profiler.so
./lib/postgresql/gms_sql.so

View File

@ -0,0 +1,21 @@
#This is the main CMAKE for build all gms_compress.
# gms_compress
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TGT_gms_compress_SRC)
set(TGT_gms_compress_INC
${PROJECT_OPENGS_DIR}/contrib/gms_compress
${PROJECT_OPENGS_DIR}/contrib
)
set(gms_compress_DEF_OPTIONS ${MACRO_OPTIONS})
set(gms_compress_COMPILE_OPTIONS ${OPTIMIZE_OPTIONS} ${OS_OPTIONS} ${PROTECT_OPTIONS} ${WARNING_OPTIONS} ${LIB_SECURE_OPTIONS} ${CHECK_OPTIONS})
set(gms_compress_LINK_OPTIONS ${LIB_LINK_OPTIONS})
add_shared_libtarget(gms_compress TGT_gms_compress_SRC TGT_gms_compress_INC "${gms_compress_DEF_OPTIONS}" "${gms_compress_COMPILE_OPTIONS}" "${gms_compress_LINK_OPTIONS}")
set_target_properties(gms_compress PROPERTIES PREFIX "")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_compress.control
DESTINATION share/postgresql/extension/
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_compress--1.0.sql
DESTINATION share/postgresql/extension/
)
install(TARGETS gms_compress DESTINATION lib/postgresql)

View File

@ -0,0 +1,26 @@
# contrib/gms_compress/Makefile
MODULE_big = gms_compress
OBJS = gms_compress.o
EXTENSION = gms_compress
DATA = gms_compress--1.0.sql
exclude_option = -fPIE
override CPPFLAGS := -fstack-protector-strong $(filter-out $(exclude_option),$(CPPFLAGS))
REGRESS = gms_compress
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/gms_compress
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
regress_home = $(top_builddir)/src/test/regress
REGRESS_OPTS = -c 0 -d 1 -r 1 -p 25632 --single_node -w --keep_last_data=false \
--regconf=$(regress_home)/regress.conf \
--temp-config=$(regress_home)/make_fastcheck_postgresql.conf
include $(top_srcdir)/contrib/contrib-global.mk
endif

View File

@ -0,0 +1 @@
The openGauss regression needs this file to run.

View File

@ -0,0 +1,970 @@
create extension gms_compress;
create schema gms_compress_test;
set search_path=gms_compress_test;
-- test gms_compress.compress
select gms_compress.lz_compress('123'::raw);
lz_compress
----------------------------------------------
1F8B080000000000000363540600CC52A5FA02000000
(1 row)
select gms_compress.lz_compress('df'::raw);
lz_compress
--------------------------------------------
1F8B0800000000000003BB0F00C8206EC401000000
(1 row)
select gms_compress.lz_compress('12ab56'::raw);
lz_compress
------------------------------------------------
1F8B0800000000000003135A1D0600EF3F182F03000000
(1 row)
select gms_compress.lz_compress('123'::raw, 1);
lz_compress
----------------------------------------------
1F8B080000000000040363540600CC52A5FA02000000
(1 row)
select gms_compress.lz_compress('df'::raw, 6);
lz_compress
--------------------------------------------
1F8B0800000000000003BB0F00C8206EC401000000
(1 row)
select gms_compress.lz_compress('12ab56'::raw, 9);
lz_compress
------------------------------------------------
1F8B0800000000000203135A1D0600EF3F182F03000000
(1 row)
select gms_compress.lz_compress('123'::blob);
lz_compress
----------------------------------------------
1F8B080000000000000363540600CC52A5FA02000000
(1 row)
select gms_compress.lz_compress('df'::blob);
lz_compress
--------------------------------------------
1F8B0800000000000003BB0F00C8206EC401000000
(1 row)
select gms_compress.lz_compress('12ab56'::blob);
lz_compress
------------------------------------------------
1F8B0800000000000003135A1D0600EF3F182F03000000
(1 row)
select gms_compress.lz_compress('123'::blob, 1);
lz_compress
----------------------------------------------
1F8B080000000000040363540600CC52A5FA02000000
(1 row)
select gms_compress.lz_compress('df'::blob, 6);
lz_compress
--------------------------------------------
1F8B0800000000000003BB0F00C8206EC401000000
(1 row)
select gms_compress.lz_compress('12ab56'::blob, 9);
lz_compress
------------------------------------------------
1F8B0800000000000203135A1D0600EF3F182F03000000
(1 row)
DECLARE
content BLOB;
r_content BLOB;
v_handle int;
v_raw raw;
r_raw raw;
v_bool boolean;
BEGIN
content := '123';
v_raw := '12345';
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw);
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
r_content := '111';
GMS_COMPRESS.LZ_COMPRESS(content, r_content);
RAISE NOTICE 'r_content=%', r_content;
END;
/
NOTICE: r_content=1F8B080000000000000363540600CC52A5FA02000000,r_raw=1F8B080000000000000363547605005B719C4603000000
NOTICE: r_content=1F8B080000000000000363540600CC52A5FA02000000
DECLARE
content BLOB;
r_content BLOB;
v_handle int;
v_raw raw;
r_raw raw;
v_bool boolean;
BEGIN
content := 'abc';
v_raw := 'df';
r_content := GMS_COMPRESS.LZ_COMPRESS(content, 1);
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw, 9);
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
r_content := '111';
GMS_COMPRESS.LZ_COMPRESS(content, r_content, 5);
RAISE NOTICE 'r_content=%', r_content;
END;
/
NOTICE: r_content=1F8B0800000000000403E3DA0300D205E17902000000,r_raw=1F8B0800000000000203BB0F00C8206EC401000000
NOTICE: r_content=1F8B0800000000000003E3DA0300D205E17902000000
-- abnormal scenario
select gms_compress.lz_compress(null::raw);
ERROR: compressed data cannot be NULL
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress(''::raw);
ERROR: compressed data cannot be NULL
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress('dfg'::raw);
ERROR: invalid hexadecimal digit: "g"
LINE 1: select gms_compress.lz_compress('dfg'::raw);
^
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress('dfg'::raw, 5);
ERROR: invalid hexadecimal digit: "g"
LINE 1: select gms_compress.lz_compress('dfg'::raw, 5);
^
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress('123'::raw, 0);
ERROR: compression quality must be within the range of 1 to 9
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress('123'::raw, 10);
ERROR: compression quality must be within the range of 1 to 9
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress(null::blob);
ERROR: compressed data cannot be NULL
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress(''::blob);
ERROR: compressed data cannot be NULL
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress('dfg'::blob);
ERROR: invalid hexadecimal digit: "g"
LINE 1: select gms_compress.lz_compress('dfg'::blob);
^
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress('dfg'::blob, 5);
ERROR: invalid hexadecimal digit: "g"
LINE 1: select gms_compress.lz_compress('dfg'::blob, 5);
^
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress('123'::blob, 0);
ERROR: compression quality must be within the range of 1 to 9
CONTEXT: referenced column: lz_compress
select gms_compress.lz_compress('123'::blob, 10);
ERROR: compression quality must be within the range of 1 to 9
CONTEXT: referenced column: lz_compress
DECLARE
content BLOB;
r_content BLOB;
v_raw raw;
r_raw raw;
BEGIN
content := '';
v_raw := 'dfg';
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw);
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
r_content := '111';
GMS_COMPRESS.LZ_COMPRESS(content, r_content);
RAISE NOTICE 'r_content=%', r_content;
END;
/
ERROR: invalid hexadecimal digit: "g"
CONTEXT: PL/pgSQL function inline_code_block line 7 at assignment
DECLARE
content BLOB;
r_content BLOB;
v_raw raw;
r_raw raw;
BEGIN
content := 'abc';
v_raw := 'df';
r_content := GMS_COMPRESS.LZ_COMPRESS(content, 0);
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw, 10);
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
r_content := '111';
GMS_COMPRESS.LZ_COMPRESS(content, r_content, -1);
RAISE NOTICE 'r_content=%', r_content;
END;
/
ERROR: compression quality must be within the range of 1 to 9
CONTEXT: PL/pgSQL function inline_code_block line 8 at assignment
-- test gms_compress.lz_uncompress
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::raw));
lz_uncompress
---------------
0123
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::raw));
lz_uncompress
---------------
DF
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::raw));
lz_uncompress
---------------
12AB56
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::raw, 1));
lz_uncompress
---------------
0123
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::raw, 6));
lz_uncompress
---------------
DF
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::raw, 9));
lz_uncompress
---------------
12AB56
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::blob));
lz_uncompress
---------------
0123
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::blob));
lz_uncompress
---------------
DF
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::blob));
lz_uncompress
---------------
12AB56
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::blob, 1));
lz_uncompress
---------------
0123
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::blob, 6));
lz_uncompress
---------------
DF
(1 row)
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::blob, 9));
lz_uncompress
---------------
12AB56
(1 row)
DECLARE
content BLOB;
r_content BLOB;
v_content BLOB;
v_bool boolean;
BEGIN
content := '123';
v_content := '123';
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
END;
/
NOTICE: content=0123,r_content=1F8B080000000000000363540600CC52A5FA02000000,v_content=0123
-- abnormal scenario
select gms_compress.lz_uncompress(null::raw);
ERROR: uncompressed data cannot be NULL
CONTEXT: referenced column: lz_uncompress
select gms_compress.lz_uncompress(''::raw);
ERROR: uncompressed data cannot be NULL
CONTEXT: referenced column: lz_uncompress
select gms_compress.lz_uncompress('dfg'::raw);
ERROR: invalid hexadecimal digit: "g"
LINE 1: select gms_compress.lz_uncompress('dfg'::raw);
^
CONTEXT: referenced column: lz_uncompress
select gms_compress.lz_uncompress('123'::raw);
ERROR: too small, minimum length of gzip format is 14 bytes
CONTEXT: referenced column: lz_uncompress
select gms_compress.lz_uncompress(null::blob);
ERROR: uncompressed data cannot be NULL
CONTEXT: referenced column: lz_uncompress
select gms_compress.lz_uncompress(''::blob);
ERROR: uncompressed data cannot be NULL
CONTEXT: referenced column: lz_uncompress
select gms_compress.lz_uncompress('dfg'::blob);
ERROR: invalid hexadecimal digit: "g"
LINE 1: select gms_compress.lz_uncompress('dfg'::blob);
^
CONTEXT: referenced column: lz_uncompress
select gms_compress.lz_uncompress('123'::blob);
ERROR: too small, minimum length of gzip format is 14 bytes
CONTEXT: referenced column: lz_uncompress
DECLARE
content BLOB;
r_content BLOB;
v_content BLOB;
v_bool boolean;
BEGIN
r_content := NULL;
v_content := '123';
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
END;
/
ERROR: parameter cannot be NULL
CONTEXT: SQL statement "CALL gms_compress.lz_uncompress(r_content,v_content)"
PL/pgSQL function inline_code_block line 8 at SQL statement
DECLARE
content BLOB;
r_content BLOB;
v_content BLOB;
v_bool boolean;
BEGIN
r_content := '123';
v_content := '123';
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
END;
/
ERROR: too small, minimum length of gzip format is 14 bytes
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress(blob,blob) line 5 at assignment
SQL statement "CALL gms_compress.lz_uncompress(r_content,v_content)"
PL/pgSQL function inline_code_block line 8 at SQL statement
DECLARE
content BLOB;
r_content BLOB;
v_content BLOB;
v_bool boolean;
BEGIN
content := '123';
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
v_content := NULL;
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
END;
/
ERROR: parameter cannot be NULL
CONTEXT: SQL statement "CALL gms_compress.lz_uncompress(r_content,v_content)"
PL/pgSQL function inline_code_block line 9 at SQL statement
-- test gms_compress.lz_compress_open and ms_compress.lz_compress_close
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: content=<NULL>
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content,5);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: content=<NULL>
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(2,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(3,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(4,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(5,content);
END;
/
-- abnormal scenario
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
ERROR: NULL input for detoast datum packed
CONTEXT: PL/pgSQL function inline_code_block line 5 at assignment
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content, 0);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
ERROR: compression quality must be within the range of 1 to 9
CONTEXT: PL/pgSQL function inline_code_block line 5 at assignment
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(0,content);
RAISE NOTICE 'content=%', content;
END;
/
ERROR: invalid handle, it be within the range of 1 to 5
CONTEXT: PL/pgSQL function gms_compress.lz_compress_close(integer,blob) line 2 at assignment
SQL statement "CALL gms_compress.lz_compress_close(0,content)"
PL/pgSQL function inline_code_block line 6 at SQL statement
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: content=<NULL>
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle+1,content);
RAISE NOTICE 'content=%', content;
END;
/
ERROR: handle 2 is not be used
CONTEXT: PL/pgSQL function gms_compress.lz_compress_close(integer,blob) line 2 at assignment
SQL statement "CALL gms_compress.lz_compress_close(v_handle+1,content)"
PL/pgSQL function inline_code_block line 6 at SQL statement
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: content=<NULL>
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
RAISE NOTICE 'content=%', content;
END;
/
ERROR: no handle free, the maximum number of handles is 5
CONTEXT: PL/pgSQL function inline_code_block line 10 at assignment
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(2,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(3,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(4,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(5,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
ERROR: handle 1 is not be used
CONTEXT: PL/pgSQL function gms_compress.lz_compress_close(integer,blob) line 2 at assignment
SQL statement "CALL gms_compress.lz_compress_close(1,content)"
PL/pgSQL function inline_code_block line 10 at SQL statement
-- test gms_compress.lz_compress_add
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: content=1F8B080000000000000363540600CC52A5FA02000000
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: content=1F8B0800000000000003635466540600F3008F1804000000
-- abnormal scenario
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,NULL);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
ERROR: parameter cannot be NULL
CONTEXT: SQL statement "CALL gms_compress.lz_compress_add(v_handle,content,NULL)"
PL/pgSQL function inline_code_block line 8 at SQL statement
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: content=<NULL>
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(0,content,src);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
ERROR: invalid handle, it be within the range of 1 to 5
CONTEXT: SQL statement "CALL gms_compress.compress_add(handle,src)"
PL/pgSQL function gms_compress.lz_compress_add(integer,blob,raw) line 5 at PERFORM
SQL statement "CALL gms_compress.lz_compress_add(0,content,src)"
PL/pgSQL function inline_code_block line 8 at SQL statement
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: content=<NULL>
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle+1,content,src);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
ERROR: handle 2 is not be used
CONTEXT: SQL statement "CALL gms_compress.compress_add(handle,src)"
PL/pgSQL function gms_compress.lz_compress_add(integer,blob,raw) line 5 at PERFORM
SQL statement "CALL gms_compress.lz_compress_add(v_handle+1,content,src)"
PL/pgSQL function inline_code_block line 8 at SQL statement
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: content=<NULL>
-- test gms_compress.lz_uncompress_open and ms_compress.lz_uncompress_close
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
END;
/
NOTICE: v_handle=1
NOTICE: content=1F8B080000000000000363540600CC52A5FA02000000
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
END;
/
NOTICE: v_handle=1
NOTICE: v_handle=2
NOTICE: v_handle=3
NOTICE: v_handle=4
NOTICE: v_handle=5
-- abnormal scenario
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
END;
/
ERROR: uncompress_data can not be NULL
CONTEXT: PL/pgSQL function inline_code_block line 5 at assignment
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
END;
/
ERROR: handle 1 is not be used
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
SQL statement "CALL gms_compress.lz_uncompress_close(v_handle)"
PL/pgSQL function inline_code_block line 7 at PERFORM
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(0);
END;
/
ERROR: invalid handle, it be within the range of 1 to 5
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
SQL statement "CALL gms_compress.lz_uncompress_close(0)"
PL/pgSQL function inline_code_block line 7 at PERFORM
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
END;
/
ERROR: handle 2 is not be used
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
SQL statement "CALL gms_compress.lz_uncompress_close(2)"
PL/pgSQL function inline_code_block line 7 at PERFORM
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
END;
/
ERROR: handle 1 is a compressed handle
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
SQL statement "CALL gms_compress.lz_uncompress_close(v_handle)"
PL/pgSQL function inline_code_block line 6 at PERFORM
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1, content);
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
END;
/
NOTICE: v_handle=1
NOTICE: v_handle=2
NOTICE: v_handle=3
NOTICE: v_handle=4
NOTICE: v_handle=5
ERROR: no handle free, the maximum number of handles is 5
CONTEXT: PL/pgSQL function inline_code_block line 16 at assignment
DECLARE
content BLOB;
v_handle int;
BEGIN
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(6);
END;
/
ERROR: invalid handle, it be within the range of 1 to 5
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
SQL statement "CALL gms_compress.lz_uncompress_close(6)"
PL/pgSQL function inline_code_block line 9 at PERFORM
-- test gms_compress.lz_uncompress_extract
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
NOTICE: content=1F8B080000000000000363540600CC52A5FA02000000
NOTICE: v_raw=0123
-- abnormal scenario
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(0, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
ERROR: invalid handle, it be within the range of 1 to 5
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress_extract(integer,raw) line 2 at assignment
SQL statement "CALL gms_compress.lz_uncompress_extract(0,v_raw)"
PL/pgSQL function inline_code_block line 8 at SQL statement
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
END;
/
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(1, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
ERROR: handle 1 is not be used
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress_extract(integer,raw) line 2 at assignment
SQL statement "CALL gms_compress.lz_uncompress_extract(1,v_raw)"
PL/pgSQL function inline_code_block line 7 at SQL statement
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
ERROR: no compressed data found in handle 1
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress_extract(integer,raw) line 2 at assignment
SQL statement "CALL gms_compress.lz_uncompress_extract(v_handle,v_raw)"
PL/pgSQL function inline_code_block line 7 at SQL statement
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1);
END;
/
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
NOTICE: content=1F8B080000000000000363540600CC52A5FA02000000
NOTICE: v_raw=0123
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
END;
/
ERROR: handle 1 is not be used
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
SQL statement "CALL gms_compress.lz_uncompress_close(1)"
PL/pgSQL function inline_code_block line 3 at PERFORM
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
ERROR: too small, minimum length of gzip format is 14 bytes
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress_extract(integer,raw) line 2 at assignment
SQL statement "CALL gms_compress.lz_uncompress_extract(v_handle,v_raw)"
PL/pgSQL function inline_code_block line 7 at SQL statement
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
END;
/
-- test gms_compress.lz_isopen
DECLARE
content BLOB;
v_handle int;
v_bool boolean;
BEGIN
content := '123';
v_bool := false;
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
RAISE NOTICE 'v_bool=%', v_bool;
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
RAISE NOTICE 'v_bool=%', v_bool;
END;
/
NOTICE: v_bool=t
NOTICE: v_bool=f
DECLARE
content BLOB;
v_handle int;
v_bool boolean;
BEGIN
content := '123';
v_bool := false;
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
RAISE NOTICE 'v_bool=%', v_bool;
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle,content);
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
RAISE NOTICE 'v_bool=%', v_bool;
END;
/
ERROR: when invoking function gms_compress.lz_uncompress_close, expected ")", maybe input something superfluous.
CONTEXT: compilation of PL/pgSQL function "inline_code_block" near line 10
-- abnormal scenario
DECLARE
v_bool boolean;
BEGIN
v_bool := true;
v_bool := GMS_COMPRESS.ISOPEN(0);
RAISE NOTICE 'v_bool=%', v_bool;
END;
/
NOTICE: v_bool=f
DECLARE
v_bool boolean;
BEGIN
v_bool := true;
v_bool := GMS_COMPRESS.ISOPEN(1);
RAISE NOTICE 'v_bool=%', v_bool;
END;
/
NOTICE: v_bool=f
reset search_path;
drop schema gms_compress_test cascade;

View File

@ -0,0 +1,102 @@
/* contrib/gms_compress/gms_compress--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION gms_compress" to load this file. \quit
CREATE SCHEMA gms_compress;
GRANT USAGE ON SCHEMA gms_compress TO PUBLIC;
set behavior_compat_options='proc_outparam_override';
--These functions and procedures compress data using Lempel-Ziv compression algorithm.
CREATE OR REPLACE FUNCTION gms_compress.lz_compress(src IN raw, quality IN integer := 6)
RETURNS raw PACKAGE
AS 'MODULE_PATHNAME','gms_lz_compress'
LANGUAGE C;
CREATE OR REPLACE FUNCTION gms_compress.lz_compress(src IN blob, quality IN integer := 6)
RETURNS blob PACKAGE
AS 'MODULE_PATHNAME','gms_lz_compress'
LANGUAGE C;
CREATE OR REPLACE PROCEDURE gms_compress.lz_compress(src IN blob, dst INOUT blob, quality IN integer := 6) PACKAGE as
begin
dst := gms_compress.lz_compress(src, quality);
end;
CREATE OR REPLACE FUNCTION gms_compress.lz_compress_open(src INOUT blob, quality IN integer := 6)
RETURNS integer
AS 'MODULE_PATHNAME','gms_lz_compress_open'
LANGUAGE C;
CREATE OR REPLACE FUNCTION gms_compress.lz_compress_close(handle IN integer)
RETURNS blob PACKAGE
AS '$libdir/gms_compress', 'gms_lz_compress_close'
LANGUAGE C;
CREATE OR REPLACE PROCEDURE gms_compress.lz_compress_close(handle IN integer, dst INOUT blob) PACKAGE AS
begin
dst := gms_compress.lz_compress_close(handle);
end;
CREATE OR REPLACE FUNCTION gms_compress.lz_uncompress_open(src IN blob)
RETURNS integer
AS 'MODULE_PATHNAME','gms_lz_uncompress_open'
LANGUAGE C;
CREATE OR REPLACE FUNCTION gms_compress.uncompress_close(handle IN integer)
RETURNS void
AS '$libdir/gms_compress', 'gms_lz_uncompress_close'
LANGUAGE C;
CREATE OR REPLACE PROCEDURE gms_compress.lz_uncompress_close(handle IN integer) AS
begin
gms_compress.uncompress_close(handle);
end;
CREATE OR REPLACE FUNCTION gms_compress.compress_add(handle IN integer, src IN raw)
RETURNS void PACKAGE
AS '$libdir/gms_compress', 'gms_lz_compress_add'
LANGUAGE C;
CREATE OR REPLACE PROCEDURE gms_compress.lz_compress_add(handle IN integer, dst INOUT blob, src IN raw) PACKAGE AS
begin
IF src IS NULL THEN
RAISE EXCEPTION 'parameter cannot be NULL';
END IF;
gms_compress.compress_add(handle, src);
end;
CREATE OR REPLACE FUNCTION gms_compress.uncompress_extract(handle IN integer)
RETURNS raw PACKAGE
AS '$libdir/gms_compress', 'gms_lz_uncompress_extract'
LANGUAGE C;
CREATE OR REPLACE PROCEDURE gms_compress.lz_uncompress_extract(handle IN integer, dst INOUT raw) PACKAGE AS
begin
dst := gms_compress.uncompress_extract(handle);
end;
CREATE OR REPLACE FUNCTION gms_compress.isopen(handle IN integer)
RETURNS boolean
AS '$libdir/gms_compress', 'gms_isopen'
LANGUAGE C;
----These functions and procedures decompress data using the Lempel-Ziv decompression algorithm.
CREATE OR REPLACE FUNCTION gms_compress.lz_uncompress(src IN raw)
RETURNS raw PACKAGE
AS 'MODULE_PATHNAME','gms_lz_uncompress'
LANGUAGE C;
CREATE OR REPLACE FUNCTION gms_compress.lz_uncompress(src IN blob)
RETURNS blob PACKAGE
AS 'MODULE_PATHNAME','gms_lz_uncompress'
LANGUAGE C;
CREATE OR REPLACE PROCEDURE gms_compress.lz_uncompress(src IN blob, dst INOUT blob) PACKAGE as
begin
IF src IS NULL OR dst IS NULL THEN
RAISE EXCEPTION 'parameter cannot be NULL';
END IF;
dst := gms_compress.lz_uncompress(src);
end;

View File

@ -0,0 +1,5 @@
# gms_compress extension
comment = 'provides a set of data compression utilities'
default_version = '1.0'
module_pathname = '$libdir/gms_compress'
relocatable = true

View File

@ -0,0 +1,399 @@
#include <cstdlib>
#include <zlib.h>
#include "postgres.h"
#include "knl/knl_variable.h"
#include "commands/extension.h"
#include "utils/builtins.h"
#include "utils/varbit.h"
#include "utils/memutils.h"
#include "gms_compress.h"
PG_MODULE_MAGIC;
#define MIN_QUALITY 1
#define MAX_QUALITY 9
#define MIN_HANDLE 0
#define MAX_HANDLE 4
#define HANDLE_OFFSET 1
#define UNCOMPRESS_LEVEL 0
PG_FUNCTION_INFO_V1(gms_lz_compress);
PG_FUNCTION_INFO_V1(gms_lz_uncompress);
PG_FUNCTION_INFO_V1(gms_lz_compress_open);
PG_FUNCTION_INFO_V1(gms_lz_compress_close);
PG_FUNCTION_INFO_V1(gms_lz_compress_add);
PG_FUNCTION_INFO_V1(gms_lz_uncompress_open);
PG_FUNCTION_INFO_V1(gms_lz_uncompress_close);
PG_FUNCTION_INFO_V1(gms_lz_uncompress_extract);
PG_FUNCTION_INFO_V1(gms_isopen);
static void gzip_compress(void* src, Size src_len, void** dst, Size* dst_len, int quality);
static void gzip_uncompress(void* src, Size src_len, void** dst, Size* dst_len);
static void free_context(int handle);
static inline void Check_Invalid_Input(gms_compress_context* compress_cxt, int handle);
static uint32 compress_index;
void set_extension_index(uint32 index)
{
compress_index = index;
}
void init_session_vars(void) {
RepallocSessionVarsArrayIfNecessary();
gms_compress_context* psc =
(gms_compress_context*)MemoryContextAlloc(u_sess->self_mem_cxt, sizeof(gms_compress_context));
u_sess->attr.attr_common.extension_session_vars_array[compress_index] = psc;
for (int i =0;i < UTLCOMP_MAX_HANDLE;i++) {
psc->context[i].compress_level = -1;
psc->context[i].compressed_data = NULL;
psc->context[i].uncompressed_data = NULL;
psc->context[i].used = false;
}
}
gms_compress_context* get_session_context() {
if (u_sess->attr.attr_common.extension_session_vars_array[compress_index] == NULL) {
init_session_vars();
}
return (gms_compress_context*)u_sess->attr.attr_common.extension_session_vars_array[compress_index];
}
Datum gms_lz_compress(PG_FUNCTION_ARGS)
{
if (PG_ARGISNULL(0)) {
ereport(ERROR, (errmsg("compressed data cannot be NULL")));
}
bytea *input_bytea = PG_GETARG_BYTEA_PP(0);
int quality = PG_GETARG_INT32(1);
Size src_len = VARSIZE_ANY_EXHDR(input_bytea);
bytea *dst = NULL;
Size dst_len = 0;
/* Call gzip_compress function for compression */
gzip_compress(input_bytea, src_len, (void**)&dst, &dst_len, quality);
SET_VARSIZE(dst, VARHDRSZ + dst_len);
PG_RETURN_BYTEA_P(dst);
}
Datum gms_lz_uncompress(PG_FUNCTION_ARGS)
{
if (PG_ARGISNULL(0)) {
ereport(ERROR, (errmsg("uncompressed data cannot be NULL")));
}
bytea *input_bytea = PG_GETARG_BYTEA_PP(0);
Size src_len = VARSIZE_ANY_EXHDR(input_bytea);
bytea *dst = NULL;
Size dst_len = 0;
/* Call gzip_uncompress function for uncompression */
gzip_uncompress(input_bytea, src_len, (void**)&dst, &dst_len);
SET_VARSIZE(dst, VARHDRSZ + dst_len);
PG_RETURN_TEXT_P(dst);
}
/* Open a handle and initialize it */
Datum gms_lz_compress_open(PG_FUNCTION_ARGS)
{
bytea *input_bytea = PG_GETARG_BYTEA_PP(0);
int quality = PG_GETARG_INT32(1);
if (quality < MIN_QUALITY || quality > MAX_QUALITY) {
ereport(ERROR, (errmsg("compression quality must be within the range of %d to %d", MIN_QUALITY, MAX_QUALITY)));
}
gms_compress_context *compress_cxt = get_session_context();
for(int i = 0;i < UTLCOMP_MAX_HANDLE;i++) {
if (!compress_cxt->context[i].used) {
compress_cxt->context[i].compress_level = quality;
compress_cxt->context[i].used = true;
PG_RETURN_INT32(i + HANDLE_OFFSET);
}
}
ereport(ERROR, (errmsg("no handle free, the maximum number of handles is %d", MAX_HANDLE + HANDLE_OFFSET)));
PG_RETURN_VOID();
}
/* Close a handle and compress the data back */
Datum gms_lz_compress_close(PG_FUNCTION_ARGS)
{
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
gms_compress_context *compress_cxt = get_session_context();
Check_Invalid_Input(compress_cxt, handle);
if (compress_cxt->context[handle].uncompressed_data == NULL) {
free_context(handle);
PG_RETURN_NULL();
}
if (compress_cxt->context[handle].compress_level == UNCOMPRESS_LEVEL) {
ereport(ERROR, (errmsg("handle %d is a uncompressed handle", handle + HANDLE_OFFSET)));
}
bytea *input_bytea = (bytea *)compress_cxt->context[handle].uncompressed_data;
Assert((char*)input_bytea + VARHDRSZ == VARDATA_ANY(input_bytea));
Size src_len = VARSIZE_ANY_EXHDR(input_bytea);
if (src_len > MaxAllocSize - VARHDRSZ) {
free_context(handle);
ereport(ERROR, (errmsg("data too long, data size cannot exceed 1GB")));
}
bytea *dst = NULL;
Size dst_len = 0;
int quality = compress_cxt->context[handle].compress_level;
/* Call gzip_compress function for compression */
gzip_compress(input_bytea, src_len, (void**)&dst, &dst_len, quality);
SET_VARSIZE(dst, VARHDRSZ + dst_len);
free_context(handle);
PG_RETURN_BYTEA_P(dst);
}
/* Open a handle and store data into it */
Datum gms_lz_compress_add(PG_FUNCTION_ARGS)
{
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
gms_compress_context *compress_cxt = get_session_context();
bytea *input_bytea = PG_GETARG_BYTEA_PP(1);
Size src_len = VARSIZE_ANY_EXHDR(input_bytea);
Check_Invalid_Input(compress_cxt, handle);
if (compress_cxt->context[handle].compress_level == UNCOMPRESS_LEVEL) {
ereport(ERROR, (errmsg("handle %d is a uncompressed handle", handle + HANDLE_OFFSET)));
}
if (src_len > MaxAllocSize - VARHDRSZ) {
ereport(ERROR, (errmsg("data too long, data size cannot exceed 1GB")));
}
bytea *new_data = (bytea *)compress_cxt->context[handle].uncompressed_data;
if (new_data == NULL) {
new_data = (bytea *)MemoryContextAlloc(u_sess->self_mem_cxt, src_len + VARHDRSZ);
SET_VARSIZE(new_data, src_len + VARHDRSZ);
Assert((char*)new_data + VARHDRSZ == VARDATA_ANY(new_data));
errno_t rc = memcpy_s(VARDATA(new_data), src_len, VARDATA(input_bytea), src_len);
securec_check(rc, "\0", "\0");
compress_cxt->context[handle].uncompressed_data = new_data;
} else {
Size dst_len = VARSIZE_ANY_EXHDR(new_data);
Size uncompressed_size = src_len + dst_len + VARHDRSZ;
if (uncompressed_size > MaxAllocSize) {
ereport(ERROR, (errmsg("data too long, data size cannot exceed 1GB")));
}
new_data = (bytea *)repalloc(new_data, uncompressed_size);
SET_VARSIZE(new_data, uncompressed_size);
Assert((char*)new_data + VARHDRSZ == VARDATA_ANY(new_data));
errno_t rc = memcpy_s(VARDATA(new_data) + dst_len, src_len, VARDATA(input_bytea), src_len);
securec_check(rc, "\0", "\0");
compress_cxt->context[handle].uncompressed_data = new_data;
}
PG_RETURN_VOID();
}
/* Open a handle and initialize it */
Datum gms_lz_uncompress_open(PG_FUNCTION_ARGS)
{
if (PG_ARGISNULL(0)) {
ereport(ERROR, (errmsg("uncompress_data can not be NULL")));
}
bytea *input_bytea = PG_GETARG_BYTEA_PP(0);
gms_compress_context *compress_cxt = get_session_context();
for(int i = 0;i < UTLCOMP_MAX_HANDLE;i++) {
if (!compress_cxt->context[i].used) {
compress_cxt->context[i].compressed_data = input_bytea;
compress_cxt->context[i].compress_level = UNCOMPRESS_LEVEL;
compress_cxt->context[i].used = true;
PG_RETURN_INT32(i + HANDLE_OFFSET);
}
}
ereport(ERROR, (errmsg("no handle free, the maximum number of handles is %d", MAX_HANDLE + HANDLE_OFFSET)));
PG_RETURN_VOID();
}
/* Close and free the handle */
Datum gms_lz_uncompress_close(PG_FUNCTION_ARGS)
{
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
gms_compress_context *compress_cxt = get_session_context();
Check_Invalid_Input(compress_cxt, handle);
if (compress_cxt->context[handle].compress_level != UNCOMPRESS_LEVEL) {
ereport(ERROR, (errmsg("handle %d is a compressed handle", handle + HANDLE_OFFSET)));
}
free_context(handle);
PG_RETURN_VOID();
}
/* Open a handle and uncompress the data back */
Datum gms_lz_uncompress_extract(PG_FUNCTION_ARGS)
{
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
gms_compress_context *compress_cxt = get_session_context();
Check_Invalid_Input(compress_cxt, handle);
if (compress_cxt->context[handle].compressed_data == NULL) {
ereport(ERROR, (errmsg("no compressed data found in handle %d", handle + HANDLE_OFFSET)));
}
if (compress_cxt->context[handle].compress_level != UNCOMPRESS_LEVEL) {
ereport(ERROR, (errmsg("handle %d is a compressed handle", handle + HANDLE_OFFSET)));
}
bytea *src = (bytea *)compress_cxt->context[handle].compressed_data;
Size src_len = VARSIZE_ANY_EXHDR(src);
Size dst_len = 0;
bytea *dst = NULL;
gzip_uncompress(src, src_len, (void**)&dst, &dst_len);
SET_VARSIZE(dst, VARHDRSZ + dst_len);
PG_RETURN_BYTEA_P(dst);
}
/* Check if a handle has been opened */
Datum gms_isopen(PG_FUNCTION_ARGS)
{
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
if (handle < MIN_HANDLE || handle > MAX_HANDLE) {
return false;
}
return get_session_context()->context[handle].used;
}
/* Using the zlib library and Lemoel Xiv algorithm to implement compression functionality */
static void gzip_compress(void* src, Size src_len, void** dst, Size* dst_len, int quality)
{
/* The compression quality is limited between 1 and 9 */
if (quality < MIN_QUALITY || quality > MAX_QUALITY) {
ereport(ERROR, (errmsg("compression quality must be within the range of %d to %d", MIN_QUALITY, MAX_QUALITY)));
}
bytea *input_bytea = (bytea*)src;
Size compressed_size = compressBound(src_len) + GZIP_COMPRESS_EXTRA_LENGTH;
bytea *result = (bytea*)palloc(VARHDRSZ + compressed_size);
SET_VARSIZE(result, VARHDRSZ + compressed_size);
z_stream c_stream;
c_stream.zalloc = NULL;
c_stream.zfree = NULL;
c_stream.opaque = NULL;
// MAX_WBITS + 16 for gzip
if (deflateInit2(&c_stream, quality, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
pfree_ext(result);
ereport(ERROR, (errmsg("zlib compression initialization failed")));
}
c_stream.avail_out = compressed_size; // output size
c_stream.next_out = (Bytef*)VARDATA_ANY(result); // output buffer
c_stream.avail_in = src_len; // input size
c_stream.next_in = (Bytef*)VARDATA_ANY(input_bytea); // input buffer
if (deflate(&c_stream, Z_FINISH) != Z_STREAM_END) {
pfree_ext(result);
ereport(ERROR, (errmsg("zlib compression failed")));
}
if (deflateEnd(&c_stream) != Z_OK) {
pfree_ext(result);
ereport(ERROR, (errmsg("zlib cleaning up compression stream failed")));
}
*dst_len = c_stream.total_out;
*dst = result;
}
/* Using the zlib library and Lemoel Xiv algorithm to implement uncompression functionality */
static void gzip_uncompress(void* src, Size src_len, void** dst, Size* dst_len)
{
bytea *input_bytea = (bytea*)src;
if (src_len < GZIP_MIN_LENGTH) {
ereport(ERROR, (errmsg("too small, minimum length of gzip format is %d bytes", GZIP_MIN_LENGTH)));
}
unsigned char *gzip_content = (unsigned char*)VARDATA_ANY(input_bytea);
if (gzip_content[0] != GZIP_HEADER_1 || gzip_content[1] != GZIP_HEADER_2) {
ereport(ERROR, (errmsg("data corrupt, invalid compressed data head")));
}
uint4 uncompressed_size = *(uint4*)(gzip_content + src_len - sizeof(int));
#ifdef WORDS_BIGENDIAN
uncompressed_size = BSWAP32(uncompressed_size);
#endif
if (uncompressed_size > MaxAllocSize - VARHDRSZ) {
ereport(ERROR, (errmsg("data too long, data size cannot exceed 1GB")));
}
bytea *result = (bytea*)palloc(VARHDRSZ + uncompressed_size);
SET_VARSIZE(result, VARHDRSZ + uncompressed_size);
z_stream d_stream = { 0 };
d_stream.zalloc = NULL;
d_stream.zfree = NULL;
d_stream.opaque = NULL;
d_stream.next_in = (Bytef*)VARDATA_ANY(input_bytea);
d_stream.avail_in = src_len;
d_stream.avail_out = VARSIZE_ANY_EXHDR(result);
d_stream.next_out = (Bytef*)VARDATA_ANY(result);
// MAX_WBITS + 16 for gzip
if (inflateInit2(&d_stream, 16 + MAX_WBITS) != Z_OK) {
pfree_ext(result);
ereport(ERROR, (errmsg("zlib uncompression initialization failed")));
}
if (inflate(&d_stream, Z_FINISH) != Z_STREAM_END) {
pfree_ext(result);
ereport(ERROR, (errmsg("zlib uncompression failed")));
}
if (inflateEnd(&d_stream) != Z_OK) {
pfree_ext(result);
ereport(ERROR, (errmsg("zlib cleaning up uncompression stream failed")));
}
*dst_len = d_stream.total_out;
*dst = result;
return;
}
/**
* Because compressed_data is the data source address and
* uncompressed_data is the newly created data address,
* it is necessary to point compressed_data to null and release uncompressed_data
*/
static void free_context(int handle)
{
if (handle < MIN_HANDLE || handle > MAX_HANDLE)
{
return;
}
gms_compress_context *compress_cxt = get_session_context();
compress_cxt->context[handle].compressed_data =NULL;
pfree_ext(compress_cxt->context[handle].uncompressed_data);
compress_cxt->context[handle].compress_level = -1;
compress_cxt->context[handle].used = false;
return;
}
static inline void Check_Invalid_Input(gms_compress_context* compress_cxt, int handle) {
if (handle < MIN_HANDLE || handle > MAX_HANDLE) {
ereport(ERROR, (errmsg("invalid handle, it be within the range of %d to %d",
MIN_HANDLE + HANDLE_OFFSET, MAX_HANDLE + HANDLE_OFFSET)));
}
if (!compress_cxt->context[handle].used) {
ereport(ERROR, (errmsg("handle %d is not be used", handle + HANDLE_OFFSET)));
}
}

View File

@ -0,0 +1,36 @@
#ifndef __GMS_COMPRESS__
#define __GMS_COMPRESS__
#include "postgres.h"
#define GZIP_COMPRESS_EXTRA_LENGTH 18
#define GZIP_MIN_LENGTH 14
#define GZIP_HEADER_1 ((unsigned char)0x1f)
#define GZIP_HEADER_2 ((unsigned char)0x8b)
#define UTLCOMP_MAX_HANDLE 5
typedef struct gms_context {
void *uncompressed_data; /* data to be compressed */
void *compressed_data; /* data after compressed or data to be uncompressed */
int2 compress_level; /* 0 for uncompress, 1~9 for compress */
bool used;
} gms_context;
typedef struct gms_compress_context {
gms_context context[UTLCOMP_MAX_HANDLE];
} gms_compress_context;
extern "C" Datum gms_lz_compress(PG_FUNCTION_ARGS);
extern "C" Datum gms_lz_uncompress(PG_FUNCTION_ARGS);
extern "C" Datum gms_lz_compress_open(PG_FUNCTION_ARGS);
extern "C" Datum gms_lz_compress_close(PG_FUNCTION_ARGS);
extern "C" Datum gms_lz_compress_add(PG_FUNCTION_ARGS);
extern "C" Datum gms_lz_uncompress_open(PG_FUNCTION_ARGS);
extern "C" Datum gms_lz_uncompress_close(PG_FUNCTION_ARGS);
extern "C" Datum gms_lz_uncompress_extract(PG_FUNCTION_ARGS);
extern "C" Datum gms_isopen(PG_FUNCTION_ARGS);
extern "C" void set_extension_index(uint32 index);
extern "C" void init_session_vars(void);
#endif // __GMS_COMPRESS__

View File

@ -0,0 +1,715 @@
create extension gms_compress;
create schema gms_compress_test;
set search_path=gms_compress_test;
-- test gms_compress.compress
select gms_compress.lz_compress('123'::raw);
select gms_compress.lz_compress('df'::raw);
select gms_compress.lz_compress('12ab56'::raw);
select gms_compress.lz_compress('123'::raw, 1);
select gms_compress.lz_compress('df'::raw, 6);
select gms_compress.lz_compress('12ab56'::raw, 9);
select gms_compress.lz_compress('123'::blob);
select gms_compress.lz_compress('df'::blob);
select gms_compress.lz_compress('12ab56'::blob);
select gms_compress.lz_compress('123'::blob, 1);
select gms_compress.lz_compress('df'::blob, 6);
select gms_compress.lz_compress('12ab56'::blob, 9);
DECLARE
content BLOB;
r_content BLOB;
v_handle int;
v_raw raw;
r_raw raw;
v_bool boolean;
BEGIN
content := '123';
v_raw := '12345';
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw);
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
r_content := '111';
GMS_COMPRESS.LZ_COMPRESS(content, r_content);
RAISE NOTICE 'r_content=%', r_content;
END;
/
DECLARE
content BLOB;
r_content BLOB;
v_handle int;
v_raw raw;
r_raw raw;
v_bool boolean;
BEGIN
content := 'abc';
v_raw := 'df';
r_content := GMS_COMPRESS.LZ_COMPRESS(content, 1);
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw, 9);
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
r_content := '111';
GMS_COMPRESS.LZ_COMPRESS(content, r_content, 5);
RAISE NOTICE 'r_content=%', r_content;
END;
/
-- abnormal scenario
select gms_compress.lz_compress(null::raw);
select gms_compress.lz_compress(''::raw);
select gms_compress.lz_compress('dfg'::raw);
select gms_compress.lz_compress('dfg'::raw, 5);
select gms_compress.lz_compress('123'::raw, 0);
select gms_compress.lz_compress('123'::raw, 10);
select gms_compress.lz_compress(null::blob);
select gms_compress.lz_compress(''::blob);
select gms_compress.lz_compress('dfg'::blob);
select gms_compress.lz_compress('dfg'::blob, 5);
select gms_compress.lz_compress('123'::blob, 0);
select gms_compress.lz_compress('123'::blob, 10);
DECLARE
content BLOB;
r_content BLOB;
v_raw raw;
r_raw raw;
BEGIN
content := '';
v_raw := 'dfg';
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw);
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
r_content := '111';
GMS_COMPRESS.LZ_COMPRESS(content, r_content);
RAISE NOTICE 'r_content=%', r_content;
END;
/
DECLARE
content BLOB;
r_content BLOB;
v_raw raw;
r_raw raw;
BEGIN
content := 'abc';
v_raw := 'df';
r_content := GMS_COMPRESS.LZ_COMPRESS(content, 0);
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw, 10);
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
r_content := '111';
GMS_COMPRESS.LZ_COMPRESS(content, r_content, -1);
RAISE NOTICE 'r_content=%', r_content;
END;
/
-- test gms_compress.lz_uncompress
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::raw));
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::raw));
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::raw));
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::raw, 1));
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::raw, 6));
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::raw, 9));
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::blob));
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::blob));
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::blob));
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::blob, 1));
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::blob, 6));
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::blob, 9));
DECLARE
content BLOB;
r_content BLOB;
v_content BLOB;
v_bool boolean;
BEGIN
content := '123';
v_content := '123';
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
END;
/
-- abnormal scenario
select gms_compress.lz_uncompress(null::raw);
select gms_compress.lz_uncompress(''::raw);
select gms_compress.lz_uncompress('dfg'::raw);
select gms_compress.lz_uncompress('123'::raw);
select gms_compress.lz_uncompress(null::blob);
select gms_compress.lz_uncompress(''::blob);
select gms_compress.lz_uncompress('dfg'::blob);
select gms_compress.lz_uncompress('123'::blob);
DECLARE
content BLOB;
r_content BLOB;
v_content BLOB;
v_bool boolean;
BEGIN
r_content := NULL;
v_content := '123';
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
END;
/
DECLARE
content BLOB;
r_content BLOB;
v_content BLOB;
v_bool boolean;
BEGIN
r_content := '123';
v_content := '123';
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
END;
/
DECLARE
content BLOB;
r_content BLOB;
v_content BLOB;
v_bool boolean;
BEGIN
content := '123';
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
v_content := NULL;
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
END;
/
-- test gms_compress.lz_compress_open and ms_compress.lz_compress_close
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content,5);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(2,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(3,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(4,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(5,content);
END;
/
-- abnormal scenario
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content, 0);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(0,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle+1,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(2,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(3,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(4,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(5,content);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
-- test gms_compress.lz_compress_add
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
-- abnormal scenario
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,NULL);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(0,content,src);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
src raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
src := '123';
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle+1,content,src);
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
RAISE NOTICE 'content=%', content;
END;
/
-- test gms_compress.lz_uncompress_open and ms_compress.lz_uncompress_close
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
END;
/
-- abnormal scenario
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(0);
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1, content);
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
RAISE NOTICE 'v_handle=%', v_handle;
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
END;
/
DECLARE
content BLOB;
v_handle int;
BEGIN
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(6);
END;
/
-- test gms_compress.lz_uncompress_extract
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
-- abnormal scenario
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(0, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
END;
/
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(1, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1);
END;
/
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
END;
/
DECLARE
content BLOB;
v_handle int;
v_raw raw;
BEGIN
content := '123';
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
RAISE NOTICE 'content=%', content;
RAISE NOTICE 'v_raw=%', v_raw;
END;
/
DECLARE
content BLOB;
BEGIN
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
END;
/
-- test gms_compress.lz_isopen
DECLARE
content BLOB;
v_handle int;
v_bool boolean;
BEGIN
content := '123';
v_bool := false;
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
RAISE NOTICE 'v_bool=%', v_bool;
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
RAISE NOTICE 'v_bool=%', v_bool;
END;
/
DECLARE
content BLOB;
v_handle int;
v_bool boolean;
BEGIN
content := '123';
v_bool := false;
content := GMS_COMPRESS.LZ_COMPRESS(content);
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
RAISE NOTICE 'v_bool=%', v_bool;
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle,content);
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
RAISE NOTICE 'v_bool=%', v_bool;
END;
/
-- abnormal scenario
DECLARE
v_bool boolean;
BEGIN
v_bool := true;
v_bool := GMS_COMPRESS.ISOPEN(0);
RAISE NOTICE 'v_bool=%', v_bool;
END;
/
DECLARE
v_bool boolean;
BEGIN
v_bool := true;
v_bool := GMS_COMPRESS.ISOPEN(1);
RAISE NOTICE 'v_bool=%', v_bool;
END;
/
reset search_path;
drop schema gms_compress_test cascade;

View File

@ -96,6 +96,7 @@ static void DropExtensionInListIsSupported(List* objname)
"db_pg_parser",
"hdfs_fdw",
"age",
"gms_compress",
"gms_stats",
"gms_output",
"gms_profiler",