Navigation Menu

Skip to content

Commit

Permalink
Support ILIKE with index
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 28, 2015
1 parent b0e6879 commit 9ece27b
Show file tree
Hide file tree
Showing 26 changed files with 515 additions and 5 deletions.
21 changes: 21 additions & 0 deletions expected/full-text-search/text/single/ilike/begin/bitmapscan.out
@@ -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.');
INSERT INTO memos VALUES (4, 'groonga command is provided.');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = off;
SET enable_indexscan = off;
SET enable_bitmapscan = on;
SELECT id, content
FROM memos
WHERE content ILIKE 'POSTGRESQL%';
id | content
----+------------------------
1 | PostgreSQL is a RDBMS.
(1 row)

DROP TABLE memos;
21 changes: 21 additions & 0 deletions expected/full-text-search/text/single/ilike/begin/indexscan.out
@@ -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.');
INSERT INTO memos VALUES (4, 'groonga command is provided.');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = off;
SET enable_indexscan = on;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content ILIKE 'POSTGRESQL%';
id | content
----+------------------------
1 | PostgreSQL is a RDBMS.
(1 row)

DROP TABLE memos;
21 changes: 21 additions & 0 deletions expected/full-text-search/text/single/ilike/begin/seqscan.out
@@ -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.');
INSERT INTO memos VALUES (4, 'groonga command is provided.');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = on;
SET enable_indexscan = off;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content ILIKE 'POSTGRESQL%';
id | content
----+------------------------
1 | PostgreSQL is a RDBMS.
(1 row)

DROP TABLE memos;
21 changes: 21 additions & 0 deletions expected/full-text-search/text/single/ilike/end/bitmapscan.out
@@ -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');
INSERT INTO memos VALUES (4, 'groonga command is provided');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = off;
SET enable_indexscan = off;
SET enable_bitmapscan = on;
SELECT id, content
FROM memos
WHERE content ILIKE '%GROONGA';
id | content
----+------------------------------------------------------
3 | PGroonga is a PostgreSQL extension that uses Groonga
(1 row)

DROP TABLE memos;
21 changes: 21 additions & 0 deletions expected/full-text-search/text/single/ilike/end/indexscan.out
@@ -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');
INSERT INTO memos VALUES (4, 'groonga command is provided');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = off;
SET enable_indexscan = on;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content ILIKE '%GROONGA';
id | content
----+------------------------------------------------------
3 | PGroonga is a PostgreSQL extension that uses Groonga
(1 row)

DROP TABLE memos;
21 changes: 21 additions & 0 deletions expected/full-text-search/text/single/ilike/end/seqscan.out
@@ -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');
INSERT INTO memos VALUES (4, 'groonga command is provided');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = on;
SET enable_indexscan = off;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content ILIKE '%GROONGA';
id | content
----+------------------------------------------------------
3 | PGroonga is a PostgreSQL extension that uses Groonga
(1 row)

DROP TABLE memos;
23 changes: 23 additions & 0 deletions expected/full-text-search/text/single/ilike/partial/bitmapscan.out
@@ -0,0 +1,23 @@
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.');
INSERT INTO memos VALUES (4, 'groonga command is provided.');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = off;
SET enable_indexscan = off;
SET enable_bitmapscan = on;
SELECT id, content
FROM memos
WHERE content ILIKE '%GROONGA%';
id | content
----+-------------------------------------------------------
2 | Groonga is fast full text search engine.
3 | PGroonga is a PostgreSQL extension that uses Groonga.
4 | groonga command is provided.
(3 rows)

DROP TABLE memos;
23 changes: 23 additions & 0 deletions expected/full-text-search/text/single/ilike/partial/indexscan.out
@@ -0,0 +1,23 @@
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.');
INSERT INTO memos VALUES (4, 'groonga command is provided.');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = off;
SET enable_indexscan = on;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content ILIKE '%GROONGA%';
id | content
----+-------------------------------------------------------
2 | Groonga is fast full text search engine.
3 | PGroonga is a PostgreSQL extension that uses Groonga.
4 | groonga command is provided.
(3 rows)

DROP TABLE memos;
23 changes: 23 additions & 0 deletions expected/full-text-search/text/single/ilike/partial/seqscan.out
@@ -0,0 +1,23 @@
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.');
INSERT INTO memos VALUES (4, 'groonga command is provided.');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = on;
SET enable_indexscan = off;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content ILIKE '%GROONGA%';
id | content
----+-------------------------------------------------------
2 | Groonga is fast full text search engine.
3 | PGroonga is a PostgreSQL extension that uses Groonga.
4 | groonga command is provided.
(3 rows)

DROP TABLE memos;
@@ -0,0 +1,20 @@
CREATE TABLE memos (
id integer,
content text
);
INSERT INTO memos VALUES (1, '');
INSERT INTO memos VALUES (2, 'a');
INSERT INTO memos VALUES (3, 'ab');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = off;
SET enable_indexscan = off;
SET enable_bitmapscan = on;
SELECT id, content
FROM memos
WHERE content ILIKE '_';
id | content
----+---------
2 | a
(1 row)

DROP TABLE memos;
@@ -0,0 +1,20 @@
CREATE TABLE memos (
id integer,
content text
);
INSERT INTO memos VALUES (1, '');
INSERT INTO memos VALUES (2, 'a');
INSERT INTO memos VALUES (3, 'ab');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = off;
SET enable_indexscan = on;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content ILIKE '_';
id | content
----+---------
2 | a
(1 row)

DROP TABLE memos;
20 changes: 20 additions & 0 deletions expected/full-text-search/text/single/ilike/underscore/seqscan.out
@@ -0,0 +1,20 @@
CREATE TABLE memos (
id integer,
content text
);
INSERT INTO memos VALUES (1, '');
INSERT INTO memos VALUES (2, 'a');
INSERT INTO memos VALUES (3, 'ab');
CREATE INDEX grnindex ON memos USING pgroonga (content);
SET enable_seqscan = on;
SET enable_indexscan = off;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content ILIKE '_';
id | content
----+---------
2 | a
(1 row)

DROP TABLE memos;
9 changes: 7 additions & 2 deletions pgroonga.c
Expand Up @@ -3662,6 +3662,7 @@ PGrnSearchBuildCondition(IndexScanDesc scan,
operator = GRN_OP_GREATER;
break;
case PGrnLikeStrategyNumber:
case PGrnILikeStrategyNumber:
break;
case PGrnMatchStrategyNumber:
operator = GRN_OP_MATCH;
Expand All @@ -3687,7 +3688,10 @@ PGrnSearchBuildCondition(IndexScanDesc scan,
else
PGrnSearchBuildConditionLikeMatch(data, matchTarget, &buffer);
break;
case PGrnQueryStrategyNumber:
case PGrnILikeStrategyNumber:
PGrnSearchBuildConditionLikeMatch(data, matchTarget, &buffer);
break;
case PGrnQueryStrategyNumber:
{
grn_rc rc;
grn_expr_flags flags =
Expand Down Expand Up @@ -4082,7 +4086,8 @@ PGrnEnsureCursorOpened(IndexScanDesc scan, ScanDirection dir)
for (i = 0; i < scan->numberOfKeys; i++)
{
ScanKey key = &(scan->keyData[i]);
if (key->sk_strategy == PGrnLikeStrategyNumber)
if (key->sk_strategy == PGrnLikeStrategyNumber ||
key->sk_strategy == PGrnILikeStrategyNumber)
{
scan->xs_recheck = true;
break;
Expand Down
7 changes: 4 additions & 3 deletions pgroonga.h
Expand Up @@ -19,10 +19,11 @@
#define PGrnGreaterEqualStrategyNumber 4 /* operator >= */
#define PGrnGreaterStrategyNumber 5 /* operator > */
#define PGrnLikeStrategyNumber 6 /* operator ~~ (LIKE) */
#define PGrnMatchStrategyNumber 7 /* operator %% (@ in Groonga) */
#define PGrnQueryStrategyNumber 8 /* operator @@ (Groonga query) */
#define PGrnJSONContainStrategyNumber 9 /* operator @> */
#define PGrnILikeStrategyNumber 7 /* operator ~~* (ILIKE) */
#define PGrnMatchStrategyNumber 8 /* operator %% (@ in Groonga) */
#define PGrnQueryStrategyNumber 9 /* operator @@ (Groonga query) */
#define PGrnRegexpStrategyNumber 10 /* operator @~ (@~ in Groonga) */
#define PGrnJSONContainStrategyNumber 11 /* operator @> */

/* file and table names */
#define PGrnLogBasename "pgroonga.log"
Expand Down
21 changes: 21 additions & 0 deletions sql/full-text-search/text/single/ilike/begin/bitmapscan.sql
@@ -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.');
INSERT INTO memos VALUES (4, 'groonga command is provided.');

CREATE INDEX grnindex ON memos USING pgroonga (content);

SET enable_seqscan = off;
SET enable_indexscan = off;
SET enable_bitmapscan = on;

SELECT id, content
FROM memos
WHERE content ILIKE 'POSTGRESQL%';

DROP TABLE memos;
21 changes: 21 additions & 0 deletions sql/full-text-search/text/single/ilike/begin/indexscan.sql
@@ -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.');
INSERT INTO memos VALUES (4, 'groonga command is provided.');

CREATE INDEX grnindex ON memos USING pgroonga (content);

SET enable_seqscan = off;
SET enable_indexscan = on;
SET enable_bitmapscan = off;

SELECT id, content
FROM memos
WHERE content ILIKE 'POSTGRESQL%';

DROP TABLE memos;
21 changes: 21 additions & 0 deletions sql/full-text-search/text/single/ilike/begin/seqscan.sql
@@ -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.');
INSERT INTO memos VALUES (4, 'groonga command is provided.');

CREATE INDEX grnindex ON memos USING pgroonga (content);

SET enable_seqscan = on;
SET enable_indexscan = off;
SET enable_bitmapscan = off;

SELECT id, content
FROM memos
WHERE content ILIKE 'POSTGRESQL%';

DROP TABLE memos;
21 changes: 21 additions & 0 deletions sql/full-text-search/text/single/ilike/end/bitmapscan.sql
@@ -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');
INSERT INTO memos VALUES (4, 'groonga command is provided');

CREATE INDEX grnindex ON memos USING pgroonga (content);

SET enable_seqscan = off;
SET enable_indexscan = off;
SET enable_bitmapscan = on;

SELECT id, content
FROM memos
WHERE content ILIKE '%GROONGA';

DROP TABLE memos;

0 comments on commit 9ece27b

Please sign in to comment.