Skip to content

Commit cc181ea

Browse files
author
Alexander Korotkov
committed
Merge with PGPROEE9_6_ALPHA.
2 parents 2b0a919 + 22c5a59 commit cc181ea

File tree

149 files changed

+12971
-532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+12971
-532
lines changed

configure

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ LDFLAGS_EX
704704
ELF_SYS
705705
EGREP
706706
GREP
707+
with_zstd
707708
with_zlib
708709
with_system_tzdata
709710
with_libxslt
@@ -847,6 +848,7 @@ with_libxml
847848
with_libxslt
848849
with_system_tzdata
849850
with_zlib
851+
with_zstd
850852
with_gnu_ld
851853
enable_largefile
852854
enable_float4_byval
@@ -1540,6 +1542,7 @@ Optional Packages:
15401542
--with-system-tzdata=DIR
15411543
use system time zone data in DIR
15421544
--without-zlib do not use Zlib
1545+
--with-zstd build with libzstd
15431546
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
15441547

15451548
Some influential environment variables:
@@ -6174,6 +6177,88 @@ fi
61746177

61756178

61766179

6180+
#
6181+
# ZStd
6182+
#
6183+
6184+
6185+
6186+
# Check whether --with-zstd was given.
6187+
if test "${with_zstd+set}" = set; then :
6188+
withval=$with_zstd;
6189+
case $withval in
6190+
yes)
6191+
6192+
$as_echo "#define CFS_COMPRESSOR 6" >>confdefs.h
6193+
6194+
;;
6195+
no)
6196+
:
6197+
;;
6198+
*)
6199+
as_fn_error $? "no argument expected for --with-zstd option" "$LINENO" 5
6200+
;;
6201+
esac
6202+
6203+
else
6204+
with_zstd=no
6205+
6206+
fi
6207+
6208+
6209+
6210+
6211+
if test "$with_zstd" = yes ; then
6212+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ZSTD_compress in -lzstd" >&5
6213+
$as_echo_n "checking for ZSTD_compress in -lzstd... " >&6; }
6214+
if ${ac_cv_lib_zstd_ZSTD_compress+:} false; then :
6215+
$as_echo_n "(cached) " >&6
6216+
else
6217+
ac_check_lib_save_LIBS=$LIBS
6218+
LIBS="-lzstd $LIBS"
6219+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6220+
/* end confdefs.h. */
6221+
6222+
/* Override any GCC internal prototype to avoid an error.
6223+
Use char because int might match the return type of a GCC
6224+
builtin and then its argument prototype would still apply. */
6225+
#ifdef __cplusplus
6226+
extern "C"
6227+
#endif
6228+
char ZSTD_compress ();
6229+
int
6230+
main ()
6231+
{
6232+
return ZSTD_compress ();
6233+
;
6234+
return 0;
6235+
}
6236+
_ACEOF
6237+
if ac_fn_c_try_link "$LINENO"; then :
6238+
ac_cv_lib_zstd_ZSTD_compress=yes
6239+
else
6240+
ac_cv_lib_zstd_ZSTD_compress=no
6241+
fi
6242+
rm -f core conftest.err conftest.$ac_objext \
6243+
conftest$ac_exeext conftest.$ac_ext
6244+
LIBS=$ac_check_lib_save_LIBS
6245+
fi
6246+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_zstd_ZSTD_compress" >&5
6247+
$as_echo "$ac_cv_lib_zstd_ZSTD_compress" >&6; }
6248+
if test "x$ac_cv_lib_zstd_ZSTD_compress" = xyes; then :
6249+
cat >>confdefs.h <<_ACEOF
6250+
#define HAVE_LIBZSTD 1
6251+
_ACEOF
6252+
6253+
LIBS="-lzstd $LIBS"
6254+
6255+
else
6256+
as_fn_error $? "library 'zstd' is required for ZSTD support" "$LINENO" 5
6257+
fi
6258+
6259+
fi
6260+
6261+
61776262
#
61786263
# Elf
61796264
#

configure.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,17 @@ PGAC_ARG_BOOL(with, zlib, yes,
854854
[do not use Zlib])
855855
AC_SUBST(with_zlib)
856856

857+
#
858+
# ZStd
859+
#
860+
PGAC_ARG_BOOL(with, zstd, no, [build with libzstd], [AC_DEFINE([CFS_COMPRESSOR], 6, [Define to 6 to use libzstd support when building CFS. (--with-zstd)])])
861+
AC_SUBST(with_zstd)
862+
863+
if test "$with_zstd" = yes ; then
864+
AC_CHECK_LIB(zstd, ZSTD_compress, [], [AC_MSG_ERROR([library 'zstd' is required for ZSTD support])])
865+
fi
866+
867+
857868
#
858869
# Elf
859870
#

contrib/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ SUBDIRS = \
6363
pg_arman \
6464
pg_pathman \
6565
shared_ispell \
66-
pg_hint_plan
66+
pg_hint_plan \
67+
vacuumlo \
68+
mchar \
69+
fulleq \
70+
fasttrun \
71+
online_analyze \
72+
plantuner
6773

6874
ifeq ($(with_openssl),yes)
6975
SUBDIRS += sslinfo

contrib/fasttrun/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
MODULE_big = fasttrun
2+
OBJS = fasttrun.o $(WIN32RES)
3+
EXTENSION = fasttrun
4+
DATA = fasttrun--1.0.sql
5+
DOCS = README.fasttrun
6+
REGRESS = fasttrun
7+
PGFIELDDESC = "fasttrun - functions to truncates the temporary table and doesn't grow pg_class size."
8+
9+
ifdef USE_PGXS
10+
PGXS := $(shell pg_config --pgxs)
11+
include $(PGXS)
12+
else
13+
subdir = contrib/fasttrun
14+
top_builddir = ../..
15+
include $(top_builddir)/src/Makefile.global
16+
include $(top_srcdir)/contrib/contrib-global.mk
17+
endif

contrib/fasttrun/README.fasttrun

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
select fasttruncate('TABLE_NAME');
2+
3+
Function truncates the temporary table and doesn't grow
4+
pg_class size.
5+
6+
Warning: function isn't transaction safe!
7+
8+
For tests:
9+
create or replace function f() returns void as $$
10+
begin
11+
for i in 1..1000
12+
loop
13+
PERFORM fasttruncate('tt1');
14+
end loop;
15+
end;
16+
$$ language plpgsql;
17+
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
CREATE EXTENSION fasttrun;
2+
create table persist ( a int );
3+
insert into persist values (1);
4+
select fasttruncate('persist');
5+
ERROR: Relation isn't a temporary table
6+
insert into persist values (2);
7+
select * from persist order by a;
8+
a
9+
---
10+
1
11+
2
12+
(2 rows)
13+
14+
create temp table temp1 (a int);
15+
insert into temp1 values (1);
16+
BEGIN;
17+
create temp table temp2 (a int);
18+
insert into temp2 values (1);
19+
select * from temp1 order by a;
20+
a
21+
---
22+
1
23+
(1 row)
24+
25+
select * from temp2 order by a;
26+
a
27+
---
28+
1
29+
(1 row)
30+
31+
insert into temp1 (select * from generate_series(1,10000));
32+
insert into temp2 (select * from generate_series(1,11000));
33+
analyze temp2;
34+
select relname, relpages>0, reltuples>0 from pg_class where relname in ('temp1', 'temp2') order by relname;
35+
relname | ?column? | ?column?
36+
---------+----------+----------
37+
temp1 | f | f
38+
temp2 | t | t
39+
(2 rows)
40+
41+
select fasttruncate('temp1');
42+
fasttruncate
43+
--------------
44+
45+
(1 row)
46+
47+
select fasttruncate('temp2');
48+
fasttruncate
49+
--------------
50+
51+
(1 row)
52+
53+
insert into temp1 values (-2);
54+
insert into temp2 values (-2);
55+
select * from temp1 order by a;
56+
a
57+
----
58+
-2
59+
(1 row)
60+
61+
select * from temp2 order by a;
62+
a
63+
----
64+
-2
65+
(1 row)
66+
67+
COMMIT;
68+
select * from temp1 order by a;
69+
a
70+
----
71+
-2
72+
(1 row)
73+
74+
select * from temp2 order by a;
75+
a
76+
----
77+
-2
78+
(1 row)
79+
80+
select relname, relpages>0, reltuples>0 from pg_class where relname in ('temp1', 'temp2') order by relname;
81+
relname | ?column? | ?column?
82+
---------+----------+----------
83+
temp1 | f | f
84+
temp2 | f | f
85+
(2 rows)
86+
87+
select fasttruncate('temp1');
88+
fasttruncate
89+
--------------
90+
91+
(1 row)
92+
93+
select fasttruncate('temp2');
94+
fasttruncate
95+
--------------
96+
97+
(1 row)
98+
99+
select * from temp1 order by a;
100+
a
101+
---
102+
(0 rows)
103+
104+
select * from temp2 order by a;
105+
a
106+
---
107+
(0 rows)
108+
109+
select relname, relpages>0, reltuples>0 from pg_class where relname in ('temp1', 'temp2') order by relname;
110+
relname | ?column? | ?column?
111+
---------+----------+----------
112+
temp1 | f | f
113+
temp2 | f | f
114+
(2 rows)
115+

contrib/fasttrun/fasttrun--1.0.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE OR REPLACE FUNCTION fasttruncate(text)
2+
RETURNS void AS 'MODULE_PATHNAME'
3+
LANGUAGE C RETURNS NULL ON NULL INPUT VOLATILE;

contrib/fasttrun/fasttrun.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "postgres.h"
2+
3+
#include "access/genam.h"
4+
#include "access/heapam.h"
5+
#include "miscadmin.h"
6+
#include "storage/lmgr.h"
7+
#include "storage/bufmgr.h"
8+
#include "catalog/namespace.h"
9+
#include "utils/lsyscache.h"
10+
#include "utils/builtins.h"
11+
#include <fmgr.h>
12+
#include <funcapi.h>
13+
#include <access/heapam.h>
14+
#include <catalog/pg_type.h>
15+
#include <catalog/heap.h>
16+
#include <commands/vacuum.h>
17+
18+
#ifdef PG_MODULE_MAGIC
19+
PG_MODULE_MAGIC;
20+
#endif
21+
22+
PG_FUNCTION_INFO_V1(fasttruncate);
23+
Datum fasttruncate(PG_FUNCTION_ARGS);
24+
Datum
25+
fasttruncate(PG_FUNCTION_ARGS) {
26+
text *name=PG_GETARG_TEXT_P(0);
27+
char *relname;
28+
List *relname_list;
29+
RangeVar *relvar;
30+
Oid relOid;
31+
Relation rel;
32+
bool makeanalyze = false;
33+
34+
relname = palloc( VARSIZE(name) + 1);
35+
memcpy(relname, VARDATA(name), VARSIZE(name)-VARHDRSZ);
36+
relname[ VARSIZE(name)-VARHDRSZ ] = '\0';
37+
38+
relname_list = stringToQualifiedNameList(relname);
39+
relvar = makeRangeVarFromNameList(relname_list);
40+
relOid = RangeVarGetRelid(relvar, AccessExclusiveLock, false);
41+
42+
if ( get_rel_relkind(relOid) != RELKIND_RELATION )
43+
elog(ERROR,"Relation isn't a ordinary table");
44+
45+
rel = heap_open(relOid, NoLock);
46+
47+
if ( !isTempNamespace(get_rel_namespace(relOid)) )
48+
elog(ERROR,"Relation isn't a temporary table");
49+
50+
heap_truncate(list_make1_oid(relOid));
51+
52+
if ( rel->rd_rel->relpages > 0 || rel->rd_rel->reltuples > 0 )
53+
makeanalyze = true;
54+
55+
/*
56+
* heap_truncate doesn't unlock the table,
57+
* so we should unlock it.
58+
*/
59+
60+
heap_close(rel, AccessExclusiveLock);
61+
62+
if ( makeanalyze ) {
63+
VacuumParams params;
64+
65+
params.freeze_min_age = -1;
66+
params.freeze_table_age = -1;
67+
params.multixact_freeze_min_age = -1;
68+
params.multixact_freeze_table_age = -1;
69+
params.is_wraparound = false;
70+
params.log_min_duration = -1;
71+
72+
vacuum(VACOPT_ANALYZE, NULL, relOid, &params, NULL,
73+
GetAccessStrategy(BAS_VACUUM), false);
74+
}
75+
76+
PG_RETURN_VOID();
77+
}

contrib/fasttrun/fasttrun.control

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# fasttrun extension
2+
comment = 'Functions to truncates the temporary table and does not grow pg_class size'
3+
default_version = '1.0'
4+
module_pathname = '$libdir/fasttrun'
5+
relocatable = true

0 commit comments

Comments
 (0)