| 1 |
CREATE EXTENSION tsm_system_time; |
| 2 |
|
| 3 |
CREATE TABLE test_tablesample (id int, name text); |
| 4 |
INSERT INTO test_tablesample SELECT i, repeat(i::text, 1000) |
| 5 |
FROM generate_series(0, 30) s(i); |
| 6 |
ANALYZE test_tablesample; |
| 7 |
|
| 8 |
-- It's a bit tricky to test SYSTEM_TIME in a platform-independent way. |
| 9 |
-- We can test the zero-time corner case ... |
| 10 |
SELECT count(*) FROM test_tablesample TABLESAMPLE system_time (0); |
| 11 |
-- ... and we assume that this will finish before running out of time: |
| 12 |
SELECT count(*) FROM test_tablesample TABLESAMPLE system_time (100000); |
| 13 |
|
| 14 |
-- bad parameters should get through planning, but not execution: |
| 15 |
EXPLAIN (COSTS OFF) |
| 16 |
SELECT id FROM test_tablesample TABLESAMPLE system_time (-1); |
| 17 |
|
| 18 |
SELECT id FROM test_tablesample TABLESAMPLE system_time (-1); |
| 19 |
|
| 20 |
-- fail, this method is not repeatable: |
| 21 |
SELECT * FROM test_tablesample TABLESAMPLE system_time (10) REPEATABLE (0); |
| 22 |
|
| 23 |
-- since it's not repeatable, we expect a Materialize node in these plans: |
| 24 |
EXPLAIN (COSTS OFF) |
| 25 |
SELECT * FROM |
| 26 |
(VALUES (0),(100000)) v(time), |
| 27 |
LATERAL (SELECT COUNT(*) FROM test_tablesample |
| 28 |
TABLESAMPLE system_time (100000)) ss; |
| 29 |
|
| 30 |
SELECT * FROM |
| 31 |
(VALUES (0),(100000)) v(time), |
| 32 |
LATERAL (SELECT COUNT(*) FROM test_tablesample |
| 33 |
TABLESAMPLE system_time (100000)) ss; |
| 34 |
|
| 35 |
EXPLAIN (COSTS OFF) |
| 36 |
SELECT * FROM |
| 37 |
(VALUES (0),(100000)) v(time), |
| 38 |
LATERAL (SELECT COUNT(*) FROM test_tablesample |
| 39 |
TABLESAMPLE system_time (time)) ss; |
| 40 |
|
| 41 |
SELECT * FROM |
| 42 |
(VALUES (0),(100000)) v(time), |
| 43 |
LATERAL (SELECT COUNT(*) FROM test_tablesample |
| 44 |
TABLESAMPLE system_time (time)) ss; |
| 45 |
|
| 46 |
CREATE VIEW vv AS |
| 47 |
SELECT * FROM test_tablesample TABLESAMPLE system_time (20); |
| 48 |
|
| 49 |
EXPLAIN (COSTS OFF) SELECT * FROM vv; |
| 50 |
|
| 51 |
DROP EXTENSION tsm_system_time; -- fail, view depends on extension |