From 2b5a368d06f1d1a936d7dabba46a6e942425773e Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 8 May 2012 15:51:13 +0200 Subject: [PATCH] RRTimeslice: Changed all comparison operators to compare SEQ only. Else, a b-tree won't work (d'oh!). --- src/postrr.h.in | 18 ++++++------ src/postrr.sql.in | 48 +++++++++++++++--------------- src/rrtimeslice.c | 74 ++++++++++++++++++++++++----------------------- 3 files changed, 71 insertions(+), 69 deletions(-) diff --git a/src/postrr.h.in b/src/postrr.h.in index 9a25d4e..2d32f1c 100644 --- a/src/postrr.h.in +++ b/src/postrr.h.in @@ -81,28 +81,28 @@ rrtimeslice_to_rrtimeslice(PG_FUNCTION_ARGS); /* comparison operators */ Datum -rrtimeslice_eq(PG_FUNCTION_ARGS); +rrtimeslice_seq_eq(PG_FUNCTION_ARGS); Datum -rrtimeslice_ne(PG_FUNCTION_ARGS); +rrtimeslice_seq_ne(PG_FUNCTION_ARGS); Datum -rrtimeslice_lt(PG_FUNCTION_ARGS); +rrtimeslice_seq_lt(PG_FUNCTION_ARGS); Datum -rrtimeslice_le(PG_FUNCTION_ARGS); +rrtimeslice_seq_le(PG_FUNCTION_ARGS); Datum -rrtimeslice_gt(PG_FUNCTION_ARGS); +rrtimeslice_seq_gt(PG_FUNCTION_ARGS); Datum -rrtimeslice_ge(PG_FUNCTION_ARGS); +rrtimeslice_seq_ge(PG_FUNCTION_ARGS); Datum -rrtimeslice_cmp(PG_FUNCTION_ARGS); +rrtimeslice_seq_cmp(PG_FUNCTION_ARGS); Datum -rrtimeslice_hash(PG_FUNCTION_ARGS); +rrtimeslice_seq_hash(PG_FUNCTION_ARGS); /* * internal (not fmgr-callable) functions */ int -rrtimeslice_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2); +rrtimeslice_seq_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2); /* * CData data type diff --git a/src/postrr.sql.in b/src/postrr.sql.in index c2b4821..8596cf8 100644 --- a/src/postrr.sql.in +++ b/src/postrr.sql.in @@ -100,50 +100,50 @@ CREATE CAST (rrtimeslice AS rrtimeslice) WITH FUNCTION RRTimeslice(rrtimeslice, integer, boolean) AS IMPLICIT; -CREATE OR REPLACE FUNCTION RRTimeslice_eq(rrtimeslice, rrtimeslice) +CREATE OR REPLACE FUNCTION rrtimeslice_seq_eq(rrtimeslice, rrtimeslice) RETURNS boolean - AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_eq' + AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_seq_eq' LANGUAGE 'C' IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION RRTimeslice_ne(rrtimeslice, rrtimeslice) +CREATE OR REPLACE FUNCTION rrtimeslice_seq_ne(rrtimeslice, rrtimeslice) RETURNS boolean - AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_ne' + AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_seq_ne' LANGUAGE 'C' IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION RRTimeslice_lt(rrtimeslice, rrtimeslice) +CREATE OR REPLACE FUNCTION rrtimeslice_seq_lt(rrtimeslice, rrtimeslice) RETURNS boolean - AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_lt' + AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_seq_lt' LANGUAGE 'C' IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION RRTimeslice_le(rrtimeslice, rrtimeslice) +CREATE OR REPLACE FUNCTION rrtimeslice_seq_le(rrtimeslice, rrtimeslice) RETURNS boolean - AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_le' + AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_seq_le' LANGUAGE 'C' IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION RRTimeslice_gt(rrtimeslice, rrtimeslice) +CREATE OR REPLACE FUNCTION rrtimeslice_seq_gt(rrtimeslice, rrtimeslice) RETURNS boolean - AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_gt' + AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_seq_gt' LANGUAGE 'C' IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION RRTimeslice_ge(rrtimeslice, rrtimeslice) +CREATE OR REPLACE FUNCTION rrtimeslice_seq_ge(rrtimeslice, rrtimeslice) RETURNS boolean - AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_ge' + AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_seq_ge' LANGUAGE 'C' IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION RRTimeslice_cmp(rrtimeslice, rrtimeslice) +CREATE OR REPLACE FUNCTION rrtimeslice_seq_cmp(rrtimeslice, rrtimeslice) RETURNS integer - AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_cmp' + AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_seq_cmp' LANGUAGE 'C' IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION RRTimeslice_hash(rrtimeslice) +CREATE OR REPLACE FUNCTION rrtimeslice_seq_hash(rrtimeslice) RETURNS integer - AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_hash' + AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_seq_hash' LANGUAGE 'C' IMMUTABLE STRICT; CREATE OPERATOR = ( LEFTARG = RRTimeslice, RIGHTARG = RRTimeslice, - PROCEDURE = RRTimeslice_eq, + PROCEDURE = rrtimeslice_seq_eq, COMMUTATOR = =, NEGATOR = <>, RESTRICT = eqsel @@ -152,7 +152,7 @@ CREATE OPERATOR = ( CREATE OPERATOR <> ( LEFTARG = RRTimeslice, RIGHTARG = RRTimeslice, - PROCEDURE = RRTimeslice_ne, + PROCEDURE = rrtimeslice_seq_ne, COMMUTATOR = <>, NEGATOR = =, RESTRICT = neqsel @@ -161,7 +161,7 @@ CREATE OPERATOR <> ( CREATE OPERATOR < ( LEFTARG = RRTimeslice, RIGHTARG = RRTimeslice, - PROCEDURE = RRTimeslice_lt, + PROCEDURE = rrtimeslice_seq_lt, COMMUTATOR = >, NEGATOR = <=, RESTRICT = scalarltsel @@ -170,7 +170,7 @@ CREATE OPERATOR < ( CREATE OPERATOR <= ( LEFTARG = RRTimeslice, RIGHTARG = RRTimeslice, - PROCEDURE = RRTimeslice_le, + PROCEDURE = rrtimeslice_seq_le, COMMUTATOR = >=, NEGATOR = <, RESTRICT = scalarltsel @@ -179,7 +179,7 @@ CREATE OPERATOR <= ( CREATE OPERATOR > ( LEFTARG = RRTimeslice, RIGHTARG = RRTimeslice, - PROCEDURE = RRTimeslice_gt, + PROCEDURE = rrtimeslice_seq_gt, COMMUTATOR = <, NEGATOR = >=, RESTRICT = scalargtsel @@ -188,7 +188,7 @@ CREATE OPERATOR > ( CREATE OPERATOR >= ( LEFTARG = RRTimeslice, RIGHTARG = RRTimeslice, - PROCEDURE = RRTimeslice_ge, + PROCEDURE = rrtimeslice_seq_ge, COMMUTATOR = <=, NEGATOR = >, RESTRICT = scalargtsel @@ -201,12 +201,12 @@ CREATE OPERATOR CLASS rrtimeslice_ops OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , - FUNCTION 1 RRTimeslice_cmp(rrtimeslice, rrtimeslice); + FUNCTION 1 rrtimeslice_seq_cmp(rrtimeslice, rrtimeslice); CREATE OPERATOR CLASS rrtimeslice_hash_ops FOR TYPE RRTimeslice USING hash AS OPERATOR 1 = , - FUNCTION 1 RRTimeslice_hash(rrtimeslice); + FUNCTION 1 rrtimeslice_seq_hash(rrtimeslice); CREATE TYPE CData; diff --git a/src/rrtimeslice.c b/src/rrtimeslice.c index b086622..a91a9de 100644 --- a/src/rrtimeslice.c +++ b/src/rrtimeslice.c @@ -208,14 +208,14 @@ PG_FUNCTION_INFO_V1(rrtimeslice_typmodout); PG_FUNCTION_INFO_V1(rrtimeslice_to_rrtimeslice); -PG_FUNCTION_INFO_V1(rrtimeslice_eq); -PG_FUNCTION_INFO_V1(rrtimeslice_ne); -PG_FUNCTION_INFO_V1(rrtimeslice_lt); -PG_FUNCTION_INFO_V1(rrtimeslice_gt); -PG_FUNCTION_INFO_V1(rrtimeslice_le); -PG_FUNCTION_INFO_V1(rrtimeslice_ge); -PG_FUNCTION_INFO_V1(rrtimeslice_cmp); -PG_FUNCTION_INFO_V1(rrtimeslice_hash); +PG_FUNCTION_INFO_V1(rrtimeslice_seq_eq); +PG_FUNCTION_INFO_V1(rrtimeslice_seq_ne); +PG_FUNCTION_INFO_V1(rrtimeslice_seq_lt); +PG_FUNCTION_INFO_V1(rrtimeslice_seq_gt); +PG_FUNCTION_INFO_V1(rrtimeslice_seq_le); +PG_FUNCTION_INFO_V1(rrtimeslice_seq_ge); +PG_FUNCTION_INFO_V1(rrtimeslice_seq_cmp); +PG_FUNCTION_INFO_V1(rrtimeslice_seq_hash); /* * public API @@ -473,7 +473,7 @@ rrtimeslice_to_rrtimeslice(PG_FUNCTION_ARGS) } /* rrtimeslice_to_rrtimeslice */ int -rrtimeslice_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2) +rrtimeslice_seq_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2) { if ((! ts1) && (! ts2)) return 0; @@ -494,81 +494,83 @@ rrtimeslice_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2) "rrtimeslices with different typmods (yet)") )); - if (ts1->seq == ts2->seq) + if (ts1->seq < ts2->seq) + return -1; + else if (ts1->seq == ts2->seq) return 0; - - return timestamp_cmp_internal(ts1->tstamp, ts2->tstamp); -} /* rrtimeslice_cmp_internal */ + else + return 1; +} /* rrtimeslice_seq_cmp_internal */ Datum -rrtimeslice_eq(PG_FUNCTION_ARGS) +rrtimeslice_seq_eq(PG_FUNCTION_ARGS) { rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0); rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1); - PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) == 0); -} /* rrtimeslice_eq */ + PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) == 0); +} /* rrtimeslice_seq_eq */ Datum -rrtimeslice_ne(PG_FUNCTION_ARGS) +rrtimeslice_seq_ne(PG_FUNCTION_ARGS) { rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0); rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1); - PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) != 0); -} /* rrtimeslice_ne */ + PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) != 0); +} /* rrtimeslice_seq_ne */ Datum -rrtimeslice_lt(PG_FUNCTION_ARGS) +rrtimeslice_seq_lt(PG_FUNCTION_ARGS) { rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0); rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1); - PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) < 0); -} /* rrtimeslice_lt */ + PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) < 0); +} /* rrtimeslice_seq_lt */ Datum -rrtimeslice_le(PG_FUNCTION_ARGS) +rrtimeslice_seq_le(PG_FUNCTION_ARGS) { rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0); rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1); - PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) <= 0); -} /* rrtimeslice_le */ + PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) <= 0); +} /* rrtimeslice_seq_le */ Datum -rrtimeslice_gt(PG_FUNCTION_ARGS) +rrtimeslice_seq_gt(PG_FUNCTION_ARGS) { rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0); rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1); - PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) > 0); -} /* rrtimeslice_gt */ + PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) > 0); +} /* rrtimeslice_seq_gt */ Datum -rrtimeslice_ge(PG_FUNCTION_ARGS) +rrtimeslice_seq_ge(PG_FUNCTION_ARGS) { rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0); rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1); - PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) >= 0); -} /* rrtimeslice_ge */ + PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) >= 0); +} /* rrtimeslice_seq_ge */ Datum -rrtimeslice_cmp(PG_FUNCTION_ARGS) +rrtimeslice_seq_cmp(PG_FUNCTION_ARGS) { rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0); rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1); - PG_RETURN_INT32(rrtimeslice_cmp_internal(ts1, ts2)); -} /* rrtimeslice_ge */ + PG_RETURN_INT32(rrtimeslice_seq_cmp_internal(ts1, ts2)); +} /* rrtimeslice_seq_ge */ Datum -rrtimeslice_hash(PG_FUNCTION_ARGS) +rrtimeslice_seq_hash(PG_FUNCTION_ARGS) { rrtimeslice_t *ts = PG_GETARG_RRTIMESLICE_P(0); return hash_uint32(ts->seq); -} /* rrtimeslice_hash */ +} /* rrtimeslice_seq_hash */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ -- 2.30.2