mirror of
https://github.com/postgres/postgres.git
synced 2025-11-29 23:43:17 +03:00
Using the just-added infrastructure, extend btree_gin to support cross-type operators in its other opclasses. All of the cross-type comparison operators supported by the core btree opclasses for these datatypes are now available for btree_gin indexes as well. Author: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com> Discussion: https://postgr.es/m/262624.1738460652@sss.pgh.pa.us
414 lines
7.9 KiB
Plaintext
414 lines
7.9 KiB
Plaintext
set enable_seqscan=off;
|
|
CREATE TABLE test_date (
|
|
i date
|
|
);
|
|
INSERT INTO test_date VALUES
|
|
( '2004-10-23' ),
|
|
( '2004-10-24' ),
|
|
( '2004-10-25' ),
|
|
( '2004-10-26' ),
|
|
( '2004-10-27' ),
|
|
( '2004-10-28' )
|
|
;
|
|
CREATE INDEX idx_date ON test_date USING gin (i);
|
|
SELECT * FROM test_date WHERE i<'2004-10-26'::date ORDER BY i;
|
|
i
|
|
------------
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<='2004-10-26'::date ORDER BY i;
|
|
i
|
|
------------
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i='2004-10-26'::date ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i>='2004-10-26'::date ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_date WHERE i>'2004-10-26'::date ORDER BY i;
|
|
i
|
|
------------
|
|
10-27-2004
|
|
10-28-2004
|
|
(2 rows)
|
|
|
|
explain (costs off)
|
|
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamp ORDER BY i;
|
|
QUERY PLAN
|
|
-----------------------------------------------------------------------------------------
|
|
Sort
|
|
Sort Key: i
|
|
-> Bitmap Heap Scan on test_date
|
|
Recheck Cond: (i < 'Tue Oct 26 00:00:00 2004'::timestamp without time zone)
|
|
-> Bitmap Index Scan on idx_date
|
|
Index Cond: (i < 'Tue Oct 26 00:00:00 2004'::timestamp without time zone)
|
|
(6 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<='2004-10-26'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i='2004-10-26'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i>='2004-10-26'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_date WHERE i>'2004-10-26'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
10-27-2004
|
|
10-28-2004
|
|
(2 rows)
|
|
|
|
explain (costs off)
|
|
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamptz ORDER BY i;
|
|
QUERY PLAN
|
|
------------------------------------------------------------------------------------------
|
|
Sort
|
|
Sort Key: i
|
|
-> Bitmap Heap Scan on test_date
|
|
Recheck Cond: (i < 'Tue Oct 26 00:00:00 2004 PDT'::timestamp with time zone)
|
|
-> Bitmap Index Scan on idx_date
|
|
Index Cond: (i < 'Tue Oct 26 00:00:00 2004 PDT'::timestamp with time zone)
|
|
(6 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<'2004-10-26'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<='2004-10-26'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i='2004-10-26'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i>='2004-10-26'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_date WHERE i>'2004-10-26'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
10-27-2004
|
|
10-28-2004
|
|
(2 rows)
|
|
|
|
-- Check endpoint and out-of-range cases
|
|
INSERT INTO test_date VALUES ('-infinity'), ('infinity');
|
|
SELECT gin_clean_pending_list('idx_date');
|
|
gin_clean_pending_list
|
|
------------------------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i<'-infinity'::timestamp ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<='-infinity'::timestamp ORDER BY i;
|
|
i
|
|
-----------
|
|
-infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i='-infinity'::timestamp ORDER BY i;
|
|
i
|
|
-----------
|
|
-infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i>='-infinity'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(8 rows)
|
|
|
|
SELECT * FROM test_date WHERE i>'-infinity'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(7 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<'infinity'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
(7 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<='infinity'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(8 rows)
|
|
|
|
SELECT * FROM test_date WHERE i='infinity'::timestamp ORDER BY i;
|
|
i
|
|
----------
|
|
infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i>='infinity'::timestamp ORDER BY i;
|
|
i
|
|
----------
|
|
infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i>'infinity'::timestamp ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<'-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<='-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
-----------
|
|
-infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i='-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
-----------
|
|
-infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i>='-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(8 rows)
|
|
|
|
SELECT * FROM test_date WHERE i>'-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(7 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<'infinity'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
(7 rows)
|
|
|
|
SELECT * FROM test_date WHERE i<='infinity'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(8 rows)
|
|
|
|
SELECT * FROM test_date WHERE i='infinity'::timestamptz ORDER BY i;
|
|
i
|
|
----------
|
|
infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i>='infinity'::timestamptz ORDER BY i;
|
|
i
|
|
----------
|
|
infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_date WHERE i>'infinity'::timestamptz ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
-- Check rounding cases
|
|
-- '2004-10-25 00:00:01' rounds to '2004-10-25' for date.
|
|
-- '2004-10-25 23:59:59' also rounds to '2004-10-25',
|
|
-- so it's the same case as '2004-10-25 00:00:01'
|
|
SELECT * FROM test_date WHERE i < '2004-10-25 00:00:01'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i <= '2004-10-25 00:00:01'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i = '2004-10-25 00:00:01'::timestamp ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_date WHERE i > '2004-10-25 00:00:01'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i >= '2004-10-25 00:00:01'::timestamp ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i < '2004-10-25 00:00:01'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i <= '2004-10-25 00:00:01'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
-infinity
|
|
10-23-2004
|
|
10-24-2004
|
|
10-25-2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i = '2004-10-25 00:00:01'::timestamptz ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_date WHERE i > '2004-10-25 00:00:01'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_date WHERE i >= '2004-10-25 00:00:01'::timestamptz ORDER BY i;
|
|
i
|
|
------------
|
|
10-26-2004
|
|
10-27-2004
|
|
10-28-2004
|
|
infinity
|
|
(4 rows)
|
|
|