|
| 1 | +--SET log_min_messages TO DEBUG1; |
| 2 | +--SET client_min_messages TO DEBUG1; |
| 3 | +--Testcase 16: |
| 4 | +CREATE EXTENSION sqlite_fdw; |
| 5 | +--Testcase 17: |
| 6 | +CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw |
| 7 | +OPTIONS (database '/tmp/sqlitefdw_test.db'); |
| 8 | +--Testcase 18: |
| 9 | +CREATE FOREIGN TABLE multiprimary(a int, b int OPTIONS (key 'true'), c int OPTIONS(key 'true')) SERVER sqlite_svr; |
| 10 | +-- test for aggregate pushdown |
| 11 | +--Testcase 8: |
| 12 | +DROP SERVER IF EXISTS sqlite_svr CASCADE; |
| 13 | +NOTICE: drop cascades to foreign table multiprimary |
| 14 | +--Testcase 9: |
| 15 | +DROP EXTENSION IF EXISTS sqlite_fdw CASCADE; |
| 16 | +--Testcase 10: |
| 17 | +CREATE EXTENSION sqlite_fdw; |
| 18 | +--Testcase 11: |
| 19 | +CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw |
| 20 | +OPTIONS (database '/tmp/sqlitefdw_test.db'); |
| 21 | +--Testcase 12: |
| 22 | +CREATE FOREIGN TABLE multiprimary(a int, b int OPTIONS (key 'true'), c int OPTIONS(key 'true')) SERVER sqlite_svr; |
| 23 | +--Testcase 1: |
| 24 | +explain (costs off, verbose) select count(distinct a) from multiprimary; |
| 25 | + QUERY PLAN |
| 26 | +--------------------------------------------------------------------- |
| 27 | + Foreign Scan |
| 28 | + Output: (count(DISTINCT a)) |
| 29 | + SQLite query: SELECT count(DISTINCT `a`) FROM main."multiprimary" |
| 30 | +(3 rows) |
| 31 | + |
| 32 | +--Testcase 2: |
| 33 | +explain (costs off, verbose) select sum(b),max(b), min(b), avg(b) from multiprimary; |
| 34 | + QUERY PLAN |
| 35 | +---------------------------------------------------------------------------------------- |
| 36 | + Foreign Scan |
| 37 | + Output: (sum(b)), (max(b)), (min(b)), (avg(b)) |
| 38 | + SQLite query: SELECT sum(`b`), max(`b`), min(`b`), avg(`b`) FROM main."multiprimary" |
| 39 | +(3 rows) |
| 40 | + |
| 41 | +--Testcase 3: |
| 42 | +explain (costs off, verbose) select sum(b+5)+2 from multiprimary group by b/2 order by b/2; |
| 43 | + QUERY PLAN |
| 44 | +------------------------------------------------------------------------------------------------------------------------------ |
| 45 | + Foreign Scan |
| 46 | + Output: ((sum((b + 5)) + 2)), ((b / 2)) |
| 47 | + SQLite query: SELECT (sum((`b` + 5)) + 2), (`b` / 2) FROM main."multiprimary" GROUP BY 2 ORDER BY (`b` / 2) ASC NULLS LAST |
| 48 | +(3 rows) |
| 49 | + |
| 50 | +--Testcase 4: |
| 51 | +explain (costs off, verbose) select sum(a) from multiprimary group by b having sum(a) > 0; |
| 52 | + QUERY PLAN |
| 53 | +-------------------------------------------------------------------------------------------------- |
| 54 | + Foreign Scan |
| 55 | + Output: (sum(a)), b |
| 56 | + SQLite query: SELECT sum(`a`), `b` FROM main."multiprimary" GROUP BY 2 HAVING ((sum(`a`) > 0)) |
| 57 | +(3 rows) |
| 58 | + |
| 59 | +--Testcase 5: |
| 60 | +explain (costs off, verbose) select sum(a) from multiprimary group by b having avg(a^2) > 0 and sum(a) > 0; |
| 61 | + QUERY PLAN |
| 62 | +--------------------------------------------------------------------------------------------------------------------------------------- |
| 63 | + GroupAggregate |
| 64 | + Output: sum(a), b |
| 65 | + Group Key: multiprimary.b |
| 66 | + Filter: ((avg(((multiprimary.a)::double precision ^ '2'::double precision)) > '0'::double precision) AND (sum(multiprimary.a) > 0)) |
| 67 | + -> Foreign Scan on public.multiprimary |
| 68 | + Output: a, b, c |
| 69 | + SQLite query: SELECT `a`, `b` FROM main."multiprimary" ORDER BY `b` ASC NULLS LAST |
| 70 | +(7 rows) |
| 71 | + |
| 72 | +-- stddev and variance are not pushed down |
| 73 | +--Testcase 6: |
| 74 | +explain (costs off, verbose) select stddev(a) from multiprimary; |
| 75 | + QUERY PLAN |
| 76 | +----------------------------------------------------------- |
| 77 | + Aggregate |
| 78 | + Output: stddev(a) |
| 79 | + -> Foreign Scan on public.multiprimary |
| 80 | + Output: a, b, c |
| 81 | + SQLite query: SELECT `a` FROM main."multiprimary" |
| 82 | +(5 rows) |
| 83 | + |
| 84 | +--Testcase 7: |
| 85 | +explain (costs off, verbose) select sum(a) from multiprimary group by b having variance(a) > 0; |
| 86 | + QUERY PLAN |
| 87 | +-------------------------------------------------------------------------------------------- |
| 88 | + GroupAggregate |
| 89 | + Output: sum(a), b |
| 90 | + Group Key: multiprimary.b |
| 91 | + Filter: (variance(multiprimary.a) > '0'::numeric) |
| 92 | + -> Foreign Scan on public.multiprimary |
| 93 | + Output: a, b, c |
| 94 | + SQLite query: SELECT `a`, `b` FROM main."multiprimary" ORDER BY `b` ASC NULLS LAST |
| 95 | +(7 rows) |
| 96 | + |
| 97 | +--Testcase 13: |
| 98 | +DROP FOREIGN TABLE multiprimary; |
| 99 | +--Testcase 16: |
| 100 | +CREATE FOREIGN TABLE limittest(id serial OPTIONS (key 'true'), x int, y text) SERVER sqlite_svr; |
| 101 | +--Testcase 17: |
| 102 | +INSERT INTO limittest(x, y) VALUES (1, 'x'), (2, 'x'), (3, 'x'), (4, 'x'); |
| 103 | +--Testcase 18: |
| 104 | +INSERT INTO limittest(x, y) VALUES (1, 'y'), (2, 'y'), (3, 'y'), (4, 'y'); |
| 105 | +--Testcase 19: |
| 106 | +INSERT INTO limittest(x, y) VALUES (1, 'z'), (2, 'z'), (3, 'z'), (4, 'z'); |
| 107 | +--Testcase 20: |
| 108 | +EXPLAIN VERBOSE |
| 109 | +SELECT avg(x) FROM limittest GROUP BY y ORDER BY 1 DESC FETCH FIRST 2 ROWS WITH TIES; |
| 110 | + QUERY PLAN |
| 111 | +---------------------------------------------------------------------------------------------------------------- |
| 112 | + Limit (cost=1.00..1.00 rows=1 width=64) |
| 113 | + Output: (avg(x)), y |
| 114 | + -> Foreign Scan (cost=1.00..1.00 rows=1 width=64) |
| 115 | + Output: (avg(x)), y |
| 116 | + SQLite query: SELECT avg(`x`), `y` FROM main."limittest" GROUP BY 2 ORDER BY avg(`x`) DESC NULLS FIRST |
| 117 | +(5 rows) |
| 118 | + |
| 119 | +--Testcase 21: |
| 120 | +SELECT avg(x) FROM limittest GROUP BY y ORDER BY 1 DESC FETCH FIRST 2 ROWS WITH TIES; |
| 121 | + avg |
| 122 | +----- |
| 123 | + 2.5 |
| 124 | + 2.5 |
| 125 | + 2.5 |
| 126 | +(3 rows) |
| 127 | + |
| 128 | +--Testcase 22: |
| 129 | +EXPLAIN VERBOSE |
| 130 | +SELECT avg(x) FROM limittest WHERE x >= 0 GROUP BY y ORDER BY 1 DESC FETCH FIRST 2 ROWS WITH TIES; |
| 131 | + QUERY PLAN |
| 132 | +----------------------------------------------------------------------------------------------------------------------------------- |
| 133 | + Limit (cost=1.00..1.00 rows=1 width=64) |
| 134 | + Output: (avg(x)), y |
| 135 | + -> Foreign Scan (cost=1.00..1.00 rows=1 width=64) |
| 136 | + Output: (avg(x)), y |
| 137 | + SQLite query: SELECT avg(`x`), `y` FROM main."limittest" WHERE ((`x` >= 0)) GROUP BY 2 ORDER BY avg(`x`) DESC NULLS FIRST |
| 138 | +(5 rows) |
| 139 | + |
| 140 | +--Testcase 23: |
| 141 | +SELECT avg(x) FROM limittest WHERE x >= 0 GROUP BY y ORDER BY 1 DESC FETCH FIRST 2 ROWS WITH TIES; |
| 142 | + avg |
| 143 | +----- |
| 144 | + 2.5 |
| 145 | + 2.5 |
| 146 | + 2.5 |
| 147 | +(3 rows) |
| 148 | + |
| 149 | +--Testcase 24: |
| 150 | +EXPLAIN VERBOSE |
| 151 | +SELECT x FROM limittest WHERE x > 0 ORDER BY 1 FETCH FIRST 2 ROWS WITH TIES; |
| 152 | + QUERY PLAN |
| 153 | +------------------------------------------------------------------------------------------------------ |
| 154 | + Limit (cost=10.00..10.00 rows=2 width=4) |
| 155 | + Output: x |
| 156 | + -> Foreign Scan on public.limittest (cost=10.00..10.00 rows=10 width=4) |
| 157 | + Output: x |
| 158 | + SQLite query: SELECT `x` FROM main."limittest" WHERE ((`x` > 0)) ORDER BY `x` ASC NULLS LAST |
| 159 | +(5 rows) |
| 160 | + |
| 161 | +--Testcase 25: |
| 162 | +SELECT x FROM limittest WHERE x > 0 ORDER BY 1 FETCH FIRST 2 ROWS WITH TIES; |
| 163 | + x |
| 164 | +--- |
| 165 | + 1 |
| 166 | + 1 |
| 167 | + 1 |
| 168 | +(3 rows) |
| 169 | + |
| 170 | +--Testcase 26: |
| 171 | +EXPLAIN VERBOSE |
| 172 | +SELECT x FROM limittest ORDER BY 1 FETCH FIRST 2 ROWS ONLY; |
| 173 | + QUERY PLAN |
| 174 | +-------------------------------------------------------------------------------------- |
| 175 | + Foreign Scan on public.limittest (cost=1.00..1.00 rows=1 width=4) |
| 176 | + Output: x |
| 177 | + SQLite query: SELECT `x` FROM main."limittest" ORDER BY `x` ASC NULLS LAST LIMIT 2 |
| 178 | +(3 rows) |
| 179 | + |
| 180 | +--Testcase 27: |
| 181 | +SELECT x FROM limittest ORDER BY 1 FETCH FIRST 2 ROWS ONLY; |
| 182 | + x |
| 183 | +--- |
| 184 | + 1 |
| 185 | + 1 |
| 186 | +(2 rows) |
| 187 | + |
| 188 | +--Testcase 28: |
| 189 | +DROP FOREIGN TABLE limittest; |
| 190 | +--Testcase 14: |
| 191 | +DROP SERVER sqlite_svr; |
| 192 | +--Testcase 15: |
| 193 | +DROP EXTENSION sqlite_fdw CASCADE; |
0 commit comments