summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPallavi Sontakke2016-02-12 12:50:37 +0000
committerPavan Deolasee2016-10-18 09:58:27 +0000
commitedba6664b02512e2b72583232ea0301a9e110c77 (patch)
treee4f87d6f66e2a6341a1b3c8ca18174be9d06a9da
parenta86de3c017a84a1612cd9392125aa33a6d2cc948 (diff)
Test sql and output changes for LATERAL issue
Separate out Issue #73 in Issue Tracker. Accept XL query plans.
-rw-r--r--contrib/tsm_system_time/Makefile2
-rw-r--r--contrib/tsm_system_time/expected/tsm_system_time.out116
-rw-r--r--contrib/tsm_system_time/expected/xl_known_bugs.out33
-rw-r--r--contrib/tsm_system_time/sql/tsm_system_time.sql30
-rw-r--r--contrib/tsm_system_time/sql/xl_known_bugs.sql18
5 files changed, 152 insertions, 47 deletions
diff --git a/contrib/tsm_system_time/Makefile b/contrib/tsm_system_time/Makefile
index c42c1c6bb6..8e1648b122 100644
--- a/contrib/tsm_system_time/Makefile
+++ b/contrib/tsm_system_time/Makefile
@@ -7,7 +7,7 @@ PGFILEDESC = "tsm_system_time - SYSTEM TABLESAMPLE method which accepts number r
EXTENSION = tsm_system_time
DATA = tsm_system_time--1.0.sql
-REGRESS = tsm_system_time
+REGRESS = tsm_system_time xl_known_bugs
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/contrib/tsm_system_time/expected/tsm_system_time.out b/contrib/tsm_system_time/expected/tsm_system_time.out
index 32ad03c4bd..0ac019b558 100644
--- a/contrib/tsm_system_time/expected/tsm_system_time.out
+++ b/contrib/tsm_system_time/expected/tsm_system_time.out
@@ -8,47 +8,83 @@ SELECT count(*) FROM test_tablesample TABLESAMPLE system_time (1000);
31
(1 row)
-SELECT id FROM test_tablesample TABLESAMPLE system_time (1000) REPEATABLE (5432);
- id
-----
- 7
- 14
- 21
- 28
- 4
- 11
- 18
- 25
- 1
- 8
- 15
- 22
- 29
- 5
- 12
- 19
- 26
- 2
- 9
- 16
- 23
- 30
- 6
- 13
- 20
- 27
- 3
- 10
- 17
- 24
- 0
-(31 rows)
+-- bad parameters should get through planning, but not execution:
+EXPLAIN (COSTS OFF)
+SELECT id FROM test_tablesample TABLESAMPLE system_time (-1);
+ QUERY PLAN
+--------------------------------------------------------
+ Remote Fast Query Execution
+ Node/s: datanode_1, datanode_2
+ -> Sample Scan on test_tablesample
+ Sampling: system_time ('-1'::double precision)
+(4 rows)
-EXPLAIN SELECT id FROM test_tablesample TABLESAMPLE system_time (100) REPEATABLE (10);
+SELECT id FROM test_tablesample TABLESAMPLE system_time (-1);
+ERROR: sample collection time must not be negative
+-- fail, this method is not repeatable:
+SELECT * FROM test_tablesample TABLESAMPLE system_time (10) REPEATABLE (0);
+ERROR: tablesample method system_time does not support REPEATABLE
+LINE 1: SELECT * FROM test_tablesample TABLESAMPLE system_time (10) ...
+ ^
+-- since it's not repeatable, we expect a Materialize node in these plans:
+EXPLAIN (COSTS OFF)
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (100000)) ss;
QUERY PLAN
------------------------------------------------------------------------------------
- Sample Scan (system_time) on test_tablesample (cost=0.00..100.25 rows=25 width=4)
-(1 row)
+ Nested Loop
+ -> Aggregate
+ -> Remote Subquery Scan on all (datanode_1,datanode_2)
+ -> Aggregate
+ -> Materialize
+ -> Sample Scan on test_tablesample
+ Sampling: system_time ('100000'::double precision)
+ -> Values Scan on "*VALUES*"
+(8 rows)
+
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (100000)) ss;
+ time | count
+--------+-------
+ 0 | 31
+ 100000 | 31
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (time)) ss;
+ QUERY PLAN
+----------------------------------------------------------------------------
+ Nested Loop
+ -> Values Scan on "*VALUES*"
+ -> Aggregate
+ -> Remote Subquery Scan on all (datanode_1,datanode_2)
+ -> Aggregate
+ -> Materialize
+ -> Sample Scan on test_tablesample
+ Sampling: system_time ("*VALUES*".column1)
+(8 rows)
+
+CREATE VIEW vv AS
+ SELECT * FROM test_tablesample TABLESAMPLE system_time (20);
+EXPLAIN (COSTS OFF) SELECT * FROM vv;
+ QUERY PLAN
+--------------------------------------------------------
+ Remote Subquery Scan on all (datanode_1,datanode_2)
+ -> Sample Scan on test_tablesample
+ Sampling: system_time ('20'::double precision)
+(3 rows)
--- done
-DROP TABLE test_tablesample CASCADE;
+DROP EXTENSION tsm_system_time; -- fail, view depends on extension
+ERROR: cannot drop extension tsm_system_time because other objects depend on it
+DETAIL: view vv depends on function system_time(internal)
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
+DROP VIEW vv;
+DROP TABLE test_tablesample;
+DROP EXTENSION tsm_system_time;
diff --git a/contrib/tsm_system_time/expected/xl_known_bugs.out b/contrib/tsm_system_time/expected/xl_known_bugs.out
new file mode 100644
index 0000000000..69998b0dea
--- /dev/null
+++ b/contrib/tsm_system_time/expected/xl_known_bugs.out
@@ -0,0 +1,33 @@
+CREATE EXTENSION tsm_system_time;
+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);
+EXPLAIN (COSTS OFF)
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (time)) ss;
+ QUERY PLAN
+----------------------------------------------------------------------------
+ Nested Loop
+ -> Values Scan on "*VALUES*"
+ -> Aggregate
+ -> Remote Subquery Scan on all (datanode_1,datanode_2)
+ -> Aggregate
+ -> Materialize
+ -> Sample Scan on test_tablesample
+ Sampling: system_time ("*VALUES*".column1)
+(8 rows)
+
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (time)) ss;
+ time | count
+--------+-------
+ 0 | 0
+ 100000 | 31
+(2 rows)
+
+DROP TABLE test_tablesample;
+DROP EXTENSION tsm_system_time; -- fail, view depends on extension
diff --git a/contrib/tsm_system_time/sql/tsm_system_time.sql b/contrib/tsm_system_time/sql/tsm_system_time.sql
index 68dbbf98af..46cf391fee 100644
--- a/contrib/tsm_system_time/sql/tsm_system_time.sql
+++ b/contrib/tsm_system_time/sql/tsm_system_time.sql
@@ -2,13 +2,31 @@ CREATE EXTENSION tsm_system_time;
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
-INSERT INTO test_tablesample SELECT i, repeat(i::text, 1000) FROM generate_series(0, 30) s(i) ORDER BY i;
-ANALYZE test_tablesample;
+-- since it's not repeatable, we expect a Materialize node in these plans:
+EXPLAIN (COSTS OFF)
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (100000)) ss;
-SELECT count(*) FROM test_tablesample TABLESAMPLE system_time (1000);
-SELECT id FROM test_tablesample TABLESAMPLE system_time (1000) REPEATABLE (5432);
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (100000)) ss;
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (time)) ss;
+
+CREATE VIEW vv AS
+ SELECT * FROM test_tablesample TABLESAMPLE system_time (20);
EXPLAIN SELECT id FROM test_tablesample TABLESAMPLE system_time (100) REPEATABLE (10);
--- done
-DROP TABLE test_tablesample CASCADE;
+DROP EXTENSION tsm_system_time; -- fail, view depends on extension
+
+DROP VIEW vv;
+DROP TABLE test_tablesample;
+DROP EXTENSION tsm_system_time;
diff --git a/contrib/tsm_system_time/sql/xl_known_bugs.sql b/contrib/tsm_system_time/sql/xl_known_bugs.sql
new file mode 100644
index 0000000000..2778b70f32
--- /dev/null
+++ b/contrib/tsm_system_time/sql/xl_known_bugs.sql
@@ -0,0 +1,18 @@
+CREATE EXTENSION tsm_system_time;
+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);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (time)) ss;
+
+SELECT * FROM
+ (VALUES (0),(100000)) v(time),
+ LATERAL (SELECT COUNT(*) FROM test_tablesample
+ TABLESAMPLE system_time (time)) ss;
+
+DROP TABLE test_tablesample;
+DROP EXTENSION tsm_system_time; -- fail, view depends on extension