Kouhei Sutou
null+****@clear*****
Wed Feb 4 23:19:24 JST 2015
Kouhei Sutou 2015-02-04 23:19:24 +0900 (Wed, 04 Feb 2015) New Revision: 711cd5911aba4b5e1e43503bce02d849cb01abc2 https://github.com/pgroonga/pgroonga/commit/711cd5911aba4b5e1e43503bce02d849cb01abc2 Message: Support text index for no full-text search Added files: expected/compare/text/single/equal/bitmapscan.out expected/compare/text/single/equal/indexscan.out expected/compare/text/single/equal/seqscan.out sql/compare/text/single/equal/bitmapscan.sql sql/compare/text/single/equal/indexscan.sql sql/compare/text/single/equal/seqscan.sql Modified files: Makefile pgroonga.c test.sql Modified: Makefile (+3 -0) =================================================================== --- Makefile 2015-02-04 23:02:03 +0900 (de72634) +++ Makefile 2015-02-04 23:19:24 +0900 (5e24890) @@ -31,6 +31,7 @@ installcheck: results/full-text-search/text/single/and installcheck: results/full-text-search/text/multiple/contain installcheck: results/full-text-search/text/options/tokenizer installcheck: results/full-text-search/text/options/normalizer +installcheck: results/compare/text/single/equal results/full-text-search/text/single/contain: @mkdir -p results/full-text-search/text/single/contain @@ -44,3 +45,5 @@ results/full-text-search/text/options/tokenizer: @mkdir -p results/full-text-search/text/options/tokenizer results/full-text-search/text/options/normalizer: @mkdir -p results/full-text-search/text/options/normalizer +results/compare/text/single/equal: + @mkdir -p $@ Added: expected/compare/text/single/equal/bitmapscan.out (+21 -0) 100644 =================================================================== --- /dev/null +++ expected/compare/text/single/equal/bitmapscan.out 2015-02-04 23:19:24 +0900 (6455400) @@ -0,0 +1,21 @@ +CREATE TABLE memos ( + id integer, + title text +); +INSERT INTO memos VALUES (1, 'PostgreSQL'); +INSERT INTO memos VALUES (2, 'Groonga'); +INSERT INTO memos VALUES (3, 'PGroonga'); +CREATE INDEX grnindex ON memos USING pgroonga (content pgroonga.text_ops); +ERROR: column "content" does not exist +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; +SELECT id, title + FROM memos + WHERE title = 'Groonga'; + id | title +----+--------- + 2 | Groonga +(1 row) + +DROP TABLE memos; Added: expected/compare/text/single/equal/indexscan.out (+21 -0) 100644 =================================================================== --- /dev/null +++ expected/compare/text/single/equal/indexscan.out 2015-02-04 23:19:24 +0900 (7138d51) @@ -0,0 +1,21 @@ +CREATE TABLE memos ( + id integer, + title text +); +INSERT INTO memos VALUES (1, 'PostgreSQL'); +INSERT INTO memos VALUES (2, 'Groonga'); +INSERT INTO memos VALUES (3, 'PGroonga'); +CREATE INDEX grnindex ON memos USING pgroonga (content pgroonga.text_ops); +ERROR: column "content" does not exist +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT id, title + FROM memos + WHERE title = 'Groonga'; + id | title +----+--------- + 2 | Groonga +(1 row) + +DROP TABLE memos; Added: expected/compare/text/single/equal/seqscan.out (+21 -0) 100644 =================================================================== --- /dev/null +++ expected/compare/text/single/equal/seqscan.out 2015-02-04 23:19:24 +0900 (745f030) @@ -0,0 +1,21 @@ +CREATE TABLE memos ( + id integer, + title text +); +INSERT INTO memos VALUES (1, 'PostgreSQL'); +INSERT INTO memos VALUES (2, 'Groonga'); +INSERT INTO memos VALUES (3, 'PGroonga'); +CREATE INDEX grnindex ON memos USING pgroonga (content pgroonga.text_ops); +ERROR: column "content" does not exist +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; +SELECT id, title + FROM memos + WHERE title = 'Groonga'; + id | title +----+--------- + 2 | Groonga +(1 row) + +DROP TABLE memos; Modified: pgroonga.c (+13 -2) =================================================================== --- pgroonga.c 2015-02-04 23:02:03 +0900 (0e28e12) +++ pgroonga.c 2015-02-04 23:19:24 +0900 (b28525c) @@ -14,6 +14,7 @@ #include <miscadmin.h> #include <storage/ipc.h> #include <storage/lmgr.h> +#include <utils/lsyscache.h> #include <utils/selfuncs.h> #include <groonga.h> @@ -439,6 +440,7 @@ PGrnCreate(Relation index, grn_obj **idsTable, int i; TupleDesc desc; Oid relNode = index->rd_node.relNode; + bool forFullTextSearch = false; desc = RelationGetDescr(index); @@ -484,6 +486,15 @@ PGrnCreate(Relation index, grn_obj **idsTable, grn_ctx_at(ctx, attributeTypeID)); } + { + Oid containStrategyOID; + containStrategyOID = get_opfamily_member(index->rd_opfamily[0], + index->rd_opcintype[0], + index->rd_opcintype[0], + PGrnContainStrategyNumber); + forFullTextSearch = (containStrategyOID != InvalidOid); + } + switch (typeID) { case GRN_DB_TEXT: @@ -496,7 +507,7 @@ PGrnCreate(Relation index, grn_obj **idsTable, *lexicon = PGrnCreateTable(lexiconName, GRN_OBJ_TABLE_PAT_KEY, grn_ctx_at(ctx, typeID)); - if (typeID == GRN_DB_SHORT_TEXT) + if (forFullTextSearch) { PGrnOptions *options; const char *tokenizerName = PGRN_DEFAULT_TOKENIZER; @@ -522,7 +533,7 @@ PGrnCreate(Relation index, grn_obj **idsTable, { grn_obj_flags flags = GRN_OBJ_COLUMN_INDEX; - if (typeID == GRN_DB_SHORT_TEXT) + if (forFullTextSearch) flags |= GRN_OBJ_WITH_POSITION; if (desc->natts > 1) flags |= GRN_OBJ_WITH_SECTION; Added: sql/compare/text/single/equal/bitmapscan.sql (+20 -0) 100644 =================================================================== --- /dev/null +++ sql/compare/text/single/equal/bitmapscan.sql 2015-02-04 23:19:24 +0900 (3b460f6) @@ -0,0 +1,20 @@ +CREATE TABLE memos ( + id integer, + title text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL'); +INSERT INTO memos VALUES (2, 'Groonga'); +INSERT INTO memos VALUES (3, 'PGroonga'); + +CREATE INDEX grnindex ON memos USING pgroonga (content pgroonga.text_ops); + +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; + +SELECT id, title + FROM memos + WHERE title = 'Groonga'; + +DROP TABLE memos; Added: sql/compare/text/single/equal/indexscan.sql (+20 -0) 100644 =================================================================== --- /dev/null +++ sql/compare/text/single/equal/indexscan.sql 2015-02-04 23:19:24 +0900 (517c082) @@ -0,0 +1,20 @@ +CREATE TABLE memos ( + id integer, + title text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL'); +INSERT INTO memos VALUES (2, 'Groonga'); +INSERT INTO memos VALUES (3, 'PGroonga'); + +CREATE INDEX grnindex ON memos USING pgroonga (content pgroonga.text_ops); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id, title + FROM memos + WHERE title = 'Groonga'; + +DROP TABLE memos; Added: sql/compare/text/single/equal/seqscan.sql (+20 -0) 100644 =================================================================== --- /dev/null +++ sql/compare/text/single/equal/seqscan.sql 2015-02-04 23:19:24 +0900 (20f41aa) @@ -0,0 +1,20 @@ +CREATE TABLE memos ( + id integer, + title text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL'); +INSERT INTO memos VALUES (2, 'Groonga'); +INSERT INTO memos VALUES (3, 'PGroonga'); + +CREATE INDEX grnindex ON memos USING pgroonga (content pgroonga.text_ops); + +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; + +SELECT id, title + FROM memos + WHERE title = 'Groonga'; + +DROP TABLE memos; Modified: test.sql (+22 -0) =================================================================== --- test.sql 2015-02-04 23:02:03 +0900 (22f39f5) +++ test.sql 2015-02-04 23:19:24 +0900 (5038978) @@ -1,6 +1,28 @@ DROP TABLE IF EXISTS memos; CREATE TABLE memos ( id integer, + title text +); + +INSERT INTO memos VALUES (1, 'PostgreSQL'); +INSERT INTO memos VALUES (2, 'Groonga'); +INSERT INTO memos VALUES (3, 'PGroonga'); + +CREATE INDEX grnindex ON memos USING pgroonga (title pgroonga.text_ops); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id, title + FROM memos + WHERE title = 'Groonga'; + +DROP TABLE memos; + +DROP TABLE IF EXISTS memos; +CREATE TABLE memos ( + id integer, content text ); -------------- next part -------------- HTML����������������������������...Download