[Groonga-commit] pgroonga/pgroonga at f6ab76b [master] Support timestamp and timestamp with time zone

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Feb 14 22:48:53 JST 2015


Kouhei Sutou	2015-02-14 22:48:53 +0900 (Sat, 14 Feb 2015)

  New Revision: f6ab76b9dcf3178b0d51619523998c3c5b0df4f0
  https://github.com/pgroonga/pgroonga/commit/f6ab76b9dcf3178b0d51619523998c3c5b0df4f0

  Message:
    Support timestamp and timestamp with time zone

  Added files:
    expected/compare/timestamp/single/between/bitmapscan.out
    expected/compare/timestamp/single/between/indexscan.out
    expected/compare/timestamp/single/between/seqscan.out
    sql/compare/timestamp/single/between/bitmapscan.sql
    sql/compare/timestamp/single/between/indexscan.sql
    sql/compare/timestamp/single/between/seqscan.sql
  Modified files:
    Makefile
    pgroonga.c
    pgroonga_types.c

  Modified: Makefile (+4 -1)
===================================================================
--- Makefile    2015-02-14 21:45:07 +0900 (f5b351d)
+++ Makefile    2015-02-14 22:48:53 +0900 (9fa78f6)
@@ -7,7 +7,7 @@ EXTENSION_VERSION =						\
 		sed -e "s/^.*'\([0-9.]*\)'$$/\1/")
 DATA = pgroonga--$(EXTENSION_VERSION).sql
 PG_CPPFLAGS = $(shell pkg-config --cflags groonga)
-SHLIB_LINK = $(shell pkg-config --libs groonga)
+SHLIB_LINK = $(shell pkg-config --libs groonga) -lm
 # REGRESS = pgroonga update bench
 REGRESS = $(shell find sql -name '*.sql' | sed -e 's,\(^sql/\|\.sql$$\),,g')
 REGRESS_OPTS = --load-extension=pgroonga
@@ -39,6 +39,7 @@ installcheck: results/compare/integer/single/greater-than-equal
 installcheck: results/compare/integer/single/between
 installcheck: results/compare/integer/multiple/greater-than-equal
 installcheck: results/compare/integer/order_by_limit
+installcheck: results/compare/timestamp/single/between
 installcheck: results/groonga
 
 results/full-text-search/text/single/contain:
@@ -69,5 +70,7 @@ results/compare/integer/multiple/greater-than-equal:
 	@mkdir -p $@
 results/compare/integer/order_by_limit:
 	@mkdir -p $@
+results/compare/timestamp/single/between:
+	@mkdir -p $@
 results/groonga:
 	@mkdir -p $@

  Added: expected/compare/timestamp/single/between/bitmapscan.out (+33 -0) 100644
===================================================================
--- /dev/null
+++ expected/compare/timestamp/single/between/bitmapscan.out    2015-02-14 22:48:53 +0900 (bb71222)
@@ -0,0 +1,33 @@
+CREATE TABLE logs (
+  created_at timestamp
+);
+INSERT INTO logs VALUES ('2015-02-14 10:44:10');
+INSERT INTO logs VALUES ('2015-02-14 10:44:09');
+INSERT INTO logs VALUES ('2015-02-14 10:44:02');
+INSERT INTO logs VALUES ('2015-02-14 10:44:04');
+INSERT INTO logs VALUES ('2015-02-14 10:44:01');
+INSERT INTO logs VALUES ('2015-02-14 10:44:05');
+INSERT INTO logs VALUES ('2015-02-14 10:44:07');
+INSERT INTO logs VALUES ('2015-02-14 10:44:06');
+INSERT INTO logs VALUES ('2015-02-14 10:44:03');
+INSERT INTO logs VALUES ('2015-02-14 10:44:08');
+CREATE INDEX pgroonga_index ON logs USING pgroonga (created_at);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT created_at
+  FROM logs
+ WHERE created_at BETWEEN '2015-02-14 10:44:03' AND '2015-02-14 10:44:09'
+ ORDER BY created_at ASC;
+        created_at        
+--------------------------
+ Sat Feb 14 10:44:03 2015
+ Sat Feb 14 10:44:04 2015
+ Sat Feb 14 10:44:05 2015
+ Sat Feb 14 10:44:06 2015
+ Sat Feb 14 10:44:07 2015
+ Sat Feb 14 10:44:08 2015
+ Sat Feb 14 10:44:09 2015
+(7 rows)
+
+DROP TABLE logs;

  Added: expected/compare/timestamp/single/between/indexscan.out (+33 -0) 100644
===================================================================
--- /dev/null
+++ expected/compare/timestamp/single/between/indexscan.out    2015-02-14 22:48:53 +0900 (9432c74)
@@ -0,0 +1,33 @@
+CREATE TABLE logs (
+  created_at timestamp
+);
+INSERT INTO logs VALUES ('2015-02-14 10:44:10');
+INSERT INTO logs VALUES ('2015-02-14 10:44:09');
+INSERT INTO logs VALUES ('2015-02-14 10:44:02');
+INSERT INTO logs VALUES ('2015-02-14 10:44:04');
+INSERT INTO logs VALUES ('2015-02-14 10:44:01');
+INSERT INTO logs VALUES ('2015-02-14 10:44:05');
+INSERT INTO logs VALUES ('2015-02-14 10:44:07');
+INSERT INTO logs VALUES ('2015-02-14 10:44:06');
+INSERT INTO logs VALUES ('2015-02-14 10:44:03');
+INSERT INTO logs VALUES ('2015-02-14 10:44:08');
+CREATE INDEX pgroonga_index ON logs USING pgroonga (created_at);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT created_at
+  FROM logs
+ WHERE created_at BETWEEN '2015-02-14 10:44:03' AND '2015-02-14 10:44:09'
+ ORDER BY created_at ASC;
+        created_at        
+--------------------------
+ Sat Feb 14 10:44:03 2015
+ Sat Feb 14 10:44:04 2015
+ Sat Feb 14 10:44:05 2015
+ Sat Feb 14 10:44:06 2015
+ Sat Feb 14 10:44:07 2015
+ Sat Feb 14 10:44:08 2015
+ Sat Feb 14 10:44:09 2015
+(7 rows)
+
+DROP TABLE logs;

  Added: expected/compare/timestamp/single/between/seqscan.out (+33 -0) 100644
===================================================================
--- /dev/null
+++ expected/compare/timestamp/single/between/seqscan.out    2015-02-14 22:48:53 +0900 (22e2e18)
@@ -0,0 +1,33 @@
+CREATE TABLE logs (
+  created_at timestamp
+);
+INSERT INTO logs VALUES ('2015-02-14 10:44:10');
+INSERT INTO logs VALUES ('2015-02-14 10:44:09');
+INSERT INTO logs VALUES ('2015-02-14 10:44:02');
+INSERT INTO logs VALUES ('2015-02-14 10:44:04');
+INSERT INTO logs VALUES ('2015-02-14 10:44:01');
+INSERT INTO logs VALUES ('2015-02-14 10:44:05');
+INSERT INTO logs VALUES ('2015-02-14 10:44:07');
+INSERT INTO logs VALUES ('2015-02-14 10:44:06');
+INSERT INTO logs VALUES ('2015-02-14 10:44:03');
+INSERT INTO logs VALUES ('2015-02-14 10:44:08');
+CREATE INDEX pgroonga_index ON logs USING pgroonga (created_at);
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT created_at
+  FROM logs
+ WHERE created_at BETWEEN '2015-02-14 10:44:03' AND '2015-02-14 10:44:09'
+ ORDER BY created_at ASC;
+        created_at        
+--------------------------
+ Sat Feb 14 10:44:03 2015
+ Sat Feb 14 10:44:04 2015
+ Sat Feb 14 10:44:05 2015
+ Sat Feb 14 10:44:06 2015
+ Sat Feb 14 10:44:07 2015
+ Sat Feb 14 10:44:08 2015
+ Sat Feb 14 10:44:09 2015
+(7 rows)
+
+DROP TABLE logs;

  Modified: pgroonga.c (+1 -5)
===================================================================
--- pgroonga.c    2015-02-14 21:45:07 +0900 (075eff5)
+++ pgroonga.c    2015-02-14 22:48:53 +0900 (4800fc9)
@@ -398,11 +398,7 @@ PGrnGetType(Relation index, AttrNumber n)
 		break;
 	case TIMESTAMPOID:
 	case TIMESTAMPTZOID:
-#ifdef HAVE_INT64_TIMESTAMP
-		typeID = GRN_DB_INT64;	/* FIXME: use GRN_DB_TIME instead */
-#else
-		typeID = GRN_DB_FLOAT;
-#endif
+		typeID = GRN_DB_TIME;
 		break;
 	case TEXTOID:
 	case XMLOID:

  Modified: pgroonga_types.c (+23 -2)
===================================================================
--- pgroonga_types.c    2015-02-14 21:45:07 +0900 (91bf27c)
+++ pgroonga_types.c    2015-02-14 22:48:53 +0900 (243f1cf)
@@ -7,9 +7,12 @@
 
 #include <catalog/pg_type.h>
 #include <utils/builtins.h>
+#include <utils/timestamp.h>
 
 #include <groonga.h>
 
+#include <math.h>
+
 int
 pgroonga_bpchar_size(const BpChar *arg)
 {
@@ -138,11 +141,29 @@ pgroonga_get_float8(PG_FUNCTION_ARGS)
 Datum
 pgroonga_get_timestamp(PG_FUNCTION_ARGS)
 {
+	grn_ctx	*ctx = (grn_ctx *) PG_GETARG_POINTER(0);
+	grn_obj	*obj = (grn_obj *) PG_GETARG_POINTER(1);
+	Timestamp value = PG_GETARG_TIMESTAMP(2);
+	pg_time_t unixTime;
+	int32 usec;
+
+	unixTime = timestamptz_to_time_t(value);
 #ifdef HAVE_INT64_TIMESTAMP
-	return pgroonga_get_int8(fcinfo);
+	usec = value % USECS_PER_SEC;
 #else
-	return pgroonga_get_float8(fcinfo);
+	{
+		double rawUsec;
+		modf(value, &rawUsec);
+		usec = rawUsec * USECS_PER_SEC;
+		if (usec < 0.0)
+		{
+			usec = -usec;
+		}
+	}
 #endif
+	GRN_TIME_SET(ctx, obj, GRN_TIME_PACK(unixTime, usec));
+
+	PG_RETURN_VOID();
 }
 
 Datum

  Added: sql/compare/timestamp/single/between/bitmapscan.sql (+27 -0) 100644
===================================================================
--- /dev/null
+++ sql/compare/timestamp/single/between/bitmapscan.sql    2015-02-14 22:48:53 +0900 (41556e2)
@@ -0,0 +1,27 @@
+CREATE TABLE logs (
+  created_at timestamp
+);
+
+INSERT INTO logs VALUES ('2015-02-14 10:44:10');
+INSERT INTO logs VALUES ('2015-02-14 10:44:09');
+INSERT INTO logs VALUES ('2015-02-14 10:44:02');
+INSERT INTO logs VALUES ('2015-02-14 10:44:04');
+INSERT INTO logs VALUES ('2015-02-14 10:44:01');
+INSERT INTO logs VALUES ('2015-02-14 10:44:05');
+INSERT INTO logs VALUES ('2015-02-14 10:44:07');
+INSERT INTO logs VALUES ('2015-02-14 10:44:06');
+INSERT INTO logs VALUES ('2015-02-14 10:44:03');
+INSERT INTO logs VALUES ('2015-02-14 10:44:08');
+
+CREATE INDEX pgroonga_index ON logs USING pgroonga (created_at);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT created_at
+  FROM logs
+ WHERE created_at BETWEEN '2015-02-14 10:44:03' AND '2015-02-14 10:44:09'
+ ORDER BY created_at ASC;
+
+DROP TABLE logs;

  Added: sql/compare/timestamp/single/between/indexscan.sql (+27 -0) 100644
===================================================================
--- /dev/null
+++ sql/compare/timestamp/single/between/indexscan.sql    2015-02-14 22:48:53 +0900 (574c87c)
@@ -0,0 +1,27 @@
+CREATE TABLE logs (
+  created_at timestamp
+);
+
+INSERT INTO logs VALUES ('2015-02-14 10:44:10');
+INSERT INTO logs VALUES ('2015-02-14 10:44:09');
+INSERT INTO logs VALUES ('2015-02-14 10:44:02');
+INSERT INTO logs VALUES ('2015-02-14 10:44:04');
+INSERT INTO logs VALUES ('2015-02-14 10:44:01');
+INSERT INTO logs VALUES ('2015-02-14 10:44:05');
+INSERT INTO logs VALUES ('2015-02-14 10:44:07');
+INSERT INTO logs VALUES ('2015-02-14 10:44:06');
+INSERT INTO logs VALUES ('2015-02-14 10:44:03');
+INSERT INTO logs VALUES ('2015-02-14 10:44:08');
+
+CREATE INDEX pgroonga_index ON logs USING pgroonga (created_at);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT created_at
+  FROM logs
+ WHERE created_at BETWEEN '2015-02-14 10:44:03' AND '2015-02-14 10:44:09'
+ ORDER BY created_at ASC;
+
+DROP TABLE logs;

  Added: sql/compare/timestamp/single/between/seqscan.sql (+27 -0) 100644
===================================================================
--- /dev/null
+++ sql/compare/timestamp/single/between/seqscan.sql    2015-02-14 22:48:53 +0900 (f69d093)
@@ -0,0 +1,27 @@
+CREATE TABLE logs (
+  created_at timestamp
+);
+
+INSERT INTO logs VALUES ('2015-02-14 10:44:10');
+INSERT INTO logs VALUES ('2015-02-14 10:44:09');
+INSERT INTO logs VALUES ('2015-02-14 10:44:02');
+INSERT INTO logs VALUES ('2015-02-14 10:44:04');
+INSERT INTO logs VALUES ('2015-02-14 10:44:01');
+INSERT INTO logs VALUES ('2015-02-14 10:44:05');
+INSERT INTO logs VALUES ('2015-02-14 10:44:07');
+INSERT INTO logs VALUES ('2015-02-14 10:44:06');
+INSERT INTO logs VALUES ('2015-02-14 10:44:03');
+INSERT INTO logs VALUES ('2015-02-14 10:44:08');
+
+CREATE INDEX pgroonga_index ON logs USING pgroonga (created_at);
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT created_at
+  FROM logs
+ WHERE created_at BETWEEN '2015-02-14 10:44:03' AND '2015-02-14 10:44:09'
+ ORDER BY created_at ASC;
+
+DROP TABLE logs;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index