Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3c8de95

Browse files
committed
Add regression tests exercising more code paths in nodeLimit.c.
Perusal of the code coverage report shows that the existing regression test cases for LIMIT/OFFSET don't exercise the nodeLimit code paths involving backwards scan, empty results, or null values of LIMIT/OFFSET. Improve the coverage.
1 parent 6efca23 commit 3c8de95

File tree

2 files changed

+221
-0
lines changed

2 files changed

+221
-0
lines changed

src/test/regress/expected/limit.out

+179
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,185 @@ SELECT ''::text AS five, unique1, unique2, stringu1
108108
| 904 | 793 | UIAAAA
109109
(5 rows)
110110

111+
-- Test null limit and offset. The planner would discard a simple null
112+
-- constant, so to ensure executor is exercised, do this:
113+
select * from int8_tbl limit (case when random() < 0.5 then null::bigint end);
114+
q1 | q2
115+
------------------+-------------------
116+
123 | 456
117+
123 | 4567890123456789
118+
4567890123456789 | 123
119+
4567890123456789 | 4567890123456789
120+
4567890123456789 | -4567890123456789
121+
(5 rows)
122+
123+
select * from int8_tbl offset (case when random() < 0.5 then null::bigint end);
124+
q1 | q2
125+
------------------+-------------------
126+
123 | 456
127+
123 | 4567890123456789
128+
4567890123456789 | 123
129+
4567890123456789 | 4567890123456789
130+
4567890123456789 | -4567890123456789
131+
(5 rows)
132+
133+
-- Test assorted cases involving backwards fetch from a LIMIT plan node
134+
begin;
135+
declare c1 cursor for select * from int8_tbl limit 10;
136+
fetch all in c1;
137+
q1 | q2
138+
------------------+-------------------
139+
123 | 456
140+
123 | 4567890123456789
141+
4567890123456789 | 123
142+
4567890123456789 | 4567890123456789
143+
4567890123456789 | -4567890123456789
144+
(5 rows)
145+
146+
fetch 1 in c1;
147+
q1 | q2
148+
----+----
149+
(0 rows)
150+
151+
fetch backward 1 in c1;
152+
q1 | q2
153+
------------------+-------------------
154+
4567890123456789 | -4567890123456789
155+
(1 row)
156+
157+
fetch backward all in c1;
158+
q1 | q2
159+
------------------+------------------
160+
4567890123456789 | 4567890123456789
161+
4567890123456789 | 123
162+
123 | 4567890123456789
163+
123 | 456
164+
(4 rows)
165+
166+
fetch backward 1 in c1;
167+
q1 | q2
168+
----+----
169+
(0 rows)
170+
171+
fetch all in c1;
172+
q1 | q2
173+
------------------+-------------------
174+
123 | 456
175+
123 | 4567890123456789
176+
4567890123456789 | 123
177+
4567890123456789 | 4567890123456789
178+
4567890123456789 | -4567890123456789
179+
(5 rows)
180+
181+
declare c2 cursor for select * from int8_tbl limit 3;
182+
fetch all in c2;
183+
q1 | q2
184+
------------------+------------------
185+
123 | 456
186+
123 | 4567890123456789
187+
4567890123456789 | 123
188+
(3 rows)
189+
190+
fetch 1 in c2;
191+
q1 | q2
192+
----+----
193+
(0 rows)
194+
195+
fetch backward 1 in c2;
196+
q1 | q2
197+
------------------+-----
198+
4567890123456789 | 123
199+
(1 row)
200+
201+
fetch backward all in c2;
202+
q1 | q2
203+
-----+------------------
204+
123 | 4567890123456789
205+
123 | 456
206+
(2 rows)
207+
208+
fetch backward 1 in c2;
209+
q1 | q2
210+
----+----
211+
(0 rows)
212+
213+
fetch all in c2;
214+
q1 | q2
215+
------------------+------------------
216+
123 | 456
217+
123 | 4567890123456789
218+
4567890123456789 | 123
219+
(3 rows)
220+
221+
declare c3 cursor for select * from int8_tbl offset 3;
222+
fetch all in c3;
223+
q1 | q2
224+
------------------+-------------------
225+
4567890123456789 | 4567890123456789
226+
4567890123456789 | -4567890123456789
227+
(2 rows)
228+
229+
fetch 1 in c3;
230+
q1 | q2
231+
----+----
232+
(0 rows)
233+
234+
fetch backward 1 in c3;
235+
q1 | q2
236+
------------------+-------------------
237+
4567890123456789 | -4567890123456789
238+
(1 row)
239+
240+
fetch backward all in c3;
241+
q1 | q2
242+
------------------+------------------
243+
4567890123456789 | 4567890123456789
244+
(1 row)
245+
246+
fetch backward 1 in c3;
247+
q1 | q2
248+
----+----
249+
(0 rows)
250+
251+
fetch all in c3;
252+
q1 | q2
253+
------------------+-------------------
254+
4567890123456789 | 4567890123456789
255+
4567890123456789 | -4567890123456789
256+
(2 rows)
257+
258+
declare c4 cursor for select * from int8_tbl offset 10;
259+
fetch all in c4;
260+
q1 | q2
261+
----+----
262+
(0 rows)
263+
264+
fetch 1 in c4;
265+
q1 | q2
266+
----+----
267+
(0 rows)
268+
269+
fetch backward 1 in c4;
270+
q1 | q2
271+
----+----
272+
(0 rows)
273+
274+
fetch backward all in c4;
275+
q1 | q2
276+
----+----
277+
(0 rows)
278+
279+
fetch backward 1 in c4;
280+
q1 | q2
281+
----+----
282+
(0 rows)
283+
284+
fetch all in c4;
285+
q1 | q2
286+
----+----
287+
(0 rows)
288+
289+
rollback;
111290
-- Stress test for variable LIMIT in conjunction with bounded-heap sorting
112291
SELECT
113292
(SELECT n

src/test/regress/sql/limit.sql

+42
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,48 @@ SELECT ''::text AS five, unique1, unique2, stringu1
3131
FROM onek
3232
ORDER BY unique1 LIMIT 5 OFFSET 900;
3333

34+
-- Test null limit and offset. The planner would discard a simple null
35+
-- constant, so to ensure executor is exercised, do this:
36+
select * from int8_tbl limit (case when random() < 0.5 then null::bigint end);
37+
select * from int8_tbl offset (case when random() < 0.5 then null::bigint end);
38+
39+
-- Test assorted cases involving backwards fetch from a LIMIT plan node
40+
begin;
41+
42+
declare c1 cursor for select * from int8_tbl limit 10;
43+
fetch all in c1;
44+
fetch 1 in c1;
45+
fetch backward 1 in c1;
46+
fetch backward all in c1;
47+
fetch backward 1 in c1;
48+
fetch all in c1;
49+
50+
declare c2 cursor for select * from int8_tbl limit 3;
51+
fetch all in c2;
52+
fetch 1 in c2;
53+
fetch backward 1 in c2;
54+
fetch backward all in c2;
55+
fetch backward 1 in c2;
56+
fetch all in c2;
57+
58+
declare c3 cursor for select * from int8_tbl offset 3;
59+
fetch all in c3;
60+
fetch 1 in c3;
61+
fetch backward 1 in c3;
62+
fetch backward all in c3;
63+
fetch backward 1 in c3;
64+
fetch all in c3;
65+
66+
declare c4 cursor for select * from int8_tbl offset 10;
67+
fetch all in c4;
68+
fetch 1 in c4;
69+
fetch backward 1 in c4;
70+
fetch backward all in c4;
71+
fetch backward 1 in c4;
72+
fetch all in c4;
73+
74+
rollback;
75+
3476
-- Stress test for variable LIMIT in conjunction with bounded-heap sorting
3577

3678
SELECT

0 commit comments

Comments
 (0)