2000-01-05 18:31:08 +01:00
|
|
|
--
|
|
|
|
-- CREATE_INDEX
|
|
|
|
-- Create ancillary data structures (i.e. indices)
|
|
|
|
--
|
|
|
|
--
|
|
|
|
-- BTREE
|
|
|
|
--
|
|
|
|
CREATE INDEX onek_unique1 ON onek USING btree(unique1 int4_ops);
|
|
|
|
CREATE INDEX onek_unique2 ON onek USING btree(unique2 int4_ops);
|
|
|
|
CREATE INDEX onek_hundred ON onek USING btree(hundred int4_ops);
|
|
|
|
CREATE INDEX onek_stringu1 ON onek USING btree(stringu1 name_ops);
|
|
|
|
CREATE INDEX tenk1_unique1 ON tenk1 USING btree(unique1 int4_ops);
|
|
|
|
CREATE INDEX tenk1_unique2 ON tenk1 USING btree(unique2 int4_ops);
|
|
|
|
CREATE INDEX tenk1_hundred ON tenk1 USING btree(hundred int4_ops);
|
2005-04-12 01:06:57 +02:00
|
|
|
CREATE INDEX tenk1_thous_tenthous ON tenk1 (thousand, tenthous);
|
2000-01-05 18:31:08 +01:00
|
|
|
CREATE INDEX tenk2_unique1 ON tenk2 USING btree(unique1 int4_ops);
|
|
|
|
CREATE INDEX tenk2_unique2 ON tenk2 USING btree(unique2 int4_ops);
|
|
|
|
CREATE INDEX tenk2_hundred ON tenk2 USING btree(hundred int4_ops);
|
|
|
|
CREATE INDEX rix ON road USING btree (name text_ops);
|
|
|
|
CREATE INDEX iix ON ihighway USING btree (name text_ops);
|
|
|
|
CREATE INDEX six ON shighway USING btree (name text_ops);
|
2003-11-21 23:32:49 +01:00
|
|
|
-- test comments
|
|
|
|
COMMENT ON INDEX six_wrong IS 'bad index';
|
|
|
|
ERROR: relation "six_wrong" does not exist
|
|
|
|
COMMENT ON INDEX six IS 'good index';
|
|
|
|
COMMENT ON INDEX six IS NULL;
|
2000-01-05 18:31:08 +01:00
|
|
|
--
|
|
|
|
-- BTREE ascending/descending cases
|
|
|
|
--
|
|
|
|
-- we load int4/text from pure descending data (each key is a new
|
|
|
|
-- low key) and name/f8 from pure ascending data (each key is a new
|
|
|
|
-- high key). we had a bug where new low keys would sometimes be
|
|
|
|
-- "lost".
|
|
|
|
--
|
|
|
|
CREATE INDEX bt_i4_index ON bt_i4_heap USING btree (seqno int4_ops);
|
|
|
|
CREATE INDEX bt_name_index ON bt_name_heap USING btree (seqno name_ops);
|
|
|
|
CREATE INDEX bt_txt_index ON bt_txt_heap USING btree (seqno text_ops);
|
|
|
|
CREATE INDEX bt_f8_index ON bt_f8_heap USING btree (seqno float8_ops);
|
|
|
|
--
|
|
|
|
-- BTREE partial indices
|
2001-07-16 07:07:00 +02:00
|
|
|
--
|
|
|
|
CREATE INDEX onek2_u1_prtl ON onek2 USING btree(unique1 int4_ops)
|
|
|
|
where unique1 < 20 or unique1 > 980;
|
|
|
|
CREATE INDEX onek2_u2_prtl ON onek2 USING btree(unique2 int4_ops)
|
|
|
|
where stringu1 < 'B';
|
|
|
|
CREATE INDEX onek2_stu1_prtl ON onek2 USING btree(stringu1 name_ops)
|
|
|
|
where onek2.stringu1 >= 'J' and onek2.stringu1 < 'K';
|
2000-01-05 18:31:08 +01:00
|
|
|
--
|
|
|
|
-- RTREE
|
|
|
|
--
|
|
|
|
-- rtrees use a quadratic page-splitting algorithm that takes a
|
|
|
|
-- really, really long time. we don't test all rtree opclasses
|
2000-02-17 04:40:02 +01:00
|
|
|
-- in the regression test (we check them using the sequoia 2000
|
2000-01-05 18:31:08 +01:00
|
|
|
-- benchmark).
|
|
|
|
--
|
2003-11-12 22:15:59 +01:00
|
|
|
CREATE INDEX rect2ind ON fast_emp4000 USING rtree (home_base);
|
2000-02-17 04:40:02 +01:00
|
|
|
-- there's no easy way to check that this command actually is using
|
|
|
|
-- the index, unfortunately. (EXPLAIN would work, but its output
|
|
|
|
-- changes too often for me to want to put an EXPLAIN in the test...)
|
|
|
|
SELECT * FROM fast_emp4000
|
|
|
|
WHERE home_base @ '(200,200),(2000,1000)'::box
|
|
|
|
ORDER BY home_base USING <<;
|
|
|
|
home_base
|
|
|
|
-----------------------
|
|
|
|
(337,455),(240,359)
|
|
|
|
(1444,403),(1346,344)
|
|
|
|
(2 rows)
|
|
|
|
|
2000-01-05 18:31:08 +01:00
|
|
|
--
|
|
|
|
-- HASH
|
|
|
|
--
|
|
|
|
CREATE INDEX hash_i4_index ON hash_i4_heap USING hash (random int4_ops);
|
|
|
|
CREATE INDEX hash_name_index ON hash_name_heap USING hash (random name_ops);
|
|
|
|
CREATE INDEX hash_txt_index ON hash_txt_heap USING hash (random text_ops);
|
|
|
|
CREATE INDEX hash_f8_index ON hash_f8_heap USING hash (random float8_ops);
|
|
|
|
-- CREATE INDEX hash_ovfl_index ON hash_ovfl_heap USING hash (x int4_ops);
|
2001-08-28 01:23:35 +02:00
|
|
|
--
|
|
|
|
-- Test functional index
|
|
|
|
--
|
|
|
|
CREATE TABLE func_index_heap (f1 text, f2 text);
|
|
|
|
CREATE UNIQUE INDEX func_index_index on func_index_heap (textcat(f1,f2));
|
|
|
|
INSERT INTO func_index_heap VALUES('ABC','DEF');
|
|
|
|
INSERT INTO func_index_heap VALUES('AB','CDEFG');
|
|
|
|
INSERT INTO func_index_heap VALUES('QWE','RTY');
|
|
|
|
-- this should fail because of unique index:
|
|
|
|
INSERT INTO func_index_heap VALUES('ABCD', 'EF');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: duplicate key violates unique constraint "func_index_index"
|
2001-08-28 01:23:35 +02:00
|
|
|
-- but this shouldn't:
|
|
|
|
INSERT INTO func_index_heap VALUES('QWERTY');
|
2003-05-28 18:04:02 +02:00
|
|
|
--
|
|
|
|
-- Same test, expressional index
|
|
|
|
--
|
|
|
|
DROP TABLE func_index_heap;
|
|
|
|
CREATE TABLE func_index_heap (f1 text, f2 text);
|
|
|
|
CREATE UNIQUE INDEX func_index_index on func_index_heap ((f1 || f2) text_ops);
|
|
|
|
INSERT INTO func_index_heap VALUES('ABC','DEF');
|
|
|
|
INSERT INTO func_index_heap VALUES('AB','CDEFG');
|
|
|
|
INSERT INTO func_index_heap VALUES('QWE','RTY');
|
|
|
|
-- this should fail because of unique index:
|
|
|
|
INSERT INTO func_index_heap VALUES('ABCD', 'EF');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: duplicate key violates unique constraint "func_index_index"
|
2003-05-28 18:04:02 +02:00
|
|
|
-- but this shouldn't:
|
|
|
|
INSERT INTO func_index_heap VALUES('QWERTY');
|
2003-05-29 03:09:13 +02:00
|
|
|
--
|
|
|
|
-- Also try building functional, expressional, and partial indexes on
|
|
|
|
-- tables that already contain data.
|
|
|
|
--
|
|
|
|
create unique index hash_f8_index_1 on hash_f8_heap(abs(random));
|
|
|
|
create unique index hash_f8_index_2 on hash_f8_heap((seqno + 1), random);
|
|
|
|
create unique index hash_f8_index_3 on hash_f8_heap(random) where seqno > 1000;
|