Navigation Menu

Skip to content

Commit

Permalink
Support regexp search by @~
Browse files Browse the repository at this point in the history
TODO:

  * Document
  • Loading branch information
kou committed Oct 13, 2015
1 parent 5971deb commit d0b2d67
Show file tree
Hide file tree
Showing 28 changed files with 648 additions and 4 deletions.
20 changes: 20 additions & 0 deletions expected/regexp/text/begin-of-text/bitmapscan.out
@@ -0,0 +1,20 @@
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_regexp_ops);
SET enable_seqscan = off;
SET enable_indexscan = off;
SET enable_bitmapscan = on;
SELECT id, content
FROM memos
WHERE content @~ '\Agroonga';
id | content
----+------------------------------------------
2 | Groonga is fast full text search engine.
(1 row)

DROP TABLE memos;
20 changes: 20 additions & 0 deletions expected/regexp/text/begin-of-text/indexscan.out
@@ -0,0 +1,20 @@
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_regexp_ops);
SET enable_seqscan = off;
SET enable_indexscan = on;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content @~ '\Agroonga';
id | content
----+------------------------------------------
2 | Groonga is fast full text search engine.
(1 row)

DROP TABLE memos;
20 changes: 20 additions & 0 deletions expected/regexp/text/begin-of-text/seqscan.out
@@ -0,0 +1,20 @@
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_regexp_ops);
SET enable_seqscan = on;
SET enable_indexscan = off;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content @~ '\Agroonga';
id | content
----+------------------------------------------
2 | Groonga is fast full text search engine.
(1 row)

DROP TABLE memos;
20 changes: 20 additions & 0 deletions expected/regexp/text/end-of-text/bitmapscan.out
@@ -0,0 +1,20 @@
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_regexp_ops);
SET enable_seqscan = off;
SET enable_indexscan = off;
SET enable_bitmapscan = on;
SELECT id, content
FROM memos
WHERE content @~ 'groonga\z';
id | content
----+------------------------------------------------------
3 | PGroonga is a PostgreSQL extension that uses Groonga
(1 row)

DROP TABLE memos;
20 changes: 20 additions & 0 deletions expected/regexp/text/end-of-text/indexscan.out
@@ -0,0 +1,20 @@
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_regexp_ops);
SET enable_seqscan = off;
SET enable_indexscan = on;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content @~ 'groonga\z';
id | content
----+------------------------------------------------------
3 | PGroonga is a PostgreSQL extension that uses Groonga
(1 row)

DROP TABLE memos;
20 changes: 20 additions & 0 deletions expected/regexp/text/end-of-text/seqscan.out
@@ -0,0 +1,20 @@
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_regexp_ops);
SET enable_seqscan = on;
SET enable_indexscan = off;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content @~ 'groonga\z';
id | content
----+------------------------------------------------------
3 | PGroonga is a PostgreSQL extension that uses Groonga
(1 row)

DROP TABLE memos;
20 changes: 20 additions & 0 deletions expected/regexp/text/exact/bitmapscan.out
@@ -0,0 +1,20 @@
CREATE TABLE memos (
id integer,
content 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_regexp_ops);
SET enable_seqscan = off;
SET enable_indexscan = off;
SET enable_bitmapscan = on;
SELECT id, content
FROM memos
WHERE content @~ '\Agroonga\z';
id | content
----+---------
2 | Groonga
(1 row)

DROP TABLE memos;
20 changes: 20 additions & 0 deletions expected/regexp/text/exact/indexscan.out
@@ -0,0 +1,20 @@
CREATE TABLE memos (
id integer,
content 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_regexp_ops);
SET enable_seqscan = off;
SET enable_indexscan = on;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content @~ '\Agroonga\z';
id | content
----+---------
2 | Groonga
(1 row)

DROP TABLE memos;
20 changes: 20 additions & 0 deletions expected/regexp/text/exact/seqscan.out
@@ -0,0 +1,20 @@
CREATE TABLE memos (
id integer,
content 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_regexp_ops);
SET enable_seqscan = on;
SET enable_indexscan = off;
SET enable_bitmapscan = off;
SELECT id, content
FROM memos
WHERE content @~ '\Agroonga\z';
id | content
----+---------
2 | Groonga
(1 row)

DROP TABLE memos;
21 changes: 21 additions & 0 deletions expected/regexp/text/partial/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.');
CREATE INDEX grnindex ON memos USING pgroonga (content pgroonga.text_regexp_ops);
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;
21 changes: 21 additions & 0 deletions expected/regexp/text/partial/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.');
CREATE INDEX grnindex ON memos USING pgroonga (content pgroonga.text_regexp_ops);
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;
21 changes: 21 additions & 0 deletions expected/regexp/text/partial/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.');
CREATE INDEX grnindex ON memos USING pgroonga (content pgroonga.text_regexp_ops);
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;
39 changes: 39 additions & 0 deletions pgroonga--0.9.0--1.0.0.sql
@@ -1,3 +1,4 @@
-- Support index only scan
CREATE FUNCTION pgroonga.canreturn(internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'pgroonga_canreturn'
Expand All @@ -6,3 +7,41 @@ CREATE FUNCTION pgroonga.canreturn(internal)
UPDATE pg_catalog.pg_am
SET amcanreturn = 'pgroonga.canreturn'
WHERE amname = 'pgroonga';


-- Support @~
UPDATE pg_catalog.pg_am SET amstrategies = 10 WHERE amname = 'pgroonga';

CREATE FUNCTION pgroonga.match_regexp(text, text)
RETURNS bool
AS 'MODULE_PATHNAME', 'pgroonga_match_regexp_text'
LANGUAGE C
IMMUTABLE
STRICT;

CREATE FUNCTION pgroonga.match_regexp(varchar, varchar)
RETURNS bool
AS 'MODULE_PATHNAME', 'pgroonga_match_regexp_varchar'
LANGUAGE C
IMMUTABLE
STRICT;

CREATE OPERATOR @~ (
PROCEDURE = pgroonga.match_regexp,
LEFTARG = text,
RIGHTARG = text
);

CREATE OPERATOR @~ (
PROCEDURE = pgroonga.match_regexp,
LEFTARG = varchar,
RIGHTARG = varchar
);

CREATE OPERATOR CLASS pgroonga.text_regexp_ops FOR TYPE text
USING pgroonga AS
OPERATOR 10 @~;

CREATE OPERATOR CLASS pgroonga.varchar_regexp_ops FOR TYPE varchar
USING pgroonga AS
OPERATOR 10 @~;

0 comments on commit d0b2d67

Please sign in to comment.