Skip to content

Commit 731ceb6

Browse files
committed
Merge branch 'PGPRO9_6' into PGPROEE9_6_ALPHA
Conflicts: contrib/Makefile
2 parents bc81e86 + e3b43b3 commit 731ceb6

File tree

146 files changed

+12869
-529
lines changed

Some content is hidden

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

146 files changed

+12869
-529
lines changed

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

contrib/fasttrun/sql/fasttrun.sql

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
CREATE EXTENSION fasttrun;
2+
3+
create table persist ( a int );
4+
insert into persist values (1);
5+
select fasttruncate('persist');
6+
insert into persist values (2);
7+
select * from persist order by a;
8+
9+
create temp table temp1 (a int);
10+
insert into temp1 values (1);
11+
12+
BEGIN;
13+
14+
create temp table temp2 (a int);
15+
insert into temp2 values (1);
16+
17+
select * from temp1 order by a;
18+
select * from temp2 order by a;
19+
20+
insert into temp1 (select * from generate_series(1,10000));
21+
insert into temp2 (select * from generate_series(1,11000));
22+
23+
analyze temp2;
24+
select relname, relpages>0, reltuples>0 from pg_class where relname in ('temp1', 'temp2') order by relname;
25+
26+
select fasttruncate('temp1');
27+
select fasttruncate('temp2');
28+
29+
insert into temp1 values (-2);
30+
insert into temp2 values (-2);
31+
32+
select * from temp1 order by a;
33+
select * from temp2 order by a;
34+
35+
COMMIT;
36+
37+
select * from temp1 order by a;
38+
select * from temp2 order by a;
39+
40+
select relname, relpages>0, reltuples>0 from pg_class where relname in ('temp1', 'temp2') order by relname;
41+
42+
select fasttruncate('temp1');
43+
select fasttruncate('temp2');
44+
45+
select * from temp1 order by a;
46+
select * from temp2 order by a;
47+
48+
select relname, relpages>0, reltuples>0 from pg_class where relname in ('temp1', 'temp2') order by relname;

contrib/fulleq/Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
MODULE_big = fulleq
2+
OBJS = fulleq.o
3+
EXTENSION = fulleq
4+
DATA = fulleq--1.0.sql
5+
DOCS = README.fulleq
6+
REGRESS = fulleq
7+
PGFIELDDESC = "fulleq - introduce operator == which returns true when operands are equal or both are nulls."
8+
9+
ARGTYPE = bool bytea char name int8 int2 int2vector int4 text \
10+
oid xid cid oidvector float4 float8 abstime reltime macaddr \
11+
inet cidr varchar date time timestamp timestamptz \
12+
interval timetz
13+
14+
#EXTRA_CLEAN = fulleq--1.0.sql
15+
16+
ifdef USE_PGXS
17+
PGXS := $(shell pg_config --pgxs)
18+
include $(PGXS)
19+
else
20+
subdir = contrib/fulleq
21+
top_builddir = ../..
22+
include $(top_builddir)/src/Makefile.global
23+
include $(top_srcdir)/contrib/contrib-global.mk
24+
endif
25+
26+
fulleq--1.0.sql: fulleq--1.0.sql.in.in
27+
echo '\echo Use "CREATE EXTENSION fulleq" to load this file. \quit' > $@
28+
echo 'SET search_path = public;' >> $@
29+
for type in $(ARGTYPE); \
30+
do \
31+
sed -e "s/ARGTYPE/$$type/g" < $< >> $@; \
32+
done
33+

contrib/fulleq/README.fulleq

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Introduce operator == which returns true when
2+
operands are equal or both are nulls.
3+

0 commit comments

Comments
 (0)