[Groonga-commit] pgroonga/pgroonga at cbc7658 [master] Support BETWEEN

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Feb 8 18:07:27 JST 2015


Kouhei Sutou	2015-02-08 18:07:27 +0900 (Sun, 08 Feb 2015)

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

  Message:
    Support BETWEEN

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

  Modified: Makefile (+3 -0)
===================================================================
--- Makefile    2015-02-06 00:25:00 +0900 (9159528)
+++ Makefile    2015-02-08 18:07:27 +0900 (a641ee3)
@@ -33,6 +33,7 @@ installcheck: results/full-text-search/text/options/tokenizer
 installcheck: results/full-text-search/text/options/normalizer
 installcheck: results/compare/text/single/equal
 installcheck: results/compare/integer/single/less-than-equal
+installcheck: results/compare/integer/single/between
 installcheck: results/compare/integer/order_by_limit
 
 results/full-text-search/text/single/contain:
@@ -51,5 +52,7 @@ results/compare/text/single/equal:
 	@mkdir -p $@
 results/compare/integer/single/less-than-equal:
 	@mkdir -p $@
+results/compare/integer/single/between:
+	@mkdir -p $@
 results/compare/integer/order_by_limit:
 	@mkdir -p $@

  Added: expected/compare/integer/single/between/bitmapscan.out (+33 -0) 100644
===================================================================
--- /dev/null
+++ expected/compare/integer/single/between/bitmapscan.out    2015-02-08 18:07:27 +0900 (4fcea7f)
@@ -0,0 +1,33 @@
+CREATE TABLE ids (
+  id integer
+);
+INSERT INTO ids VALUES (2);
+INSERT INTO ids VALUES (7);
+INSERT INTO ids VALUES (6);
+INSERT INTO ids VALUES (4);
+INSERT INTO ids VALUES (5);
+INSERT INTO ids VALUES (8);
+INSERT INTO ids VALUES (1);
+INSERT INTO ids VALUES (10);
+INSERT INTO ids VALUES (3);
+INSERT INTO ids VALUES (9);
+CREATE INDEX grnindex ON ids USING pgroonga (id);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id
+  FROM ids
+ WHERE id BETWEEN 3 AND 9
+ ORDER BY id ASC;
+ id 
+----
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+(7 rows)
+
+DROP TABLE ids;

  Added: expected/compare/integer/single/between/indexscan.out (+33 -0) 100644
===================================================================
--- /dev/null
+++ expected/compare/integer/single/between/indexscan.out    2015-02-08 18:07:27 +0900 (f722ca0)
@@ -0,0 +1,33 @@
+CREATE TABLE ids (
+  id integer
+);
+INSERT INTO ids VALUES (2);
+INSERT INTO ids VALUES (7);
+INSERT INTO ids VALUES (6);
+INSERT INTO ids VALUES (4);
+INSERT INTO ids VALUES (5);
+INSERT INTO ids VALUES (8);
+INSERT INTO ids VALUES (1);
+INSERT INTO ids VALUES (10);
+INSERT INTO ids VALUES (3);
+INSERT INTO ids VALUES (9);
+CREATE INDEX grnindex ON ids USING pgroonga (id);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id
+  FROM ids
+ WHERE id BETWEEN 3 AND 9
+ ORDER BY id ASC;
+ id 
+----
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+(7 rows)
+
+DROP TABLE ids;

  Added: expected/compare/integer/single/between/seqscan.out (+33 -0) 100644
===================================================================
--- /dev/null
+++ expected/compare/integer/single/between/seqscan.out    2015-02-08 18:07:27 +0900 (1f3865f)
@@ -0,0 +1,33 @@
+CREATE TABLE ids (
+  id integer
+);
+INSERT INTO ids VALUES (2);
+INSERT INTO ids VALUES (7);
+INSERT INTO ids VALUES (6);
+INSERT INTO ids VALUES (4);
+INSERT INTO ids VALUES (5);
+INSERT INTO ids VALUES (8);
+INSERT INTO ids VALUES (1);
+INSERT INTO ids VALUES (10);
+INSERT INTO ids VALUES (3);
+INSERT INTO ids VALUES (9);
+CREATE INDEX grnindex ON ids USING pgroonga (id);
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id
+  FROM ids
+ WHERE id BETWEEN 3 AND 9
+ ORDER BY id ASC;
+ id 
+----
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+(7 rows)
+
+DROP TABLE ids;

  Modified: pgroonga.c (+45 -24)
===================================================================
--- pgroonga.c    2015-02-06 00:25:00 +0900 (cf118a3)
+++ pgroonga.c    2015-02-08 18:07:27 +0900 (9476964)
@@ -46,6 +46,8 @@ typedef struct PGrnScanOpaqueData
 	grn_obj *idsTable;
 	grn_obj *lexicon;
 	grn_obj *indexColumn;
+	grn_obj minBorderValue;
+	grn_obj maxBorderValue;
 	grn_obj *searched;
 	grn_obj *sorted;
 	grn_obj *targetTable;
@@ -337,7 +339,7 @@ PGrnCheck(const char *message)
  * Support functions and type-specific routines
  */
 
-static grn_builtin_type
+static grn_id
 PGrnGetType(Relation index, AttrNumber n)
 {
 	FmgrInfo *function;
@@ -348,7 +350,7 @@ PGrnGetType(Relation index, AttrNumber n)
 	type = FunctionCall2(function,
 						 ObjectIdGetDatum(desc->attrs[n]->atttypid),
 						 Int32GetDatum(desc->attrs[n]->atttypmod));
-	return (grn_builtin_type) DatumGetInt32(type);
+	return DatumGetInt32(type);
 }
 
 static void
@@ -743,6 +745,8 @@ PGrnScanOpaqueInit(PGrnScanOpaque so, Relation index)
 	so->idsTable = PGrnLookupIDsTable(index, ERROR);
 	so->indexColumn = PGrnLookupIndexColumn(index, ERROR);
 	so->lexicon = grn_column_table(ctx, so->indexColumn);
+	GRN_VOID_INIT(&(so->minBorderValue));
+	GRN_VOID_INIT(&(so->maxBorderValue));
 	so->searched = NULL;
 	so->sorted = NULL;
 	so->targetTable = NULL;
@@ -771,6 +775,8 @@ PGrnScanOpaqueReinit(PGrnScanOpaque so)
 		grn_table_cursor_close(ctx, so->tableCursor);
 		so->tableCursor = NULL;
 	}
+	GRN_OBJ_FIN(ctx, &(so->minBorderValue));
+	GRN_OBJ_FIN(ctx, &(so->maxBorderValue));
 	if (so->sorted)
 	{
 		grn_obj_unlink(ctx, so->sorted);
@@ -1004,44 +1010,59 @@ PGrnFillBorder(IndexScanDesc scan,
 			   int *flags)
 {
 	Relation index = scan->indexRelation;
+	PGrnScanOpaque so = (PGrnScanOpaque) scan->opaque;
+	grn_obj *minBorderValue;
+	grn_obj *maxBorderValue;
 	int i;
 
+	minBorderValue = &(so->minBorderValue);
+	maxBorderValue = &(so->maxBorderValue);
 	for (i = 0; i < scan->numberOfKeys; i++)
 	{
 		ScanKey key = &(scan->keyData[i]);
+		AttrNumber attrNumber;
+		grn_id domain;
 
-		/* TODO: Use buffer for min and max */
-		grn_obj_reinit(ctx, &buffer, PGrnGetType(index, key->sk_attno - 1), 0);
-		PGrnGetValue(index, key->sk_attno - 1, &buffer, key->sk_argument);
-
+		attrNumber = key->sk_attno - 1;
+		domain = PGrnGetType(index, attrNumber);
 		switch (key->sk_strategy)
 		{
 		case PGrnLessStrategyNumber:
-			*max = GRN_BULK_HEAD(&buffer);
-			*maxSize = GRN_BULK_VSIZE(&buffer);
-			*flags |= GRN_CURSOR_LT;
-			break;
 		case PGrnLessEqualStrategyNumber:
-			*max = GRN_BULK_HEAD(&buffer);
-			*maxSize = GRN_BULK_VSIZE(&buffer);
-			*flags |= GRN_CURSOR_LE;
+			grn_obj_reinit(ctx, maxBorderValue, domain, 0);
+			PGrnGetValue(index, attrNumber, maxBorderValue, key->sk_argument);
+			*max = GRN_BULK_HEAD(maxBorderValue);
+			*maxSize = GRN_BULK_VSIZE(maxBorderValue);
+			if (key->sk_strategy == PGrnLessStrategyNumber)
+			{
+				*flags |= GRN_CURSOR_LT;
+			}
+			else
+			{
+				*flags |= GRN_CURSOR_LE;
+			}
 			break;
 		case PGrnEqualStrategyNumber:
-			*min = GRN_BULK_HEAD(&buffer);
-			*minSize = GRN_BULK_VSIZE(&buffer);
-			*max = GRN_BULK_HEAD(&buffer);
-			*maxSize = GRN_BULK_VSIZE(&buffer);
+			grn_obj_reinit(ctx, minBorderValue, domain, 0);
+			PGrnGetValue(index, attrNumber, minBorderValue, key->sk_argument);
+			grn_obj_reinit(ctx, maxBorderValue, domain, 0);
+			PGrnGetValue(index, attrNumber, maxBorderValue, key->sk_argument);
 			*flags |= GRN_CURSOR_LE | GRN_CURSOR_GE;
 			break;
 		case PGrnGreaterEqualStrategyNumber:
-			*min = GRN_BULK_HEAD(&buffer);
-			*minSize = GRN_BULK_VSIZE(&buffer);
-			*flags |= GRN_CURSOR_GE;
-			break;
 		case PGrnGreaterStrategyNumber:
-			*min = GRN_BULK_HEAD(&buffer);
-			*minSize = GRN_BULK_VSIZE(&buffer);
-			*flags |= GRN_CURSOR_GT;
+			grn_obj_reinit(ctx, minBorderValue, domain, 0);
+			PGrnGetValue(index, attrNumber, minBorderValue, key->sk_argument);
+			*min = GRN_BULK_HEAD(minBorderValue);
+			*minSize = GRN_BULK_VSIZE(minBorderValue);
+			if (key->sk_strategy == PGrnGreaterEqualStrategyNumber)
+			{
+				*flags |= GRN_CURSOR_GE;
+			}
+			else
+			{
+				*flags |= GRN_CURSOR_GT;
+			}
 			break;
 		}
 	}

  Added: sql/compare/integer/single/between/bitmapscan.sql (+27 -0) 100644
===================================================================
--- /dev/null
+++ sql/compare/integer/single/between/bitmapscan.sql    2015-02-08 18:07:27 +0900 (494447e)
@@ -0,0 +1,27 @@
+CREATE TABLE ids (
+  id integer
+);
+
+INSERT INTO ids VALUES (2);
+INSERT INTO ids VALUES (7);
+INSERT INTO ids VALUES (6);
+INSERT INTO ids VALUES (4);
+INSERT INTO ids VALUES (5);
+INSERT INTO ids VALUES (8);
+INSERT INTO ids VALUES (1);
+INSERT INTO ids VALUES (10);
+INSERT INTO ids VALUES (3);
+INSERT INTO ids VALUES (9);
+
+CREATE INDEX grnindex ON ids USING pgroonga (id);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id
+  FROM ids
+ WHERE id BETWEEN 3 AND 9
+ ORDER BY id ASC;
+
+DROP TABLE ids;

  Added: sql/compare/integer/single/between/indexscan.sql (+27 -0) 100644
===================================================================
--- /dev/null
+++ sql/compare/integer/single/between/indexscan.sql    2015-02-08 18:07:27 +0900 (4364167)
@@ -0,0 +1,27 @@
+CREATE TABLE ids (
+  id integer
+);
+
+INSERT INTO ids VALUES (2);
+INSERT INTO ids VALUES (7);
+INSERT INTO ids VALUES (6);
+INSERT INTO ids VALUES (4);
+INSERT INTO ids VALUES (5);
+INSERT INTO ids VALUES (8);
+INSERT INTO ids VALUES (1);
+INSERT INTO ids VALUES (10);
+INSERT INTO ids VALUES (3);
+INSERT INTO ids VALUES (9);
+
+CREATE INDEX grnindex ON ids USING pgroonga (id);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id
+  FROM ids
+ WHERE id BETWEEN 3 AND 9
+ ORDER BY id ASC;
+
+DROP TABLE ids;

  Added: sql/compare/integer/single/between/seqscan.sql (+27 -0) 100644
===================================================================
--- /dev/null
+++ sql/compare/integer/single/between/seqscan.sql    2015-02-08 18:07:27 +0900 (b6ddcd8)
@@ -0,0 +1,27 @@
+CREATE TABLE ids (
+  id integer
+);
+
+INSERT INTO ids VALUES (2);
+INSERT INTO ids VALUES (7);
+INSERT INTO ids VALUES (6);
+INSERT INTO ids VALUES (4);
+INSERT INTO ids VALUES (5);
+INSERT INTO ids VALUES (8);
+INSERT INTO ids VALUES (1);
+INSERT INTO ids VALUES (10);
+INSERT INTO ids VALUES (3);
+INSERT INTO ids VALUES (9);
+
+CREATE INDEX grnindex ON ids USING pgroonga (id);
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id
+  FROM ids
+ WHERE id BETWEEN 3 AND 9
+ ORDER BY id ASC;
+
+DROP TABLE ids;
-------------- next part --------------
HTML����������������������������...
Download 



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