blob: e3ab4204eea5ae601aaf9e43c1edec6d0bda29d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
CREATE EXTENSION tsm_system_rows;
CREATE TABLE test_tablesample (id int, name text);
INSERT INTO test_tablesample SELECT i, repeat(i::text, 1000)
FROM generate_series(0, 30) s(i);
ANALYZE test_tablesample;
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (0);
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (1);
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (10);
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (100);
-- bad parameters should get through planning, but not execution:
EXPLAIN (COSTS OFF)
SELECT id FROM test_tablesample TABLESAMPLE system_rows (-1);
SELECT id FROM test_tablesample TABLESAMPLE system_rows (-1);
-- fail, this method is not repeatable:
SELECT * FROM test_tablesample TABLESAMPLE system_rows (10) REPEATABLE (0);
-- but a join should be allowed:
EXPLAIN (COSTS OFF)
SELECT * FROM
(VALUES (0),(10),(100)) v(nrows),
LATERAL (SELECT count(*) FROM test_tablesample
TABLESAMPLE system_rows (nrows)) ss;
SELECT * FROM
(VALUES (0),(10),(100)) v(nrows),
LATERAL (SELECT count(*) FROM test_tablesample
TABLESAMPLE system_rows (nrows)) ss;
CREATE VIEW vv AS
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (20);
SELECT * FROM vv;
DROP EXTENSION tsm_system_rows; -- fail, view depends on extension
|