| 1 |
CREATE EXTENSION tsm_system_rows; |
| 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 |
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (0); |
| 7 |
count |
| 8 |
------- |
| 9 |
0 |
| 10 |
(1 row) |
| 11 |
|
| 12 |
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (1); |
| 13 |
count |
| 14 |
------- |
| 15 |
1 |
| 16 |
(1 row) |
| 17 |
|
| 18 |
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (10); |
| 19 |
count |
| 20 |
------- |
| 21 |
10 |
| 22 |
(1 row) |
| 23 |
|
| 24 |
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (100); |
| 25 |
count |
| 26 |
------- |
| 27 |
31 |
| 28 |
(1 row) |
| 29 |
|
| 30 |
-- bad parameters should get through planning, but not execution: |
| 31 |
EXPLAIN (COSTS OFF) |
| 32 |
SELECT id FROM test_tablesample TABLESAMPLE system_rows (-1); |
| 33 |
QUERY PLAN |
| 34 |
---------------------------------------- |
| 35 |
Sample Scan on test_tablesample |
| 36 |
Sampling: system_rows ('-1'::bigint) |
| 37 |
(2 rows) |
| 38 |
|
| 39 |
SELECT id FROM test_tablesample TABLESAMPLE system_rows (-1); |
| 40 |
ERROR: sample size must not be negative |
| 41 |
-- fail, this method is not repeatable: |
| 42 |
SELECT * FROM test_tablesample TABLESAMPLE system_rows (10) REPEATABLE (0); |
| 43 |
ERROR: tablesample method system_rows does not support REPEATABLE |
| 44 |
LINE 1: SELECT * FROM test_tablesample TABLESAMPLE system_rows (10) ... |
| 45 |
^ |
| 46 |
-- but a join should be allowed: |
| 47 |
EXPLAIN (COSTS OFF) |
| 48 |
SELECT * FROM |
| 49 |
(VALUES (0),(10),(100)) v(nrows), |
| 50 |
LATERAL (SELECT count(*) FROM test_tablesample |
| 51 |
TABLESAMPLE system_rows (nrows)) ss; |
| 52 |
QUERY PLAN |
| 53 |
---------------------------------------------------------- |
| 54 |
Nested Loop |
| 55 |
-> Values Scan on "*VALUES*" |
| 56 |
-> Aggregate |
| 57 |
-> Sample Scan on test_tablesample |
| 58 |
Sampling: system_rows ("*VALUES*".column1) |
| 59 |
(5 rows) |
| 60 |
|
| 61 |
SELECT * FROM |
| 62 |
(VALUES (0),(10),(100)) v(nrows), |
| 63 |
LATERAL (SELECT count(*) FROM test_tablesample |
| 64 |
TABLESAMPLE system_rows (nrows)) ss; |
| 65 |
nrows | count |
| 66 |
-------+------- |
| 67 |
0 | 0 |
| 68 |
10 | 10 |
| 69 |
100 | 31 |
| 70 |
(3 rows) |
| 71 |
|
| 72 |
CREATE VIEW vv AS |
| 73 |
SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (20); |
| 74 |
SELECT * FROM vv; |
| 75 |
count |
| 76 |
------- |
| 77 |
20 |
| 78 |
(1 row) |
| 79 |
|
| 80 |
DROP EXTENSION tsm_system_rows; -- fail, view depends on extension |
| 81 |
ERROR: cannot drop extension tsm_system_rows because other objects depend on it |
| 82 |
DETAIL: view vv depends on function system_rows(internal) |
| 83 |
HINT: Use DROP ... CASCADE to drop the dependent objects too. |