Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0050c0a

Browse files
committed
revert sort order for timestamp to make fast <=| instead of |=>
1 parent 4576208 commit 0050c0a

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

rum--1.0.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ CREATE OPERATOR |=> (
104104

105105
-- timestamp operator class
106106

107+
CREATE FUNCTION rum_timestamp_cmp(timestamp,timestamp)
108+
RETURNS int
109+
AS 'MODULE_PATHNAME'
110+
LANGUAGE C STRICT IMMUTABLE;
111+
107112
CREATE FUNCTION rum_timestamp_extract_value(timestamp,internal,internal,internal,internal)
108113
RETURNS internal
109114
AS 'MODULE_PATHNAME'
@@ -138,7 +143,7 @@ AS
138143
OPERATOR 4 >=,
139144
OPERATOR 5 >,
140145
--support
141-
FUNCTION 1 timestamp_cmp(timestamp,timestamp),
146+
FUNCTION 1 rum_timestamp_cmp(timestamp,timestamp),
142147
FUNCTION 2 rum_timestamp_extract_value(timestamp,internal,internal,internal,internal),
143148
FUNCTION 3 rum_timestamp_extract_query(timestamp,internal,smallint,internal,internal,internal,internal),
144149
FUNCTION 4 rum_timestamp_consistent(internal,smallint,timestamp,int,internal,internal,internal,internal),

rum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,6 @@ extern Datum FunctionCall10Coll(FmgrInfo *flinfo, Oid collation,
975975
Datum arg6, Datum arg7, Datum arg8,
976976
Datum arg9, Datum arg10);
977977

978-
#define FROM_STRATEGY (22)
978+
#define FROM_STRATEGY (21)
979979

980980
#endif /* __RUM_H__ */

rum_timestamp.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ rum_timestamp_extract_query(PG_FUNCTION_ARGS)
5454

5555
switch (strategy)
5656
{
57-
case BTLessStrategyNumber:
58-
case BTLessEqualStrategyNumber:
59-
entries[0] = TimestampGetDatum(DT_NOBEGIN); /* leftmost */
60-
*ptr_partialmatch = true;
61-
break;
6257
case BTGreaterEqualStrategyNumber:
6358
case BTGreaterStrategyNumber:
59+
entries[0] = TimestampGetDatum(DT_NOEND); /* leftmost */
6460
*ptr_partialmatch = true;
61+
break;
62+
63+
case BTLessStrategyNumber:
64+
case BTLessEqualStrategyNumber:
65+
*ptr_partialmatch = true;
66+
6567
case BTEqualStrategyNumber:
6668
case RUM_TMST_DISTANCE:
6769
case RUM_TMST_LEFT_DISTANCE:
@@ -75,6 +77,20 @@ rum_timestamp_extract_query(PG_FUNCTION_ARGS)
7577
PG_RETURN_POINTER(entries);
7678
}
7779

80+
PG_FUNCTION_INFO_V1(rum_timestamp_cmp);
81+
Datum
82+
rum_timestamp_cmp(PG_FUNCTION_ARGS)
83+
{
84+
Datum a = PG_GETARG_DATUM(0);
85+
Datum b = PG_GETARG_DATUM(1);
86+
int32 cmp;
87+
88+
cmp = -DatumGetInt32(DirectFunctionCall2Coll(timestamp_cmp,
89+
PG_GET_COLLATION(),
90+
a, b));
91+
PG_RETURN_INT32(cmp);
92+
}
93+
7894
PG_FUNCTION_INFO_V1(rum_timestamp_compare_prefix);
7995
Datum
8096
rum_timestamp_compare_prefix(PG_FUNCTION_ARGS)
@@ -85,22 +101,22 @@ rum_timestamp_compare_prefix(PG_FUNCTION_ARGS)
85101
int32 res,
86102
cmp;
87103

88-
cmp = DatumGetInt32(DirectFunctionCall2Coll(timestamp_cmp,
104+
cmp = DatumGetInt32(DirectFunctionCall2Coll(rum_timestamp_cmp,
89105
PG_GET_COLLATION(),
90-
(data->strategy == BTLessStrategyNumber ||
91-
data->strategy == BTLessEqualStrategyNumber)
106+
(data->strategy == BTGreaterStrategyNumber ||
107+
data->strategy == BTGreaterEqualStrategyNumber)
92108
? data->datum : a, b));
93109

94110
switch (data->strategy)
95111
{
96-
case BTLessStrategyNumber:
112+
case BTGreaterStrategyNumber:
97113
/* If original datum > indexed one then return match */
98114
if (cmp > 0)
99115
res = 0;
100116
else
101117
res = 1;
102118
break;
103-
case BTLessEqualStrategyNumber:
119+
case BTGreaterEqualStrategyNumber:
104120
/* The same except equality */
105121
if (cmp >= 0)
106122
res = 0;
@@ -113,14 +129,14 @@ rum_timestamp_compare_prefix(PG_FUNCTION_ARGS)
113129
else
114130
res = 0;
115131
break;
116-
case BTGreaterEqualStrategyNumber:
132+
case BTLessEqualStrategyNumber:
117133
/* If original datum <= indexed one then return match */
118134
if (cmp <= 0)
119135
res = 0;
120136
else
121137
res = 1;
122138
break;
123-
case BTGreaterStrategyNumber:
139+
case BTLessStrategyNumber:
124140
/* If original datum <= indexed one then return match */
125141
/* If original datum == indexed one then continue scan */
126142
if (cmp < 0)

0 commit comments

Comments
 (0)