1
- set enable_seqscan=off;
2
1
CREATE TABLE test_timestamp (
3
2
i timestamp
4
3
);
@@ -10,7 +9,51 @@ INSERT INTO test_timestamp VALUES
10
9
( '2004-10-26 09:55:08' ),
11
10
( '2004-10-26 10:55:08' )
12
11
;
12
+ SELECT i <-> '2004-10-26 06:24:08', i FROM test_timestamp ORDER BY 1, 2 ASC;
13
+ ?column? | i
14
+ ----------+--------------------------
15
+ 1740 | Tue Oct 26 05:55:08 2004
16
+ 5340 | Tue Oct 26 04:55:08 2004
17
+ 8940 | Tue Oct 26 03:55:08 2004
18
+ 9060 | Tue Oct 26 08:55:08 2004
19
+ 12660 | Tue Oct 26 09:55:08 2004
20
+ 16260 | Tue Oct 26 10:55:08 2004
21
+ (6 rows)
22
+
23
+ SELECT i <-| '2004-10-26 06:24:08', i FROM test_timestamp ORDER BY 1, 2 ASC;
24
+ ?column? | i
25
+ ----------+--------------------------
26
+ 1740 | Tue Oct 26 05:55:08 2004
27
+ 5340 | Tue Oct 26 04:55:08 2004
28
+ 8940 | Tue Oct 26 03:55:08 2004
29
+ Infinity | Tue Oct 26 08:55:08 2004
30
+ Infinity | Tue Oct 26 09:55:08 2004
31
+ Infinity | Tue Oct 26 10:55:08 2004
32
+ (6 rows)
33
+
34
+ SELECT i |-> '2004-10-26 06:24:08', i FROM test_timestamp ORDER BY 1, 2 ASC;
35
+ ?column? | i
36
+ ----------+--------------------------
37
+ 9060 | Tue Oct 26 08:55:08 2004
38
+ 12660 | Tue Oct 26 09:55:08 2004
39
+ 16260 | Tue Oct 26 10:55:08 2004
40
+ Infinity | Tue Oct 26 03:55:08 2004
41
+ Infinity | Tue Oct 26 04:55:08 2004
42
+ Infinity | Tue Oct 26 05:55:08 2004
43
+ (6 rows)
44
+
13
45
CREATE INDEX idx_timestamp ON test_timestamp USING rum (i);
46
+ set enable_seqscan=off;
47
+ explain (costs off)
48
+ SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
49
+ QUERY PLAN
50
+ -----------------------------------------------------------------------------------
51
+ Sort
52
+ Sort Key: i
53
+ -> Index Scan using idx_timestamp on test_timestamp
54
+ Index Cond: (i < 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
55
+ (4 rows)
56
+
14
57
SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
15
58
i
16
59
--------------------------
@@ -19,6 +62,16 @@ SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i
19
62
Tue Oct 26 05:55:08 2004
20
63
(3 rows)
21
64
65
+ explain (costs off)
66
+ SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamp ORDER BY i;
67
+ QUERY PLAN
68
+ ------------------------------------------------------------------------------------
69
+ Sort
70
+ Sort Key: i
71
+ -> Index Scan using idx_timestamp on test_timestamp
72
+ Index Cond: (i <= 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
73
+ (4 rows)
74
+
22
75
SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamp ORDER BY i;
23
76
i
24
77
--------------------------
@@ -28,12 +81,30 @@ SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamp ORDER BY
28
81
Tue Oct 26 08:55:08 2004
29
82
(4 rows)
30
83
84
+ explain (costs off)
85
+ SELECT * FROM test_timestamp WHERE i='2004-10-26 08:55:08'::timestamp ORDER BY i;
86
+ QUERY PLAN
87
+ -----------------------------------------------------------------------------
88
+ Index Scan using idx_timestamp on test_timestamp
89
+ Index Cond: (i = 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
90
+ (2 rows)
91
+
31
92
SELECT * FROM test_timestamp WHERE i='2004-10-26 08:55:08'::timestamp ORDER BY i;
32
93
i
33
94
--------------------------
34
95
Tue Oct 26 08:55:08 2004
35
96
(1 row)
36
97
98
+ explain (costs off)
99
+ SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY i;
100
+ QUERY PLAN
101
+ ------------------------------------------------------------------------------------
102
+ Sort
103
+ Sort Key: i
104
+ -> Index Scan using idx_timestamp on test_timestamp
105
+ Index Cond: (i >= 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
106
+ (4 rows)
107
+
37
108
SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY i;
38
109
i
39
110
--------------------------
@@ -42,6 +113,16 @@ SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY
42
113
Tue Oct 26 10:55:08 2004
43
114
(3 rows)
44
115
116
+ explain (costs off)
117
+ SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamp ORDER BY i;
118
+ QUERY PLAN
119
+ -----------------------------------------------------------------------------------
120
+ Sort
121
+ Sort Key: i
122
+ -> Index Scan using idx_timestamp on test_timestamp
123
+ Index Cond: (i > 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
124
+ (4 rows)
125
+
45
126
SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamp ORDER BY i;
46
127
i
47
128
--------------------------
0 commit comments