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

Commit b801e12

Browse files
committed
Improve regression test coverage for hash indexes.
On my system, this improves coverage for src/backend/access/hash from 61.3% of lines to 88.2% of lines, and from 83.5% of functions to 97.5% of functions, which is pretty good for 36 lines of tests. Mithun Cy, reviewing by Amit Kapila and Álvaro Herrera
1 parent 90d3da1 commit b801e12

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

src/test/regress/expected/hash_index.out

+36
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,39 @@ SELECT h.seqno AS f20000
196196
-- WHERE x = 90;
197197
-- SELECT count(*) AS i988 FROM hash_ovfl_heap
198198
-- WHERE x = 1000;
199+
--
200+
-- Cause some overflow insert and splits.
201+
--
202+
CREATE TABLE hash_split_heap (keycol INT);
203+
CREATE INDEX hash_split_index on hash_split_heap USING HASH (keycol);
204+
WARNING: hash indexes are not WAL-logged and their use is discouraged
205+
INSERT INTO hash_split_heap SELECT 1 FROM generate_series(1, 70000) a;
206+
VACUUM FULL hash_split_heap;
207+
-- Let's do a backward scan.
208+
BEGIN;
209+
SET enable_seqscan = OFF;
210+
SET enable_bitmapscan = OFF;
211+
DECLARE c CURSOR FOR SELECT * from hash_split_heap WHERE keycol = 1;
212+
MOVE FORWARD ALL FROM c;
213+
MOVE BACKWARD 10000 FROM c;
214+
MOVE BACKWARD ALL FROM c;
215+
CLOSE c;
216+
END;
217+
-- DELETE, INSERT, REBUILD INDEX.
218+
DELETE FROM hash_split_heap WHERE keycol = 1;
219+
INSERT INTO hash_split_heap SELECT a/2 FROM generate_series(1, 50000) a;
220+
VACUUM hash_split_heap;
221+
REINDEX INDEX hash_split_index;
222+
-- Clean up.
223+
DROP TABLE hash_split_heap;
224+
-- Index on temp table.
225+
CREATE TEMP TABLE hash_temp_heap (x int, y int);
226+
INSERT INTO hash_temp_heap VALUES (1,1);
227+
CREATE INDEX hash_idx ON hash_temp_heap USING hash (x);
228+
DROP TABLE hash_temp_heap CASCADE;
229+
-- Float4 type.
230+
CREATE TABLE hash_heap_float4 (x float4, y int);
231+
INSERT INTO hash_heap_float4 VALUES (1.1,1);
232+
CREATE INDEX hash_idx ON hash_heap_float4 USING hash (x);
233+
WARNING: hash indexes are not WAL-logged and their use is discouraged
234+
DROP TABLE hash_heap_float4 CASCADE;

src/test/regress/sql/hash_index.sql

+43
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,46 @@ SELECT h.seqno AS f20000
151151

152152
-- SELECT count(*) AS i988 FROM hash_ovfl_heap
153153
-- WHERE x = 1000;
154+
155+
--
156+
-- Cause some overflow insert and splits.
157+
--
158+
CREATE TABLE hash_split_heap (keycol INT);
159+
CREATE INDEX hash_split_index on hash_split_heap USING HASH (keycol);
160+
INSERT INTO hash_split_heap SELECT 1 FROM generate_series(1, 70000) a;
161+
162+
VACUUM FULL hash_split_heap;
163+
164+
-- Let's do a backward scan.
165+
BEGIN;
166+
SET enable_seqscan = OFF;
167+
SET enable_bitmapscan = OFF;
168+
169+
DECLARE c CURSOR FOR SELECT * from hash_split_heap WHERE keycol = 1;
170+
MOVE FORWARD ALL FROM c;
171+
MOVE BACKWARD 10000 FROM c;
172+
MOVE BACKWARD ALL FROM c;
173+
CLOSE c;
174+
END;
175+
176+
-- DELETE, INSERT, REBUILD INDEX.
177+
DELETE FROM hash_split_heap WHERE keycol = 1;
178+
INSERT INTO hash_split_heap SELECT a/2 FROM generate_series(1, 50000) a;
179+
180+
VACUUM hash_split_heap;
181+
REINDEX INDEX hash_split_index;
182+
183+
-- Clean up.
184+
DROP TABLE hash_split_heap;
185+
186+
-- Index on temp table.
187+
CREATE TEMP TABLE hash_temp_heap (x int, y int);
188+
INSERT INTO hash_temp_heap VALUES (1,1);
189+
CREATE INDEX hash_idx ON hash_temp_heap USING hash (x);
190+
DROP TABLE hash_temp_heap CASCADE;
191+
192+
-- Float4 type.
193+
CREATE TABLE hash_heap_float4 (x float4, y int);
194+
INSERT INTO hash_heap_float4 VALUES (1.1,1);
195+
CREATE INDEX hash_idx ON hash_heap_float4 USING hash (x);
196+
DROP TABLE hash_heap_float4 CASCADE;

0 commit comments

Comments
 (0)