[Groonga-commit] pgroonga/pgroonga at 42144cc [master] Reduce exported function

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Feb 14 21:45:07 JST 2015


Kouhei Sutou	2015-02-14 21:45:07 +0900 (Sat, 14 Feb 2015)

  New Revision: 42144cc2ce5c851c1e0324539c99a80a448b55f5
  https://github.com/pgroonga/pgroonga/commit/42144cc2ce5c851c1e0324539c99a80a448b55f5

  Message:
    Reduce exported function

  Modified files:
    pgroonga.c
    pgroonga.h
    pgroonga.sql
    pgroonga_types.c

  Modified: pgroonga.c (+65 -11)
===================================================================
--- pgroonga.c    2015-02-14 21:28:50 +0900 (3128c47)
+++ pgroonga.c    2015-02-14 21:45:07 +0900 (075eff5)
@@ -10,6 +10,7 @@
 #include <catalog/catalog.h>
 #include <catalog/index.h>
 #include <catalog/pg_tablespace.h>
+#include <catalog/pg_type.h>
 #include <lib/ilist.h>
 #include <mb/pg_wchar.h>
 #include <miscadmin.h>
@@ -366,22 +367,75 @@ PGrnCheck(const char *message)
 	return GRN_FALSE;
 }
 
-/*
- * Support functions and type-specific routines
- */
-
 static grn_id
 PGrnGetType(Relation index, AttrNumber n)
 {
-	FmgrInfo *function;
 	TupleDesc desc = RelationGetDescr(index);
-	Datum type;
+	Form_pg_attribute attr;
+	grn_id typeID = GRN_ID_NIL;
+	int32 maxlen;
+
+	attr = desc->attrs[n];
+
+	/* TODO: support array and record types. */
+	switch (attr->atttypid)
+	{
+	case BOOLOID:
+		typeID = GRN_DB_BOOL;
+		break;
+	case INT2OID:
+		typeID = GRN_DB_INT16;
+		break;
+	case INT4OID:
+		typeID = GRN_DB_INT32;
+		break;
+	case INT8OID:
+		typeID = GRN_DB_INT64;
+		break;
+	case FLOAT4OID:
+	case FLOAT8OID:
+		typeID = GRN_DB_FLOAT;
+		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
+		break;
+	case TEXTOID:
+	case XMLOID:
+		typeID = GRN_DB_LONG_TEXT;
+		break;
+	case BPCHAROID:
+	case VARCHAROID:
+		maxlen = type_maximum_size(attr->atttypid, attr->atttypmod);
+		if (maxlen >= 0)
+		{
+			if (maxlen < 4096)
+				typeID = GRN_DB_SHORT_TEXT;	/* 4KB */
+			if (maxlen < 64 * 1024)
+				typeID = GRN_DB_TEXT;			/* 64KB */
+		}
+		else
+		{
+			typeID = GRN_DB_LONG_TEXT;
+		}
+		break;
+#ifdef NOT_USED
+	case POINTOID:
+		typeID = GRN_DB_TOKYO_GEO_POINT or GRN_DB_WGS84_GEO_POINT;
+		break;
+#endif
+	default:
+		ereport(ERROR,
+				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+				 errmsg("pgroonga: unsupported type: %u", attr->atttypid)));
+		break;
+	}
 
-	function = index_getprocinfo(index, n + 1, PGrnTypeOfProc);
-	type = FunctionCall2(function,
-						 ObjectIdGetDatum(desc->attrs[n]->atttypid),
-						 Int32GetDatum(desc->attrs[n]->atttypmod));
-	return DatumGetInt32(type);
+	return typeID;
 }
 
 static void

  Modified: pgroonga.h (+1 -3)
===================================================================
--- pgroonga.h    2015-02-14 21:28:50 +0900 (d7d7311)
+++ pgroonga.h    2015-02-14 21:45:07 +0900 (a1c6399)
@@ -32,8 +32,7 @@
 #define PGrnQueryStrategyNumber			8	/* operator @@ (Groonga query) */
 
 /* Groonga support functions */
-#define PGrnTypeOfProc					1
-#define PGrnGetValueProc				2
+#define PGrnGetValueProc				1
 
 /* file and table names */
 #define PGrnDatabaseBasename			"pgrn"
@@ -69,7 +68,6 @@ extern Datum PGDLLEXPORT pgroonga_options(PG_FUNCTION_ARGS);
 /* in groonga_types.c */
 int pgroonga_bpchar_size(const BpChar *bpchar);
 
-extern Datum PGDLLEXPORT pgroonga_typeof(PG_FUNCTION_ARGS);
 extern Datum PGDLLEXPORT pgroonga_get_text(PG_FUNCTION_ARGS);
 extern Datum PGDLLEXPORT pgroonga_get_bpchar(PG_FUNCTION_ARGS);
 extern Datum PGDLLEXPORT pgroonga_get_bool(PG_FUNCTION_ARGS);

  Modified: pgroonga.sql (+12 -28)
===================================================================
--- pgroonga.sql    2015-02-14 21:28:50 +0900 (1fd1c68)
+++ pgroonga.sql    2015-02-14 21:45:07 +0900 (5baaee4)
@@ -126,10 +126,6 @@ CREATE FUNCTION pgroonga.options(internal)
 	AS 'MODULE_PATHNAME', 'pgroonga_options'
 	LANGUAGE C;
 
-CREATE FUNCTION pgroonga.typeof(oid, integer)
-	RETURNS integer
-	AS 'MODULE_PATHNAME', 'pgroonga_typeof'
-	LANGUAGE C;
 CREATE FUNCTION pgroonga.get_text(internal, internal, text)
 	RETURNS void
 	AS 'MODULE_PATHNAME', 'pgroonga_get_text'
@@ -210,8 +206,7 @@ CREATE OPERATOR CLASS pgroonga.full_text_search_text_ops DEFAULT FOR TYPE text
 		OPERATOR 6 pg_catalog.~~,
 		OPERATOR 7 %%,
 		OPERATOR 8 @@,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_text(internal, internal, text);
+		FUNCTION 1 pgroonga.get_text(internal, internal, text);
 
 CREATE OPERATOR CLASS pgroonga.text_ops FOR TYPE text
 	USING pgroonga AS
@@ -220,15 +215,13 @@ CREATE OPERATOR CLASS pgroonga.text_ops FOR TYPE text
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_text(internal, internal, text);
+		FUNCTION 1 pgroonga.get_text(internal, internal, text);
 
 CREATE OPERATOR CLASS pgroonga.full_text_search_bpchar_ops DEFAULT FOR TYPE bpchar
 	USING pgroonga AS
 		OPERATOR 7 %%,
 		OPERATOR 8 @@,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_bpchar(internal, internal, bpchar);
+		FUNCTION 1 pgroonga.get_bpchar(internal, internal, bpchar);
 
 CREATE OPERATOR CLASS pgroonga.bpchar_ops FOR TYPE bpchar
 	USING pgroonga AS
@@ -237,8 +230,7 @@ CREATE OPERATOR CLASS pgroonga.bpchar_ops FOR TYPE bpchar
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_bpchar(internal, internal, bpchar);
+		FUNCTION 1 pgroonga.get_bpchar(internal, internal, bpchar);
 
 CREATE OPERATOR CLASS pgroonga.bool_ops DEFAULT FOR TYPE bool
 	USING pgroonga AS
@@ -247,8 +239,7 @@ CREATE OPERATOR CLASS pgroonga.bool_ops DEFAULT FOR TYPE bool
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_bool(internal, internal, bool);
+		FUNCTION 1 pgroonga.get_bool(internal, internal, bool);
 
 CREATE OPERATOR CLASS pgroonga.int2_ops DEFAULT FOR TYPE int2
 	USING pgroonga AS
@@ -257,8 +248,7 @@ CREATE OPERATOR CLASS pgroonga.int2_ops DEFAULT FOR TYPE int2
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_int2(internal, internal, int2);
+		FUNCTION 1 pgroonga.get_int2(internal, internal, int2);
 
 CREATE OPERATOR CLASS pgroonga.int4_ops DEFAULT FOR TYPE int4
 	USING pgroonga AS
@@ -267,8 +257,7 @@ CREATE OPERATOR CLASS pgroonga.int4_ops DEFAULT FOR TYPE int4
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_int4(internal, internal, int4);
+		FUNCTION 1 pgroonga.get_int4(internal, internal, int4);
 
 CREATE OPERATOR CLASS pgroonga.int8_ops DEFAULT FOR TYPE int8
 	USING pgroonga AS
@@ -277,8 +266,7 @@ CREATE OPERATOR CLASS pgroonga.int8_ops DEFAULT FOR TYPE int8
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_int8(internal, internal, int8);
+		FUNCTION 1 pgroonga.get_int8(internal, internal, int8);
 
 CREATE OPERATOR CLASS pgroonga.float4_ops DEFAULT FOR TYPE float4
 	USING pgroonga AS
@@ -287,8 +275,7 @@ CREATE OPERATOR CLASS pgroonga.float4_ops DEFAULT FOR TYPE float4
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_float4(internal, internal, float4);
+		FUNCTION 1 pgroonga.get_float4(internal, internal, float4);
 
 CREATE OPERATOR CLASS pgroonga.float8_ops DEFAULT FOR TYPE float8
 	USING pgroonga AS
@@ -297,8 +284,7 @@ CREATE OPERATOR CLASS pgroonga.float8_ops DEFAULT FOR TYPE float8
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_float8(internal, internal, float8);
+		FUNCTION 1 pgroonga.get_float8(internal, internal, float8);
 
 CREATE OPERATOR CLASS pgroonga.timestamp_ops DEFAULT FOR TYPE timestamp
 	USING pgroonga AS
@@ -307,8 +293,7 @@ CREATE OPERATOR CLASS pgroonga.timestamp_ops DEFAULT FOR TYPE timestamp
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_timestamp(internal, internal, timestamp);
+		FUNCTION 1 pgroonga.get_timestamp(internal, internal, timestamp);
 
 CREATE OPERATOR CLASS pgroonga.timestamptz_ops DEFAULT FOR TYPE timestamptz
 	USING pgroonga AS
@@ -317,5 +302,4 @@ CREATE OPERATOR CLASS pgroonga.timestamptz_ops DEFAULT FOR TYPE timestamptz
 		OPERATOR 3 =,
 		OPERATOR 4 >=,
 		OPERATOR 5 >,
-		FUNCTION 1 pgroonga.typeof(oid, integer),
-		FUNCTION 2 pgroonga.get_timestamptz(internal, internal, timestamptz);
+		FUNCTION 1 pgroonga.get_timestamptz(internal, internal, timestamptz);

  Modified: pgroonga_types.c (+0 -60)
===================================================================
--- pgroonga_types.c    2015-02-14 21:28:50 +0900 (fce22e4)
+++ pgroonga_types.c    2015-02-14 21:45:07 +0900 (91bf27c)
@@ -26,7 +26,6 @@ pgroonga_bpchar_size(const BpChar *arg)
 	return i + 1;
 }
 
-PG_FUNCTION_INFO_V1(pgroonga_typeof);
 PG_FUNCTION_INFO_V1(pgroonga_get_text);
 PG_FUNCTION_INFO_V1(pgroonga_get_bpchar);
 PG_FUNCTION_INFO_V1(pgroonga_get_bool);
@@ -48,65 +47,6 @@ PG_FUNCTION_INFO_V1(pgroonga_set_float8);
 PG_FUNCTION_INFO_V1(pgroonga_set_timestamp);
 PG_FUNCTION_INFO_V1(pgroonga_set_timestamptz);
 
-/**
- * pgroonga_typeof -- map a postgres' built-in type to a Groonga's type
- *
- * Raises ERROR if no corresponding types found.
- */
-Datum
-pgroonga_typeof(PG_FUNCTION_ARGS)
-{
-	Oid		typid = PG_GETARG_OID(0);
-	int		typmod = PG_GETARG_INT32(1);
-	int32	maxlen;
-
-	/* TODO: support array and record types. */
-	switch (typid)
-	{
-		case BOOLOID:
-			return GRN_DB_BOOL;
-		case INT2OID:
-			return GRN_DB_INT16;
-		case INT4OID:
-			return GRN_DB_INT32;
-		case INT8OID:
-			return GRN_DB_INT64;
-		case FLOAT4OID:
-		case FLOAT8OID:
-			return GRN_DB_FLOAT;
-		case TIMESTAMPOID:
-		case TIMESTAMPTZOID:
-#ifdef HAVE_INT64_TIMESTAMP
-			return GRN_DB_INT64;	/* FIXME: use GRN_DB_TIME instead */
-#else
-			return GRN_DB_FLOAT;
-#endif
-		case TEXTOID:
-		case XMLOID:
-			return GRN_DB_LONG_TEXT;
-		case BPCHAROID:
-		case VARCHAROID:
-			maxlen = type_maximum_size(typid, typmod);
-			if (maxlen >= 0)
-			{
-				if (maxlen < 4096)
-					return GRN_DB_SHORT_TEXT;	/* 4KB */
-				if (maxlen < 64 * 1024)
-					return GRN_DB_TEXT;			/* 64KB */
-			}
-			return GRN_DB_LONG_TEXT;
-#ifdef NOT_USED
-		case POINTOID:
-			return GRN_DB_TOKYO_GEO_POINT or GRN_DB_WGS84_GEO_POINT;
-#endif
-		default:
-			ereport(ERROR,
-				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-					errmsg("Groonga: unsupported type: %u", typid)));
-			return GRN_DB_VOID;	/* keep compiler quiet */
-	}
-}
-
 Datum
 pgroonga_get_text(PG_FUNCTION_ARGS)
 {
-------------- next part --------------
HTML����������������������������...
Download 



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