1 -- tests for tidrangescans
2 SET enable_seqscan TO off;
3 CREATE TABLE tidrangescan(id integer, data text);
6 SELECT ctid FROM tidrangescan WHERE ctid < '(1, 0)';
8 -----------------------------------
9 Tid Range Scan on tidrangescan
10 TID Cond: (ctid < '(1,0)'::tid)
13 SELECT ctid FROM tidrangescan WHERE ctid < '(1, 0)';
19 SELECT ctid FROM tidrangescan WHERE ctid > '(9, 0)';
21 -----------------------------------
22 Tid Range Scan on tidrangescan
23 TID Cond: (ctid > '(9,0)'::tid)
26 SELECT ctid FROM tidrangescan WHERE ctid > '(9, 0)';
31 -- insert enough tuples to fill at least two pages
32 INSERT INTO tidrangescan SELECT i,repeat('x', 100) FROM generate_series(1,200) AS s(i);
33 -- remove all tuples after the 10th tuple on each page. Trying to ensure
34 -- we get the same layout with all CPU architectures and smaller than standard
36 DELETE FROM tidrangescan
37 WHERE substring(ctid::text FROM ',(\d+)\)')::integer > 10 OR substring(ctid::text FROM '\((\d+),')::integer > 2;
39 -- range scans with upper bound
41 SELECT ctid FROM tidrangescan WHERE ctid < '(1,0)';
43 -----------------------------------
44 Tid Range Scan on tidrangescan
45 TID Cond: (ctid < '(1,0)'::tid)
48 SELECT ctid FROM tidrangescan WHERE ctid < '(1,0)';
64 SELECT ctid FROM tidrangescan WHERE ctid <= '(1,5)';
66 ------------------------------------
67 Tid Range Scan on tidrangescan
68 TID Cond: (ctid <= '(1,5)'::tid)
71 SELECT ctid FROM tidrangescan WHERE ctid <= '(1,5)';
92 SELECT ctid FROM tidrangescan WHERE ctid < '(0,0)';
94 -----------------------------------
95 Tid Range Scan on tidrangescan
96 TID Cond: (ctid < '(0,0)'::tid)
99 SELECT ctid FROM tidrangescan WHERE ctid < '(0,0)';
104 -- range scans with lower bound
106 SELECT ctid FROM tidrangescan WHERE ctid > '(2,8)';
108 -----------------------------------
109 Tid Range Scan on tidrangescan
110 TID Cond: (ctid > '(2,8)'::tid)
113 SELECT ctid FROM tidrangescan WHERE ctid > '(2,8)';
121 SELECT ctid FROM tidrangescan WHERE '(2,8)' < ctid;
123 -----------------------------------
124 Tid Range Scan on tidrangescan
125 TID Cond: ('(2,8)'::tid < ctid)
128 SELECT ctid FROM tidrangescan WHERE '(2,8)' < ctid;
136 SELECT ctid FROM tidrangescan WHERE ctid >= '(2,8)';
138 ------------------------------------
139 Tid Range Scan on tidrangescan
140 TID Cond: (ctid >= '(2,8)'::tid)
143 SELECT ctid FROM tidrangescan WHERE ctid >= '(2,8)';
152 SELECT ctid FROM tidrangescan WHERE ctid >= '(100,0)';
154 --------------------------------------
155 Tid Range Scan on tidrangescan
156 TID Cond: (ctid >= '(100,0)'::tid)
159 SELECT ctid FROM tidrangescan WHERE ctid >= '(100,0)';
164 -- range scans with both bounds
166 SELECT ctid FROM tidrangescan WHERE ctid > '(1,4)' AND '(1,7)' >= ctid;
168 ----------------------------------------------------------------
169 Tid Range Scan on tidrangescan
170 TID Cond: ((ctid > '(1,4)'::tid) AND ('(1,7)'::tid >= ctid))
173 SELECT ctid FROM tidrangescan WHERE ctid > '(1,4)' AND '(1,7)' >= ctid;
182 SELECT ctid FROM tidrangescan WHERE '(1,7)' >= ctid AND ctid > '(1,4)';
184 ----------------------------------------------------------------
185 Tid Range Scan on tidrangescan
186 TID Cond: (('(1,7)'::tid >= ctid) AND (ctid > '(1,4)'::tid))
189 SELECT ctid FROM tidrangescan WHERE '(1,7)' >= ctid AND ctid > '(1,4)';
198 SELECT ctid FROM tidrangescan WHERE ctid > '(0,65535)' AND ctid < '(1,0)' LIMIT 1;
203 SELECT ctid FROM tidrangescan WHERE ctid < '(0,0)' LIMIT 1;
208 SELECT ctid FROM tidrangescan WHERE ctid > '(4294967295,65535)';
213 SELECT ctid FROM tidrangescan WHERE ctid < '(0,0)';
218 -- NULLs in the range cannot return tuples
219 SELECT ctid FROM tidrangescan WHERE ctid >= (SELECT NULL::tid);
226 SELECT t.ctid,t2.c FROM tidrangescan t,
227 LATERAL (SELECT count(*) c FROM tidrangescan t2 WHERE t2.ctid <= t.ctid) t2
228 WHERE t.ctid < '(1,0)';
230 -----------------------------------------------
232 -> Tid Range Scan on tidrangescan t
233 TID Cond: (ctid < '(1,0)'::tid)
235 -> Tid Range Scan on tidrangescan t2
236 TID Cond: (ctid <= t.ctid)
239 SELECT t.ctid,t2.c FROM tidrangescan t,
240 LATERAL (SELECT count(*) c FROM tidrangescan t2 WHERE t2.ctid <= t.ctid) t2
241 WHERE t.ctid < '(1,0)';
257 -- Ensure we get a TID Range scan without a Materialize node.
259 DECLARE c SCROLL CURSOR FOR SELECT ctid FROM tidrangescan WHERE ctid < '(1,0)';
261 -----------------------------------
262 Tid Range Scan on tidrangescan
263 TID Cond: (ctid < '(1,0)'::tid)
267 DECLARE c SCROLL CURSOR FOR SELECT ctid FROM tidrangescan WHERE ctid < '(1,0)';
299 DROP TABLE tidrangescan;
300 RESET enable_seqscan;