Skip to content

Commit e226ece

Browse files
authored
Merge pull request #43 from namnguyen1405/fix_issue_42
Fix 14beta1 build
2 parents a4e24fb + 84b9202 commit e226ece

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+52863
-15
lines changed

deparse.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,9 @@ sqlite_deparse_direct_update_sql(StringInfo buf, PlannerInfo *root,
20152015
deparse_expr_cxt context;
20162016
int nestlevel;
20172017
bool first;
2018-
ListCell *lc;
2018+
ListCell *lc;
2019+
ListCell *lc2;
2020+
20192021

20202022
/* Set up context struct for recursion */
20212023
context.root = root;
@@ -2034,10 +2036,18 @@ sqlite_deparse_direct_update_sql(StringInfo buf, PlannerInfo *root,
20342036
nestlevel = sqlite_set_transmission_modes();
20352037

20362038
first = true;
2037-
foreach(lc, targetAttrs)
2039+
forboth(lc, targetlist, lc2, targetAttrs)
20382040
{
2039-
int attnum = lfirst_int(lc);
2040-
TargetEntry *tle = get_tle_by_resno(targetlist, attnum);
2041+
int attnum = lfirst_int(lc2);
2042+
#if (PG_VERSION_NUM >= 140000)
2043+
TargetEntry *tle = lfirst_node(TargetEntry, lc);
2044+
2045+
/* update's new-value expressions shouldn't be resjunk */
2046+
Assert(!tle->resjunk);
2047+
#else
2048+
(void)lc;
2049+
TargetEntry *tle = get_tle_by_resno(targetlist, attnum);
2050+
#endif
20412051

20422052
if (!tle)
20432053
elog(ERROR, "attribute number %d not found in UPDATE targetlist",

expected/10.14/sqlite_fdw.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,31 @@ SELECT * FROM noprimary;
14351435
1 | 2
14361436
(2 rows)
14371437

1438+
--get version
1439+
--Testcase 153:
1440+
\df sqlite*
1441+
List of functions
1442+
Schema | Name | Result data type | Argument data types | Type
1443+
--------+----------------------+------------------+---------------------+--------
1444+
public | sqlite_fdw_handler | fdw_handler | | normal
1445+
public | sqlite_fdw_validator | void | text[], oid | normal
1446+
public | sqlite_fdw_version | integer | | normal
1447+
(3 rows)
1448+
1449+
--Testcase 154:
1450+
SELECT * FROM public.sqlite_fdw_version();
1451+
sqlite_fdw_version
1452+
--------------------
1453+
20000
1454+
(1 row)
1455+
1456+
--Testcase 155:
1457+
SELECT sqlite_fdw_version();
1458+
sqlite_fdw_version
1459+
--------------------
1460+
20000
1461+
(1 row)
1462+
14381463
--Testcase 142:
14391464
DROP FUNCTION test_param_WHERE();
14401465
--Testcase 143:

expected/11.9/sqlite_fdw.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,31 @@ SELECT * FROM noprimary;
14351435
1 | 2
14361436
(2 rows)
14371437

1438+
--get version
1439+
--Testcase 153:
1440+
\df sqlite*
1441+
List of functions
1442+
Schema | Name | Result data type | Argument data types | Type
1443+
--------+----------------------+------------------+---------------------+------
1444+
public | sqlite_fdw_handler | fdw_handler | | func
1445+
public | sqlite_fdw_validator | void | text[], oid | func
1446+
public | sqlite_fdw_version | integer | | func
1447+
(3 rows)
1448+
1449+
--Testcase 154:
1450+
SELECT * FROM public.sqlite_fdw_version();
1451+
sqlite_fdw_version
1452+
--------------------
1453+
20000
1454+
(1 row)
1455+
1456+
--Testcase 155:
1457+
SELECT sqlite_fdw_version();
1458+
sqlite_fdw_version
1459+
--------------------
1460+
20000
1461+
(1 row)
1462+
14381463
--Testcase 142:
14391464
DROP FUNCTION test_param_WHERE();
14401465
--Testcase 143:

expected/12.4/sqlite_fdw.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,31 @@ SELECT * FROM noprimary;
14351435
1 | 2
14361436
(2 rows)
14371437

1438+
--get version
1439+
--Testcase 153:
1440+
\df sqlite*
1441+
List of functions
1442+
Schema | Name | Result data type | Argument data types | Type
1443+
--------+----------------------+------------------+---------------------+------
1444+
public | sqlite_fdw_handler | fdw_handler | | func
1445+
public | sqlite_fdw_validator | void | text[], oid | func
1446+
public | sqlite_fdw_version | integer | | func
1447+
(3 rows)
1448+
1449+
--Testcase 154:
1450+
SELECT * FROM public.sqlite_fdw_version();
1451+
sqlite_fdw_version
1452+
--------------------
1453+
20000
1454+
(1 row)
1455+
1456+
--Testcase 155:
1457+
SELECT sqlite_fdw_version();
1458+
sqlite_fdw_version
1459+
--------------------
1460+
20000
1461+
(1 row)
1462+
14381463
--Testcase 142:
14391464
DROP FUNCTION test_param_WHERE();
14401465
--Testcase 143:

expected/13.0/sqlite_fdw.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,31 @@ SELECT * FROM noprimary;
14351435
1 | 2
14361436
(2 rows)
14371437

1438+
--get version
1439+
--Testcase 153:
1440+
\df sqlite*
1441+
List of functions
1442+
Schema | Name | Result data type | Argument data types | Type
1443+
--------+----------------------+------------------+---------------------+------
1444+
public | sqlite_fdw_handler | fdw_handler | | func
1445+
public | sqlite_fdw_validator | void | text[], oid | func
1446+
public | sqlite_fdw_version | integer | | func
1447+
(3 rows)
1448+
1449+
--Testcase 154:
1450+
SELECT * FROM public.sqlite_fdw_version();
1451+
sqlite_fdw_version
1452+
--------------------
1453+
20000
1454+
(1 row)
1455+
1456+
--Testcase 155:
1457+
SELECT sqlite_fdw_version();
1458+
sqlite_fdw_version
1459+
--------------------
1460+
20000
1461+
(1 row)
1462+
14381463
--Testcase 142:
14391464
DROP FUNCTION test_param_WHERE();
14401465
--Testcase 143:

expected/14beta1/aggregate.out

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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

Comments
 (0)