[Groonga-commit] pgroonga/pgroonga at 291d100 [master] jsonb: use hashed value as key to support large path

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Sep 26 22:01:40 JST 2015


Kouhei Sutou	2015-09-26 22:01:40 +0900 (Sat, 26 Sep 2015)

  New Revision: 291d1007b50abfe9d948d253d7fe30976e2b91d3
  https://github.com/pgroonga/pgroonga/commit/291d1007b50abfe9d948d253d7fe30976e2b91d3

  Message:
    jsonb: use hashed value as key to support large path

  Added files:
    .gitmodules
    vendor/xxHash
  Modified files:
    Makefile
    pgroonga.c

  Added: .gitmodules (+3 -0) 100644
===================================================================
--- /dev/null
+++ .gitmodules    2015-09-26 22:01:40 +0900 (0df46b3)
@@ -0,0 +1,3 @@
+[submodule "vendor/xxHash"]
+	path = vendor/xxHash
+	url = https://github.com/Cyan4973/xxHash.git

  Modified: Makefile (+4 -1)
===================================================================
--- Makefile    2015-09-26 20:45:00 +0900 (222dd84)
+++ Makefile    2015-09-26 22:01:40 +0900 (5b9b1b9)
@@ -1,5 +1,7 @@
 MODULE_big = pgroonga
-SRCS = pgroonga.c
+SRCS =						\
+	pgroonga.c				\
+	vendor/xxHash/xxhash.c
 OBJS = $(SRCS:.c=.o)
 EXTENSION = pgroonga
 EXTENSION_VERSION =						\
@@ -11,6 +13,7 @@ SHLIB_LINK = $(shell pkg-config --libs groonga) -lm
 REGRESS = $(shell find sql -name '*.sql' | sed -e 's,\(^sql/\|\.sql$$\),,g')
 REGRESS_OPTS = --load-extension=pgroonga
 
+COPT += -Ivendor/xxHash
 ifdef DEBUG
 COPT += -O0 -g3 -DPGROONGA_DEBUG=1
 SHLIB_LINK += -Wl,--rpath=$(shell pkg-config --libs-only-L groonga | sed -e 's/^-L//')

  Modified: pgroonga.c (+14 -7)
===================================================================
--- pgroonga.c    2015-09-26 20:45:00 +0900 (a964453)
+++ pgroonga.c    2015-09-26 22:01:40 +0900 (888320f)
@@ -29,6 +29,8 @@
 
 #include <groonga.h>
 
+#include <xxhash.h>
+
 #include <stdlib.h>
 #include <math.h>
 #include <sys/types.h>
@@ -1023,7 +1025,7 @@ PGrnCreateDataColumnsForJSON(PGrnCreateData *data)
 		data->jsonValuesTable =
 			PGrnCreateTable(jsonValuesTableName,
 							GRN_OBJ_TABLE_HASH_KEY,
-							grn_ctx_at(ctx, GRN_DB_SHORT_TEXT));
+							grn_ctx_at(ctx, GRN_DB_UINT64));
 		GRN_PTR_PUT(ctx, data->supplementaryTables, data->jsonValuesTable);
 	}
 
@@ -2098,16 +2100,16 @@ PGrnInsertJSONDataFin(PGrnInsertJSONData *data)
 	grn_obj_unlink(ctx, data->jsonPathsTable);
 }
 
-static void
+static uint64_t
 PGrnInsertJSONGenerateKey(PGrnInsertJSONData *data,
 						  bool haveValue,
 						  const char *typeName)
 {
-	/* TODO: Use hashed value as key to support 4KiB over key. */
 	unsigned int i, n;
 
 	GRN_BULK_REWIND(&(data->key));
 
+	GRN_TEXT_PUTS(ctx, &(data->key), ".");
 	n = grn_vector_size(ctx, &(data->components));
 	for (i = 0; i < n; i++)
 	{
@@ -2120,7 +2122,8 @@ PGrnInsertJSONGenerateKey(PGrnInsertJSONData *data,
 											   &component,
 											   NULL,
 											   NULL);
-		GRN_TEXT_PUTS(ctx, &(data->key), ".");
+		if (i > 0)
+			GRN_TEXT_PUTS(ctx, &(data->key), ".");
 		GRN_TEXT_PUT(ctx, &(data->key), component, componentSize);
 	}
 
@@ -2132,6 +2135,10 @@ PGrnInsertJSONGenerateKey(PGrnInsertJSONData *data,
 		GRN_TEXT_PUTS(ctx, &(data->key), "|");
 		grn_obj_cast(ctx, &(data->value), &(data->key), GRN_FALSE);
 	}
+
+	return XXH64(GRN_TEXT_VALUE(&data->key),
+				 GRN_TEXT_LEN(&data->key),
+				 0);
 }
 
 static void
@@ -2228,13 +2235,13 @@ PGrnInsertJSONValueSet(PGrnInsertJSONData *data,
 					   grn_obj *column,
 					   const char *typeName)
 {
+	uint64_t key;
 	grn_id valueID;
 	int added;
 
-	PGrnInsertJSONGenerateKey(data, column != NULL, typeName);
+	key = PGrnInsertJSONGenerateKey(data, column != NULL, typeName);
 	valueID = grn_table_add(ctx, data->jsonValuesTable,
-							GRN_TEXT_VALUE(&(data->key)),
-							GRN_TEXT_LEN(&(data->key)),
+							&key, sizeof(uint64_t),
 							&added);
 	GRN_RECORD_PUT(ctx, data->valueIDs, valueID);
 	if (!added)

  Added: vendor/xxHash (+1 -0) 160000
===================================================================
--- /dev/null
+++ vendor/xxHash    2015-09-26 22:01:40 +0900 (44a6297)
@@ -0,0 +1 @@
+Subproject commit 44a6297b298e59ab7452defe859f21ed8371aa1c
-------------- next part --------------
HTML����������������������������...
Descargar 



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