Kouhei Sutou
null+****@clear*****
Tue Feb 9 16:37:17 JST 2016
Kouhei Sutou 2016-02-09 16:37:17 +0900 (Tue, 09 Feb 2016) New Revision: b843ccaf23baedb7ff95b5e8cb678011ee58bcce https://github.com/pgroonga/pgroonga/commit/b843ccaf23baedb7ff95b5e8cb678011ee58bcce Message: v2: support match (&@) and query (&?) Added files: expected/full-text-search/text/single/match-v2/bitmapscan.out expected/full-text-search/text/single/match-v2/indexscan.out expected/full-text-search/text/single/match-v2/seqscan.out expected/full-text-search/text/single/query-v2/bitmapscan.out expected/full-text-search/text/single/query-v2/indexscan.out expected/full-text-search/text/single/query-v2/seqscan.out sql/full-text-search/text/single/match-v2/bitmapscan.sql sql/full-text-search/text/single/match-v2/indexscan.sql sql/full-text-search/text/single/match-v2/seqscan.sql sql/full-text-search/text/single/query-v2/bitmapscan.sql sql/full-text-search/text/single/query-v2/indexscan.sql sql/full-text-search/text/single/query-v2/seqscan.sql Modified files: pgroonga.sql src/pgroonga.c src/pgroonga.h Added: expected/full-text-search/text/single/match-v2/bitmapscan.out (+22 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/single/match-v2/bitmapscan.out 2016-02-09 16:37:17 +0900 (c9feae5) @@ -0,0 +1,22 @@ +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; +SELECT id, content + FROM memos + WHERE content &@ 'Groonga'; + id | content +----+------------------------------------------------------- + 2 | Groonga is fast full text search engine. + 3 | PGroonga is a PostgreSQL extension that uses Groonga. +(2 rows) + +DROP TABLE memos; Added: expected/full-text-search/text/single/match-v2/indexscan.out (+22 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/single/match-v2/indexscan.out 2016-02-09 16:37:17 +0900 (ffdc2c9) @@ -0,0 +1,22 @@ +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT id, content + FROM memos + WHERE content &@ 'Groonga'; + id | content +----+------------------------------------------------------- + 2 | Groonga is fast full text search engine. + 3 | PGroonga is a PostgreSQL extension that uses Groonga. +(2 rows) + +DROP TABLE memos; Added: expected/full-text-search/text/single/match-v2/seqscan.out (+22 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/single/match-v2/seqscan.out 2016-02-09 16:37:17 +0900 (b14508d) @@ -0,0 +1,22 @@ +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; +SELECT id, content + FROM memos + WHERE content &@ 'Groonga'; + id | content +----+------------------------------------------------------- + 2 | Groonga is fast full text search engine. + 3 | PGroonga is a PostgreSQL extension that uses Groonga. +(2 rows) + +DROP TABLE memos; Added: expected/full-text-search/text/single/query-v2/bitmapscan.out (+22 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/single/query-v2/bitmapscan.out 2016-02-09 16:37:17 +0900 (fe45e47) @@ -0,0 +1,22 @@ +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; +SELECT id, content + FROM memos + WHERE content &? 'rdbms OR engine'; + id | content +----+------------------------------------------ + 1 | PostgreSQL is a RDBMS. + 2 | Groonga is fast full text search engine. +(2 rows) + +DROP TABLE memos; Added: expected/full-text-search/text/single/query-v2/indexscan.out (+22 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/single/query-v2/indexscan.out 2016-02-09 16:37:17 +0900 (6caf0ef) @@ -0,0 +1,22 @@ +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT id, content + FROM memos + WHERE content &? 'rdbms OR engine'; + id | content +----+------------------------------------------ + 1 | PostgreSQL is a RDBMS. + 2 | Groonga is fast full text search engine. +(2 rows) + +DROP TABLE memos; Added: expected/full-text-search/text/single/query-v2/seqscan.out (+23 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/single/query-v2/seqscan.out 2016-02-09 16:37:17 +0900 (6ccbba1) @@ -0,0 +1,23 @@ +SET search_path = "$user",public,pgroonga,pg_catalog; +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; +SELECT id, content + FROM memos + WHERE content &? 'rdbms OR engine'; + id | content +----+------------------------------------------ + 1 | PostgreSQL is a RDBMS. + 2 | Groonga is fast full text search engine. +(2 rows) + +DROP TABLE memos; Modified: pgroonga.sql (+36 -8) =================================================================== --- pgroonga.sql 2016-02-09 16:12:48 +0900 (291564f) +++ pgroonga.sql 2016-02-09 16:37:17 +0900 (d082421) @@ -206,7 +206,7 @@ CREATE FUNCTION pgroonga.options(internal) DELETE FROM pg_catalog.pg_am WHERE amname = 'pgroonga'; INSERT INTO pg_catalog.pg_am VALUES( 'pgroonga', -- amname - 13, -- amstrategies + 15, -- amstrategies 0, -- amsupport true, -- amcanorder true, -- amcanorderbyop @@ -375,17 +375,30 @@ CREATE OPERATOR CLASS pgroonga.varchar_regexp_ops FOR TYPE varchar /* v2 */ -CREATE FUNCTION pgroonga.query_contain_text(text, text[]) +CREATE FUNCTION pgroonga.match_text(text, text) RETURNS bool - AS 'MODULE_PATHNAME', 'pgroonga_query_contain_text' + AS 'MODULE_PATHNAME', 'pgroonga_match_text' LANGUAGE C IMMUTABLE STRICT; -CREATE OPERATOR &?> ( - PROCEDURE = pgroonga.query_contain_text, +CREATE OPERATOR &@ ( + PROCEDURE = pgroonga.match_text, LEFTARG = text, - RIGHTARG = text[] + RIGHTARG = text +); + +CREATE FUNCTION pgroonga.query_text(text, text) + RETURNS bool + AS 'MODULE_PATHNAME', 'pgroonga_query_text' + LANGUAGE C + IMMUTABLE + STRICT; + +CREATE OPERATOR &? ( + PROCEDURE = pgroonga.query_text, + LEFTARG = text, + RIGHTARG = text ); CREATE FUNCTION pgroonga.match_contain_text(text, text[]) @@ -401,9 +414,24 @@ CREATE OPERATOR &@> ( RIGHTARG = text[] ); +CREATE FUNCTION pgroonga.query_contain_text(text, text[]) + RETURNS bool + AS 'MODULE_PATHNAME', 'pgroonga_query_contain_text' + LANGUAGE C + IMMUTABLE + STRICT; + +CREATE OPERATOR &?> ( + PROCEDURE = pgroonga.query_contain_text, + LEFTARG = text, + RIGHTARG = text[] +); + CREATE OPERATOR CLASS pgroonga.text_full_text_search_ops_v2 FOR TYPE text USING pgroonga AS OPERATOR 6 pg_catalog.~~, OPERATOR 7 pg_catalog.~~*, - OPERATOR 12 &?> (text, text[]), - OPERATOR 13 &@> (text, text[]); + OPERATOR 12 &@, + OPERATOR 13 &?, + OPERATOR 14 &@> (text, text[]), + OPERATOR 15 &?> (text, text[]); Added: sql/full-text-search/text/single/match-v2/bitmapscan.sql (+21 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/single/match-v2/bitmapscan.sql 2016-02-09 16:37:17 +0900 (09b5d8d) @@ -0,0 +1,21 @@ +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); + +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; + +SELECT id, content + FROM memos + WHERE content &@ 'Groonga'; + +DROP TABLE memos; Added: sql/full-text-search/text/single/match-v2/indexscan.sql (+21 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/single/match-v2/indexscan.sql 2016-02-09 16:37:17 +0900 (d93bf5e) @@ -0,0 +1,21 @@ +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); + +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id, content + FROM memos + WHERE content &@ 'Groonga'; + +DROP TABLE memos; Added: sql/full-text-search/text/single/match-v2/seqscan.sql (+21 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/single/match-v2/seqscan.sql 2016-02-09 16:37:17 +0900 (ad6c31a) @@ -0,0 +1,21 @@ +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); + +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); + +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; + +SELECT id, content + FROM memos + WHERE content &@ 'Groonga'; + +DROP TABLE memos; Added: sql/full-text-search/text/single/query-v2/bitmapscan.sql (+21 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/single/query-v2/bitmapscan.sql 2016-02-09 16:37:17 +0900 (d321b33) @@ -0,0 +1,21 @@ +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); + +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; + +SELECT id, content + FROM memos + WHERE content &? 'rdbms OR engine'; + +DROP TABLE memos; Added: sql/full-text-search/text/single/query-v2/indexscan.sql (+21 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/single/query-v2/indexscan.sql 2016-02-09 16:37:17 +0900 (aa2c7af) @@ -0,0 +1,21 @@ +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); + +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id, content + FROM memos + WHERE content &? 'rdbms OR engine'; + +DROP TABLE memos; Added: sql/full-text-search/text/single/query-v2/seqscan.sql (+23 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/single/query-v2/seqscan.sql 2016-02-09 16:37:17 +0900 (a2d3f6c) @@ -0,0 +1,23 @@ +SET search_path = "$user",public,pgroonga,pg_catalog; + +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.'); +INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.'); +INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.'); + +CREATE INDEX grnindex ON memos + USING pgroonga (content pgroonga.text_full_text_search_ops_v2); + +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; + +SELECT id, content + FROM memos + WHERE content &? 'rdbms OR engine'; + +DROP TABLE memos; Modified: src/pgroonga.c (+74 -24) =================================================================== --- src/pgroonga.c 2016-02-09 16:12:48 +0900 (0309312) +++ src/pgroonga.c 2016-02-09 16:37:17 +0900 (6b9757e) @@ -137,8 +137,10 @@ PG_FUNCTION_INFO_V1(pgroonga_match_regexp_text); PG_FUNCTION_INFO_V1(pgroonga_match_regexp_varchar); /* v2 */ -PG_FUNCTION_INFO_V1(pgroonga_query_contain_text); +PG_FUNCTION_INFO_V1(pgroonga_match_text); +PG_FUNCTION_INFO_V1(pgroonga_query_text); PG_FUNCTION_INFO_V1(pgroonga_match_contain_text); +PG_FUNCTION_INFO_V1(pgroonga_query_contain_text); PG_FUNCTION_INFO_V1(pgroonga_insert); PG_FUNCTION_INFO_V1(pgroonga_beginscan); @@ -557,7 +559,17 @@ PGrnIsQueryStrategyIndex(Relation index, int nthAttribute) leftType, rightType, PGrnQueryStrategyNumber); - return OidIsValid(strategyOID); + if (OidIsValid(strategyOID)) + return true; + + strategyOID = get_opfamily_member(index->rd_opfamily[nthAttribute], + leftType, + rightType, + PGrnQueryStrategyV2Number); + if (OidIsValid(strategyOID)) + return true; + + return false; } static bool @@ -1465,41 +1477,42 @@ pgroonga_match_regexp_varchar(PG_FUNCTION_ARGS) /* v2 */ /** - * pgroonga.query_contain(target text, queries text[]) : bool + * pgroonga.match_text(target text, term text) : bool */ Datum -pgroonga_query_contain_text(PG_FUNCTION_ARGS) +pgroonga_match_text(PG_FUNCTION_ARGS) { text *target = PG_GETARG_TEXT_PP(0); - ArrayType *queries = PG_GETARG_ARRAYTYPE_P(1); + text *term = PG_GETARG_TEXT_PP(1); grn_bool matched; - int i, n; - n = ARR_DIMS(queries)[0]; - for (i = 1; i <= n; i++) - { - Datum queryDatum; - text *query; - bool isNULL; + matched = pgroonga_match_term_raw(VARDATA_ANY(target), + VARSIZE_ANY_EXHDR(target), + VARDATA_ANY(term), + VARSIZE_ANY_EXHDR(term)); + PG_RETURN_BOOL(matched); +} - queryDatum = array_ref(queries, 1, &i, -1, -1, false, 'i', &isNULL); - if (isNULL) - continue; +/** + * pgroonga.query_text(target text, query text) : bool + */ +Datum +pgroonga_query_text(PG_FUNCTION_ARGS) +{ + text *target = PG_GETARG_TEXT_PP(0); + text *query = PG_GETARG_TEXT_PP(1); + bool matched = false; - query = DatumGetTextPP(queryDatum); - matched = pgroonga_match_query_raw(VARDATA_ANY(target), - VARSIZE_ANY_EXHDR(target), - VARDATA_ANY(query), - VARSIZE_ANY_EXHDR(query)); - if (matched) - break; - } + matched = pgroonga_match_query_raw(VARDATA_ANY(target), + VARSIZE_ANY_EXHDR(target), + VARDATA_ANY(query), + VARSIZE_ANY_EXHDR(query)); PG_RETURN_BOOL(matched); } /** - * pgroonga.match_contain(target text, keywords text[]) : bool + * pgroonga.match_contain_text(target text, keywords text[]) : bool */ Datum pgroonga_match_contain_text(PG_FUNCTION_ARGS) @@ -1532,6 +1545,40 @@ pgroonga_match_contain_text(PG_FUNCTION_ARGS) PG_RETURN_BOOL(matched); } +/** + * pgroonga.query_contain_text(target text, queries text[]) : bool + */ +Datum +pgroonga_query_contain_text(PG_FUNCTION_ARGS) +{ + text *target = PG_GETARG_TEXT_PP(0); + ArrayType *queries = PG_GETARG_ARRAYTYPE_P(1); + grn_bool matched; + int i, n; + + n = ARR_DIMS(queries)[0]; + for (i = 1; i <= n; i++) + { + Datum queryDatum; + text *query; + bool isNULL; + + queryDatum = array_ref(queries, 1, &i, -1, -1, false, 'i', &isNULL); + if (isNULL) + continue; + + query = DatumGetTextPP(queryDatum); + matched = pgroonga_match_query_raw(VARDATA_ANY(target), + VARSIZE_ANY_EXHDR(target), + VARDATA_ANY(query), + VARSIZE_ANY_EXHDR(query)); + if (matched) + break; + } + + PG_RETURN_BOOL(matched); +} + static void PGrnInsert(Relation index, grn_obj *sourcesTable, @@ -2127,9 +2174,11 @@ PGrnSearchBuildCondition(IndexScanDesc scan, case PGrnILikeStrategyNumber: break; case PGrnMatchStrategyNumber: + case PGrnMatchStrategyV2Number: operator = GRN_OP_MATCH; break; case PGrnQueryStrategyNumber: + case PGrnQueryStrategyV2Number: break; case PGrnRegexpStrategyNumber: operator = GRN_OP_REGEXP; @@ -2171,6 +2220,7 @@ PGrnSearchBuildCondition(IndexScanDesc scan, PGrnSearchBuildConditionLikeMatch(data, targetColumn, &(buffers->general)); break; case PGrnQueryStrategyNumber: + case PGrnQueryStrategyV2Number: PGrnSearchBuildConditionQuery(so, data, targetColumn, Modified: src/pgroonga.h (+10 -2) =================================================================== --- src/pgroonga.h 2016-02-09 16:12:48 +0900 (322d0ad) +++ src/pgroonga.h 2016-02-09 16:37:17 +0900 (c915668) @@ -24,8 +24,10 @@ #define PGrnRegexpStrategyNumber 10 /* operator @~ (@~ in Groonga) */ #define PGrnJSONContainStrategyNumber 11 /* operator @> */ -#define PGrnQueryContainStrategyNumber 12 /* operator &?> (query in Groonga) */ -#define PGrnMatchContainStrategyNumber 13 /* operator &@> (@ in Groonga) */ +#define PGrnMatchStrategyV2Number 12 /* operator &@ (@ in Groonga) */ +#define PGrnQueryStrategyV2Number 13 /* operator &? (query in Groonga) */ +#define PGrnMatchContainStrategyNumber 14 /* operator &@> (@ in Groonga) */ +#define PGrnQueryContainStrategyNumber 15 /* operator &?> (query in Groonga) */ /* file and table names */ #define PGrnLogBasename "pgroonga.log" @@ -62,6 +64,12 @@ extern Datum PGDLLEXPORT pgroonga_match_regexp_text(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_match_regexp_varchar(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_match_jsonb(PG_FUNCTION_ARGS); +/* v2 */ +extern Datum PGDLLEXPORT pgroonga_match_text(PG_FUNCTION_ARGS); +extern Datum PGDLLEXPORT pgroonga_query_text(PG_FUNCTION_ARGS); +extern Datum PGDLLEXPORT pgroonga_match_contain_text(PG_FUNCTION_ARGS); +extern Datum PGDLLEXPORT pgroonga_query_contain_text(PG_FUNCTION_ARGS); + extern Datum PGDLLEXPORT pgroonga_insert(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_beginscan(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_gettuple(PG_FUNCTION_ARGS); -------------- next part -------------- HTML����������������������������...Download