Skip to content

Commit 90a391c

Browse files
committed
Regression tests for new btree_gist "not equals" support.
Jeff Davis, with minor adjustments by me.
1 parent 3491520 commit 90a391c

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

contrib/btree_gist/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/contrib/btree_gist/Makefile,v 1.12 2007/11/10 23:59:50 momjian Exp $
1+
# $PostgreSQL: pgsql/contrib/btree_gist/Makefile,v 1.13 2010/08/03 19:53:19 rhaas Exp $
22

33
MODULE_big = btree_gist
44

@@ -11,7 +11,7 @@ DATA_built = btree_gist.sql
1111
DATA = uninstall_btree_gist.sql
1212

1313
REGRESS = init int2 int4 int8 float4 float8 cash oid timestamp timestamptz time timetz \
14-
date interval macaddr inet cidr text varchar char bytea bit varbit numeric
14+
date interval macaddr inet cidr text varchar char bytea bit varbit numeric not_equal
1515

1616
ifdef USE_PGXS
1717
PG_CONFIG = pg_config
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
SET enable_seqscan to false;
2+
-- test search for "not equals"
3+
CREATE TABLE test_ne (
4+
a TIMESTAMP,
5+
b NUMERIC
6+
);
7+
CREATE INDEX test_ne_idx ON test_ne USING gist (a, b);
8+
INSERT INTO test_ne SELECT '2009-01-01', 10.7 FROM generate_series(1,1000);
9+
INSERT INTO test_ne VALUES('2007-02-03', -91.3);
10+
INSERT INTO test_ne VALUES('2011-09-01', 43.7);
11+
INSERT INTO test_ne SELECT '2009-01-01', 10.7 FROM generate_series(1,1000);
12+
EXPLAIN (COSTS OFF) SELECT * FROM test_ne WHERE a <> '2009-01-01' AND b <> 10.7;
13+
QUERY PLAN
14+
------------------------------------------------------------------------------------------------------
15+
Bitmap Heap Scan on test_ne
16+
Recheck Cond: ((a <> 'Thu Jan 01 00:00:00 2009'::timestamp without time zone) AND (b <> 10.7))
17+
-> Bitmap Index Scan on test_ne_idx
18+
Index Cond: ((a <> 'Thu Jan 01 00:00:00 2009'::timestamp without time zone) AND (b <> 10.7))
19+
(4 rows)
20+
21+
SELECT * FROM test_ne WHERE a <> '2009-01-01' AND b <> 10.7;
22+
a | b
23+
--------------------------+-------
24+
Sat Feb 03 00:00:00 2007 | -91.3
25+
Thu Sep 01 00:00:00 2011 | 43.7
26+
(2 rows)
27+
28+
-- test search for "not equals" using an exclusion constraint
29+
CREATE TABLE zoo (
30+
cage INTEGER,
31+
animal TEXT,
32+
EXCLUDE USING gist (cage WITH =, animal WITH <>)
33+
);
34+
NOTICE: CREATE TABLE / EXCLUDE will create implicit index "zoo_cage_animal_excl" for table "zoo"
35+
INSERT INTO zoo VALUES(123, 'zebra');
36+
INSERT INTO zoo VALUES(123, 'zebra');
37+
INSERT INTO zoo VALUES(123, 'lion');
38+
ERROR: conflicting key value violates exclusion constraint "zoo_cage_animal_excl"
39+
DETAIL: Key (cage, animal)=(123, lion) conflicts with existing key (cage, animal)=(123, zebra).
40+
INSERT INTO zoo VALUES(124, 'lion');

contrib/btree_gist/sql/not_equal.sql

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
SET enable_seqscan to false;
3+
4+
-- test search for "not equals"
5+
6+
CREATE TABLE test_ne (
7+
a TIMESTAMP,
8+
b NUMERIC
9+
);
10+
CREATE INDEX test_ne_idx ON test_ne USING gist (a, b);
11+
12+
INSERT INTO test_ne SELECT '2009-01-01', 10.7 FROM generate_series(1,1000);
13+
INSERT INTO test_ne VALUES('2007-02-03', -91.3);
14+
INSERT INTO test_ne VALUES('2011-09-01', 43.7);
15+
INSERT INTO test_ne SELECT '2009-01-01', 10.7 FROM generate_series(1,1000);
16+
17+
EXPLAIN (COSTS OFF) SELECT * FROM test_ne WHERE a <> '2009-01-01' AND b <> 10.7;
18+
19+
SELECT * FROM test_ne WHERE a <> '2009-01-01' AND b <> 10.7;
20+
21+
-- test search for "not equals" using an exclusion constraint
22+
23+
CREATE TABLE zoo (
24+
cage INTEGER,
25+
animal TEXT,
26+
EXCLUDE USING gist (cage WITH =, animal WITH <>)
27+
);
28+
29+
INSERT INTO zoo VALUES(123, 'zebra');
30+
INSERT INTO zoo VALUES(123, 'zebra');
31+
INSERT INTO zoo VALUES(123, 'lion');
32+
INSERT INTO zoo VALUES(124, 'lion');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy