mirror of
https://github.com/postgres/postgres.git
synced 2025-09-17 22:22:26 +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
346 lines
8.6 KiB
Plaintext
346 lines
8.6 KiB
Plaintext
set enable_seqscan=off;
|
|
CREATE TABLE test_timestamp (
|
|
i timestamp
|
|
);
|
|
INSERT INTO test_timestamp VALUES
|
|
( '2004-10-26 03:55:08' ),
|
|
( '2004-10-26 04:55:08' ),
|
|
( '2004-10-26 05:55:08' ),
|
|
( '2004-10-26 08:55:08' ),
|
|
( '2004-10-27 09:55:08' ),
|
|
( '2004-10-27 10:55:08' )
|
|
;
|
|
CREATE INDEX idx_timestamp ON test_timestamp USING gin (i);
|
|
SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamp ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i='2004-10-26 08:55:08'::timestamp ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 08:55:08 2004
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamp ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
(2 rows)
|
|
|
|
explain (costs off)
|
|
SELECT * FROM test_timestamp WHERE i<'2004-10-27'::date ORDER BY i;
|
|
QUERY PLAN
|
|
----------------------------------------------------
|
|
Sort
|
|
Sort Key: i
|
|
-> Bitmap Heap Scan on test_timestamp
|
|
Recheck Cond: (i < '10-27-2004'::date)
|
|
-> Bitmap Index Scan on idx_timestamp
|
|
Index Cond: (i < '10-27-2004'::date)
|
|
(6 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<'2004-10-27'::date ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<='2004-10-27'::date ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i='2004-10-27'::date ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>='2004-10-27'::date ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
(2 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>'2004-10-27'::date ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
(2 rows)
|
|
|
|
explain (costs off)
|
|
SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamptz ORDER BY i;
|
|
QUERY PLAN
|
|
------------------------------------------------------------------------------------------
|
|
Sort
|
|
Sort Key: i
|
|
-> Bitmap Heap Scan on test_timestamp
|
|
Recheck Cond: (i < 'Tue Oct 26 08:55:08 2004 PDT'::timestamp with time zone)
|
|
-> Bitmap Index Scan on idx_timestamp
|
|
Index Cond: (i < 'Tue Oct 26 08:55:08 2004 PDT'::timestamp with time zone)
|
|
(6 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
(4 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i='2004-10-26 08:55:08'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 08:55:08 2004
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
(3 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
(2 rows)
|
|
|
|
-- Check endpoint and out-of-range cases
|
|
INSERT INTO test_timestamp VALUES ('-infinity'), ('infinity');
|
|
SELECT gin_clean_pending_list('idx_timestamp');
|
|
gin_clean_pending_list
|
|
------------------------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<'-infinity'::date ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<='-infinity'::date ORDER BY i;
|
|
i
|
|
-----------
|
|
-infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i='-infinity'::date ORDER BY i;
|
|
i
|
|
-----------
|
|
-infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>='-infinity'::date ORDER BY i;
|
|
i
|
|
--------------------------
|
|
-infinity
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
infinity
|
|
(8 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>'-infinity'::date ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
infinity
|
|
(7 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<'infinity'::date ORDER BY i;
|
|
i
|
|
--------------------------
|
|
-infinity
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
(7 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<='infinity'::date ORDER BY i;
|
|
i
|
|
--------------------------
|
|
-infinity
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
infinity
|
|
(8 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i='infinity'::date ORDER BY i;
|
|
i
|
|
----------
|
|
infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>='infinity'::date ORDER BY i;
|
|
i
|
|
----------
|
|
infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>'infinity'::date ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<'-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<='-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
-----------
|
|
-infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i='-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
-----------
|
|
-infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>='-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
-infinity
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
infinity
|
|
(8 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>'-infinity'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
infinity
|
|
(7 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<'infinity'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
-infinity
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
(7 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i<='infinity'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
-infinity
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
infinity
|
|
(8 rows)
|
|
|
|
SELECT * FROM test_timestamp WHERE i='infinity'::timestamptz ORDER BY i;
|
|
i
|
|
----------
|
|
infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>='infinity'::timestamptz ORDER BY i;
|
|
i
|
|
----------
|
|
infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>'infinity'::timestamptz ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
-- This PST timestamptz will underflow if converted to timestamp
|
|
SELECT * FROM test_timestamp WHERE i<='4714-11-23 17:00 BC'::timestamptz ORDER BY i;
|
|
i
|
|
-----------
|
|
-infinity
|
|
(1 row)
|
|
|
|
SELECT * FROM test_timestamp WHERE i>'4714-11-23 17:00 BC'::timestamptz ORDER BY i;
|
|
i
|
|
--------------------------
|
|
Tue Oct 26 03:55:08 2004
|
|
Tue Oct 26 04:55:08 2004
|
|
Tue Oct 26 05:55:08 2004
|
|
Tue Oct 26 08:55:08 2004
|
|
Wed Oct 27 09:55:08 2004
|
|
Wed Oct 27 10:55:08 2004
|
|
infinity
|
|
(7 rows)
|
|
|