Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 56e121a

Browse files
contrib/tsm_system_time
1 parent 4d40494 commit 56e121a

File tree

7 files changed

+453
-0
lines changed

7 files changed

+453
-0
lines changed

contrib/tsm_system_time/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Generated subdirectories
2+
/log/
3+
/results/
4+
/tmp_check/

contrib/tsm_system_time/Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# src/test/modules/tsm_system_time/Makefile
2+
3+
MODULE_big = tsm_system_time
4+
OBJS = tsm_system_time.o $(WIN32RES)
5+
PGFILEDESC = "tsm_system_time - SYSTEM TABLESAMPLE method which accepts number rows of as a limit"
6+
7+
EXTENSION = tsm_system_time
8+
DATA = tsm_system_time--1.0.sql
9+
10+
REGRESS = tsm_system_time
11+
12+
ifdef USE_PGXS
13+
PG_CONFIG = pg_config
14+
PGXS := $(shell $(PG_CONFIG) --pgxs)
15+
include $(PGXS)
16+
else
17+
subdir = contrib/tsm_system_time
18+
top_builddir = ../..
19+
include $(top_builddir)/src/Makefile.global
20+
include $(top_srcdir)/contrib/contrib-global.mk
21+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
CREATE EXTENSION tsm_system_time;
2+
CREATE TABLE test_tablesample (id int, name text) WITH (fillfactor=10); -- force smaller pages so we don't have to load too much data to get multiple pages
3+
INSERT INTO test_tablesample SELECT i, repeat(i::text, 1000) FROM generate_series(0, 30) s(i) ORDER BY i;
4+
ANALYZE test_tablesample;
5+
SELECT count(*) FROM test_tablesample TABLESAMPLE system_time (1000);
6+
count
7+
-------
8+
31
9+
(1 row)
10+
11+
SELECT id FROM test_tablesample TABLESAMPLE system_time (1000) REPEATABLE (5432);
12+
id
13+
----
14+
7
15+
14
16+
21
17+
28
18+
4
19+
11
20+
18
21+
25
22+
1
23+
8
24+
15
25+
22
26+
29
27+
5
28+
12
29+
19
30+
26
31+
2
32+
9
33+
16
34+
23
35+
30
36+
6
37+
13
38+
20
39+
27
40+
3
41+
10
42+
17
43+
24
44+
0
45+
(31 rows)
46+
47+
EXPLAIN SELECT id FROM test_tablesample TABLESAMPLE system_time (100) REPEATABLE (10);
48+
QUERY PLAN
49+
------------------------------------------------------------------------------------
50+
Sample Scan (system_time) on test_tablesample (cost=0.00..100.25 rows=25 width=4)
51+
(1 row)
52+
53+
-- done
54+
DROP TABLE test_tablesample CASCADE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE EXTENSION tsm_system_time;
2+
3+
CREATE TABLE test_tablesample (id int, name text) WITH (fillfactor=10); -- force smaller pages so we don't have to load too much data to get multiple pages
4+
5+
INSERT INTO test_tablesample SELECT i, repeat(i::text, 1000) FROM generate_series(0, 30) s(i) ORDER BY i;
6+
ANALYZE test_tablesample;
7+
8+
SELECT count(*) FROM test_tablesample TABLESAMPLE system_time (1000);
9+
SELECT id FROM test_tablesample TABLESAMPLE system_time (1000) REPEATABLE (5432);
10+
11+
EXPLAIN SELECT id FROM test_tablesample TABLESAMPLE system_time (100) REPEATABLE (10);
12+
13+
-- done
14+
DROP TABLE test_tablesample CASCADE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* src/test/modules/tablesample/tsm_system_time--1.0.sql */
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use "CREATE EXTENSION tsm_system_time" to load this file. \quit
5+
6+
CREATE FUNCTION tsm_system_time_init(internal, int4, int4)
7+
RETURNS void
8+
AS 'MODULE_PATHNAME'
9+
LANGUAGE C STRICT;
10+
11+
CREATE FUNCTION tsm_system_time_nextblock(internal)
12+
RETURNS int4
13+
AS 'MODULE_PATHNAME'
14+
LANGUAGE C STRICT;
15+
16+
CREATE FUNCTION tsm_system_time_nexttuple(internal, int4, int2)
17+
RETURNS int2
18+
AS 'MODULE_PATHNAME'
19+
LANGUAGE C STRICT;
20+
21+
CREATE FUNCTION tsm_system_time_end(internal)
22+
RETURNS void
23+
AS 'MODULE_PATHNAME'
24+
LANGUAGE C STRICT;
25+
26+
CREATE FUNCTION tsm_system_time_reset(internal)
27+
RETURNS void
28+
AS 'MODULE_PATHNAME'
29+
LANGUAGE C STRICT;
30+
31+
CREATE FUNCTION tsm_system_time_cost(internal, internal, internal, internal, internal, internal, internal)
32+
RETURNS void
33+
AS 'MODULE_PATHNAME'
34+
LANGUAGE C STRICT;
35+
36+
INSERT INTO pg_tablesample_method VALUES('system_time', false, true,
37+
'tsm_system_time_init', 'tsm_system_time_nextblock',
38+
'tsm_system_time_nexttuple', '-', 'tsm_system_time_end',
39+
'tsm_system_time_reset', 'tsm_system_time_cost');
40+

0 commit comments

Comments
 (0)