Debian Codegraph @

contrib/tsm_system_time/expected/tsm_system_time.out

raw
1 CREATE EXTENSION tsm_system_time;
2 CREATE TABLE test_tablesample (id int, name text);
3 INSERT INTO test_tablesample SELECT i, repeat(i::text, 1000)
4 FROM generate_series(0, 30) s(i);
5 ANALYZE test_tablesample;
6 -- It's a bit tricky to test SYSTEM_TIME in a platform-independent way.
7 -- We can test the zero-time corner case ...
8 SELECT count(*) FROM test_tablesample TABLESAMPLE system_time (0);
9 count
10 -------
11 0
12 (1 row)
13
14 -- ... and we assume that this will finish before running out of time:
15 SELECT count(*) FROM test_tablesample TABLESAMPLE system_time (100000);
16 count
17 -------
18 31
19 (1 row)
20
21 -- bad parameters should get through planning, but not execution:
22 EXPLAIN (COSTS OFF)
23 SELECT id FROM test_tablesample TABLESAMPLE system_time (-1);
24 QUERY PLAN
25 --------------------------------------------------
26 Sample Scan on test_tablesample
27 Sampling: system_time ('-1'::double precision)
28 (2 rows)
29
30 SELECT id FROM test_tablesample TABLESAMPLE system_time (-1);
31 ERROR: sample collection time must not be negative
32 -- fail, this method is not repeatable:
33 SELECT * FROM test_tablesample TABLESAMPLE system_time (10) REPEATABLE (0);
34 ERROR: tablesample method system_time does not support REPEATABLE
35 LINE 1: SELECT * FROM test_tablesample TABLESAMPLE system_time (10) ...
36 ^
37 -- since it's not repeatable, we expect a Materialize node in these plans:
38 EXPLAIN (COSTS OFF)
39 SELECT * FROM
40 (VALUES (0),(100000)) v(time),
41 LATERAL (SELECT COUNT(*) FROM test_tablesample
42 TABLESAMPLE system_time (100000)) ss;
43 QUERY PLAN
44 ------------------------------------------------------------------------
45 Nested Loop
46 -> Aggregate
47 -> Materialize
48 -> Sample Scan on test_tablesample
49 Sampling: system_time ('100000'::double precision)
50 -> Values Scan on "*VALUES*"
51 (6 rows)
52
53 SELECT * FROM
54 (VALUES (0),(100000)) v(time),
55 LATERAL (SELECT COUNT(*) FROM test_tablesample
56 TABLESAMPLE system_time (100000)) ss;
57 time | count
58 --------+-------
59 0 | 31
60 100000 | 31
61 (2 rows)
62
63 EXPLAIN (COSTS OFF)
64 SELECT * FROM
65 (VALUES (0),(100000)) v(time),
66 LATERAL (SELECT COUNT(*) FROM test_tablesample
67 TABLESAMPLE system_time (time)) ss;
68 QUERY PLAN
69 ----------------------------------------------------------------
70 Nested Loop
71 -> Values Scan on "*VALUES*"
72 -> Aggregate
73 -> Materialize
74 -> Sample Scan on test_tablesample
75 Sampling: system_time ("*VALUES*".column1)
76 (6 rows)
77
78 SELECT * FROM
79 (VALUES (0),(100000)) v(time),
80 LATERAL (SELECT COUNT(*) FROM test_tablesample
81 TABLESAMPLE system_time (time)) ss;
82 time | count
83 --------+-------
84 0 | 0
85 100000 | 31
86 (2 rows)
87
88 CREATE VIEW vv AS
89 SELECT * FROM test_tablesample TABLESAMPLE system_time (20);
90 EXPLAIN (COSTS OFF) SELECT * FROM vv;
91 QUERY PLAN
92 --------------------------------------------------
93 Sample Scan on test_tablesample
94 Sampling: system_time ('20'::double precision)
95 (2 rows)
96
97 DROP EXTENSION tsm_system_time; -- fail, view depends on extension
98 ERROR: cannot drop extension tsm_system_time because other objects depend on it
99 DETAIL: view vv depends on function system_time(internal)
100 HINT: Use DROP ... CASCADE to drop the dependent objects too.