[Groonga-commit] pgroonga/pgroonga at af1193d [master] Add pgroonga.jsonb_ops_v2

Back to archive index

Kouhei Sutou null+****@clear*****
Mon May 8 18:32:48 JST 2017


Kouhei Sutou	2017-05-08 18:32:48 +0900 (Mon, 08 May 2017)

  New Revision: af1193d489fc422f136011da053dbb16ab755004
  https://github.com/pgroonga/pgroonga/commit/af1193d489fc422f136011da053dbb16ab755004

  Message:
    Add pgroonga.jsonb_ops_v2

  Added files:
    expected/jsonb/compatibility/v2/script-v1/delete/multiple-values.out
    expected/jsonb/compatibility/v2/script-v1/element/boolean/bitmapscan.out
    expected/jsonb/compatibility/v2/script-v1/element/boolean/indexscan.out
    expected/jsonb/compatibility/v2/script-v1/element/boolean/seqscan.out
    expected/jsonb/compatibility/v2/script-v1/element/number/bitmapscan.out
    expected/jsonb/compatibility/v2/script-v1/element/number/indexscan.out
    expected/jsonb/compatibility/v2/script-v1/element/number/seqscan.out
    expected/jsonb/compatibility/v2/script-v1/element/string/bitmapscan.out
    expected/jsonb/compatibility/v2/script-v1/element/string/indexscan.out
    expected/jsonb/compatibility/v2/script-v1/element/string/seqscan.out
    expected/jsonb/compatibility/v2/script-v1/full-text-search/default.out
    expected/jsonb/compatibility/v2/script-v1/full-text-search/disable.out
    expected/jsonb/compatibility/v2/script-v1/object/bitmapscan.out
    expected/jsonb/compatibility/v2/script-v1/object/indexscan.out
    expected/jsonb/compatibility/v2/script-v1/object/seqscan.out
    expected/jsonb/compatibility/v2/script-v1/value/boolean/bitmapscan.out
    expected/jsonb/compatibility/v2/script-v1/value/boolean/indexscan.out
    expected/jsonb/compatibility/v2/script-v1/value/boolean/seqscan.out
    expected/jsonb/compatibility/v2/script-v1/value/number/bitmapscan.out
    expected/jsonb/compatibility/v2/script-v1/value/number/indexscan.out
    expected/jsonb/compatibility/v2/script-v1/value/number/seqscan.out
    expected/jsonb/compatibility/v2/script-v1/value/string/bitmapscan.out
    expected/jsonb/compatibility/v2/script-v1/value/string/indexscan.out
    expected/jsonb/compatibility/v2/script-v1/value/string/seqscan.out
    expected/jsonb/contain-v2/array/empty.out
    expected/jsonb/contain-v2/array/multiple-elements.out
    expected/jsonb/contain-v2/object/empty.out
    expected/jsonb/script-v2/delete/multiple-values.out
    expected/jsonb/script-v2/element/boolean/bitmapscan.out
    expected/jsonb/script-v2/element/boolean/indexscan.out
    expected/jsonb/script-v2/element/boolean/seqscan.out
    expected/jsonb/script-v2/element/number/bitmapscan.out
    expected/jsonb/script-v2/element/number/indexscan.out
    expected/jsonb/script-v2/element/number/seqscan.out
    expected/jsonb/script-v2/element/string/bitmapscan.out
    expected/jsonb/script-v2/element/string/indexscan.out
    expected/jsonb/script-v2/element/string/seqscan.out
    expected/jsonb/script-v2/full-text-search/default.out
    expected/jsonb/script-v2/full-text-search/disable.out
    expected/jsonb/script-v2/object/bitmapscan.out
    expected/jsonb/script-v2/object/indexscan.out
    expected/jsonb/script-v2/object/seqscan.out
    expected/jsonb/script-v2/value/boolean/bitmapscan.out
    expected/jsonb/script-v2/value/boolean/indexscan.out
    expected/jsonb/script-v2/value/boolean/seqscan.out
    expected/jsonb/script-v2/value/number/bitmapscan.out
    expected/jsonb/script-v2/value/number/indexscan.out
    expected/jsonb/script-v2/value/number/seqscan.out
    expected/jsonb/script-v2/value/string/bitmapscan.out
    expected/jsonb/script-v2/value/string/indexscan.out
    expected/jsonb/script-v2/value/string/seqscan.out
    sql/jsonb/compatibility/v2/script-v1/delete/multiple-values.sql
    sql/jsonb/compatibility/v2/script-v1/element/boolean/bitmapscan.sql
    sql/jsonb/compatibility/v2/script-v1/element/boolean/indexscan.sql
    sql/jsonb/compatibility/v2/script-v1/element/boolean/seqscan.sql
    sql/jsonb/compatibility/v2/script-v1/element/number/bitmapscan.sql
    sql/jsonb/compatibility/v2/script-v1/element/number/indexscan.sql
    sql/jsonb/compatibility/v2/script-v1/element/number/seqscan.sql
    sql/jsonb/compatibility/v2/script-v1/element/string/bitmapscan.sql
    sql/jsonb/compatibility/v2/script-v1/element/string/indexscan.sql
    sql/jsonb/compatibility/v2/script-v1/element/string/seqscan.sql
    sql/jsonb/compatibility/v2/script-v1/full-text-search/default.sql
    sql/jsonb/compatibility/v2/script-v1/full-text-search/disable.sql
    sql/jsonb/compatibility/v2/script-v1/object/bitmapscan.sql
    sql/jsonb/compatibility/v2/script-v1/object/indexscan.sql
    sql/jsonb/compatibility/v2/script-v1/object/seqscan.sql
    sql/jsonb/compatibility/v2/script-v1/value/boolean/bitmapscan.sql
    sql/jsonb/compatibility/v2/script-v1/value/boolean/indexscan.sql
    sql/jsonb/compatibility/v2/script-v1/value/boolean/seqscan.sql
    sql/jsonb/compatibility/v2/script-v1/value/number/bitmapscan.sql
    sql/jsonb/compatibility/v2/script-v1/value/number/indexscan.sql
    sql/jsonb/compatibility/v2/script-v1/value/number/seqscan.sql
    sql/jsonb/compatibility/v2/script-v1/value/string/bitmapscan.sql
    sql/jsonb/compatibility/v2/script-v1/value/string/indexscan.sql
    sql/jsonb/compatibility/v2/script-v1/value/string/seqscan.sql
    sql/jsonb/contain-v2/array/empty.sql
    sql/jsonb/contain-v2/array/multiple-elements.sql
    sql/jsonb/contain-v2/object/empty.sql
    sql/jsonb/script-v2/delete/multiple-values.sql
    sql/jsonb/script-v2/element/boolean/bitmapscan.sql
    sql/jsonb/script-v2/element/boolean/indexscan.sql
    sql/jsonb/script-v2/element/boolean/seqscan.sql
    sql/jsonb/script-v2/element/number/bitmapscan.sql
    sql/jsonb/script-v2/element/number/indexscan.sql
    sql/jsonb/script-v2/element/number/seqscan.sql
    sql/jsonb/script-v2/element/string/bitmapscan.sql
    sql/jsonb/script-v2/element/string/indexscan.sql
    sql/jsonb/script-v2/element/string/seqscan.sql
    sql/jsonb/script-v2/full-text-search/default.sql
    sql/jsonb/script-v2/full-text-search/disable.sql
    sql/jsonb/script-v2/object/bitmapscan.sql
    sql/jsonb/script-v2/object/indexscan.sql
    sql/jsonb/script-v2/object/seqscan.sql
    sql/jsonb/script-v2/value/boolean/bitmapscan.sql
    sql/jsonb/script-v2/value/boolean/indexscan.sql
    sql/jsonb/script-v2/value/boolean/seqscan.sql
    sql/jsonb/script-v2/value/number/bitmapscan.sql
    sql/jsonb/script-v2/value/number/indexscan.sql
    sql/jsonb/script-v2/value/number/seqscan.sql
    sql/jsonb/script-v2/value/string/bitmapscan.sql
    sql/jsonb/script-v2/value/string/indexscan.sql
    sql/jsonb/script-v2/value/string/seqscan.sql
  Modified files:
    data/pgroonga--1.2.0--1.2.1.sql
    data/pgroonga.sql
    src/pgrn-jsonb.c

  Modified: data/pgroonga--1.2.0--1.2.1.sql (+30 -0)
===================================================================
--- data/pgroonga--1.2.0--1.2.1.sql    2017-05-08 14:52:03 +0900 (86f4885)
+++ data/pgroonga--1.2.0--1.2.1.sql    2017-05-08 18:32:48 +0900 (a56f5c8)
@@ -365,3 +365,33 @@ CREATE OPERATOR CLASS pgroonga.varchar_array_ops_v2 FOR TYPE varchar[]
 ALTER OPERATOR FAMILY pgroonga.varchar_array_ops USING pgroonga
 	ADD
 		OPERATOR 12 &@ (varchar[], varchar);
+
+-- Add pgroonga.jsonb_ops_v2
+DO LANGUAGE plpgsql $$
+BEGIN
+	PERFORM 1
+		FROM pg_type
+		WHERE typname = 'jsonb';
+
+	IF FOUND THEN
+		CREATE FUNCTION pgroonga.script_jsonb(jsonb, text)
+			RETURNS bool
+			AS 'MODULE_PATHNAME', 'pgroonga_script_jsonb'
+			LANGUAGE C
+			IMMUTABLE
+			STRICT;
+
+		CREATE OPERATOR &` (
+			PROCEDURE = pgroonga.script_jsonb,
+			LEFTARG = jsonb,
+			RIGHTARG = text
+		);
+		CREATE OPERATOR CLASS pgroonga.jsonb_ops_v2
+			FOR TYPE jsonb
+			USING pgroonga AS
+				OPERATOR 9 @@ (jsonb, text), -- For backward compatibility
+				OPERATOR 11 @>,
+				OPERATOR 15 &` (jsonb, text);
+	END IF;
+END;
+$$;

  Modified: data/pgroonga.sql (+40 -0)
===================================================================
--- data/pgroonga.sql    2017-05-08 14:52:03 +0900 (4b6a50f)
+++ data/pgroonga.sql    2017-05-08 18:32:48 +0900 (779023f)
@@ -500,6 +500,29 @@ CREATE OPERATOR &` (
 	RIGHTARG = varchar
 );
 
+DO LANGUAGE plpgsql $$
+BEGIN
+	PERFORM 1
+		FROM pg_type
+		WHERE typname = 'jsonb';
+
+	IF FOUND THEN
+		CREATE FUNCTION pgroonga.script_jsonb(jsonb, text)
+			RETURNS bool
+			AS 'MODULE_PATHNAME', 'pgroonga_script_jsonb'
+			LANGUAGE C
+			IMMUTABLE
+			STRICT;
+
+		CREATE OPERATOR &` (
+			PROCEDURE = pgroonga.script_jsonb,
+			LEFTARG = jsonb,
+			RIGHTARG = text
+		);
+	END IF;
+END;
+$$;
+
 CREATE FUNCTION pgroonga.match_in_text(text, text[])
 	RETURNS bool
 	AS 'MODULE_PATHNAME', 'pgroonga_match_in_text'
@@ -970,3 +993,20 @@ CREATE OPERATOR CLASS pgroonga.varchar_regexp_ops_v2 FOR TYPE varchar
 	USING pgroonga AS
 		OPERATOR 10 @~, -- For backward compatibility
 		OPERATOR 22 &~;
+
+DO LANGUAGE plpgsql $$
+BEGIN
+	PERFORM 1
+		FROM pg_type
+		WHERE typname = 'jsonb';
+
+	IF FOUND THEN
+		CREATE OPERATOR CLASS pgroonga.jsonb_ops_v2
+			FOR TYPE jsonb
+			USING pgroonga AS
+				OPERATOR 9 @@ (jsonb, text), -- For backward compatibility
+				OPERATOR 11 @>,
+				OPERATOR 15 &` (jsonb, text);
+	END IF;
+END;
+$$;

  Added: expected/jsonb/compatibility/v2/script-v1/delete/multiple-values.out (+24 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/delete/multiple-values.out    2017-05-08 18:32:48 +0900 (0e2d967)
@@ -0,0 +1,24 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+DELETE FROM fruits WHERE id = 1;
+VACUUM;
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+ id |        items        
+----+---------------------
+  2 | ["banana", "apple"]
+(1 row)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/element/boolean/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/element/boolean/bitmapscan.out    2017-05-08 18:32:48 +0900 (73a6765)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+ id | items  
+----+--------
+  1 | [true]
+  3 | [true]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/element/boolean/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/element/boolean/indexscan.out    2017-05-08 18:32:48 +0900 (336663b)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+ id | items  
+----+--------
+  1 | [true]
+  3 | [true]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/element/boolean/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/element/boolean/seqscan.out    2017-05-08 18:32:48 +0900 (e87cb29)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+ id | items  
+----+--------
+  1 | [true]
+  3 | [true]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/element/number/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/element/number/bitmapscan.out    2017-05-08 18:32:48 +0900 (6dbf675)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |   items   
+----+-----------
+  1 | [100]
+  2 | [200, 30]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/element/number/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/element/number/indexscan.out    2017-05-08 18:32:48 +0900 (9ef5701)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |   items   
+----+-----------
+  1 | [100]
+  2 | [200, 30]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/element/number/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/element/number/seqscan.out    2017-05-08 18:32:48 +0900 (0dc79bf)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |   items   
+----+-----------
+  1 | [100]
+  2 | [200, 30]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/element/string/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/element/string/bitmapscan.out    2017-05-08 18:32:48 +0900 (6df1cdb)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+ id |        items        
+----+---------------------
+  1 | ["apple"]
+  2 | ["banana", "apple"]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/element/string/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/element/string/indexscan.out    2017-05-08 18:32:48 +0900 (1dcc9c2)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+ id |        items        
+----+---------------------
+  1 | ["apple"]
+  2 | ["banana", "apple"]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/element/string/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/element/string/seqscan.out    2017-05-08 18:32:48 +0900 (7a6f8a5)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+ id |        items        
+----+---------------------
+  1 | ["apple"]
+  2 | ["banana", "apple"]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/full-text-search/default.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/full-text-search/default.out    2017-05-08 18:32:48 +0900 (533b39d)
@@ -0,0 +1,23 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": "Hello World"}');
+INSERT INTO logs VALUES (2, '{"message": "This is a pen"}');
+INSERT INTO logs VALUES (3, '{"message": "Good-by World"}');
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'string @ "world"'
+ ORDER BY id;
+ id |            record            
+----+------------------------------
+  1 | {"message": "Hello World"}
+  3 | {"message": "Good-by World"}
+(2 rows)
+
+DROP TABLE logs;

  Added: expected/jsonb/compatibility/v2/script-v1/full-text-search/disable.out (+31 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/full-text-search/disable.out    2017-05-08 18:32:48 +0900 (509b7ba)
@@ -0,0 +1,31 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": "Hello World"}');
+INSERT INTO logs VALUES (2, '{"message": "This is a pen"}');
+INSERT INTO logs VALUES (3, '{"message": "Good-by World"}');
+CREATE INDEX pgroonga_index ON logs
+ USING pgroonga (record pgroonga.jsonb_ops_v2)
+  WITH (tokenizer = '');
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'string @ "world"'
+ ORDER BY id;
+ id | record 
+----+--------
+(0 rows)
+
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'string == "Hello World"'
+ ORDER BY id;
+ id |           record           
+----+----------------------------
+  1 | {"message": "Hello World"}
+(1 row)
+
+DROP TABLE logs;

  Added: expected/jsonb/compatibility/v2/script-v1/object/bitmapscan.out (+22 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/object/bitmapscan.out    2017-05-08 18:32:48 +0900 (dbbdc49)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+ id |                     record                     
+----+------------------------------------------------
+  1 | {"message": {"code": 100, "content": "hello"}}
+(1 row)
+
+DROP TABLE logs;

  Added: expected/jsonb/compatibility/v2/script-v1/object/indexscan.out (+22 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/object/indexscan.out    2017-05-08 18:32:48 +0900 (120a60b)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+ id |                     record                     
+----+------------------------------------------------
+  1 | {"message": {"code": 100, "content": "hello"}}
+(1 row)
+
+DROP TABLE logs;

  Added: expected/jsonb/compatibility/v2/script-v1/object/seqscan.out (+20 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/object/seqscan.out    2017-05-08 18:32:48 +0900 (32208b7)
@@ -0,0 +1,20 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+ id |                     record                     
+----+------------------------------------------------
+  1 | {"message": {"code": 100, "content": "hello"}}
+(1 row)
+
+DROP TABLE logs;

  Added: expected/jsonb/compatibility/v2/script-v1/value/boolean/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/value/boolean/bitmapscan.out    2017-05-08 18:32:48 +0900 (dd528dd)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+ id |      items      
+----+-----------------
+  1 | {"apple": true}
+  3 | {"peach": true}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/value/boolean/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/value/boolean/indexscan.out    2017-05-08 18:32:48 +0900 (d8c2df6)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+ id |      items      
+----+-----------------
+  1 | {"apple": true}
+  3 | {"peach": true}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/value/boolean/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/value/boolean/seqscan.out    2017-05-08 18:32:48 +0900 (4e756f2)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+ id |      items      
+----+-----------------
+  1 | {"apple": true}
+  3 | {"peach": true}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/value/number/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/value/number/bitmapscan.out    2017-05-08 18:32:48 +0900 (4819aa8)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |     items      
+----+----------------
+  1 | {"apple": 100}
+  2 | {"banana": 30}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/value/number/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/value/number/indexscan.out    2017-05-08 18:32:48 +0900 (c961be3)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |     items      
+----+----------------
+  1 | {"apple": 100}
+  2 | {"banana": 30}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/value/number/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/value/number/seqscan.out    2017-05-08 18:32:48 +0900 (98bddd4)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |     items      
+----+----------------
+  1 | {"apple": 100}
+  2 | {"banana": 30}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/value/string/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/value/string/bitmapscan.out    2017-05-08 18:32:48 +0900 (1846bf0)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+ id |       items       
+----+-------------------
+  1 | {"name": "apple"}
+  2 | {"type": "apple"}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/value/string/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/value/string/indexscan.out    2017-05-08 18:32:48 +0900 (079feee)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+ id |       items       
+----+-------------------
+  1 | {"name": "apple"}
+  2 | {"type": "apple"}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/compatibility/v2/script-v1/value/string/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/compatibility/v2/script-v1/value/string/seqscan.out    2017-05-08 18:32:48 +0900 (0825601)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+ id |       items       
+----+-------------------
+  1 | {"name": "apple"}
+  2 | {"type": "apple"}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/contain-v2/array/empty.out (+29 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/contain-v2/array/empty.out    2017-05-08 18:32:48 +0900 (c8e9ff0)
@@ -0,0 +1,29 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '[]');
+INSERT INTO logs VALUES (2, '[100]');
+INSERT INTO logs VALUES (3, '["hello"]');
+INSERT INTO logs VALUES (4, '[true]');
+INSERT INTO logs VALUES (5, '[{"object": "value"}]');
+INSERT INTO logs VALUES (6, '{"object": []}');
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record @> '[]'::jsonb
+ ORDER BY id;
+ id |        record         
+----+-----------------------
+  1 | []
+  2 | [100]
+  3 | ["hello"]
+  4 | [true]
+  5 | [{"object": "value"}]
+(5 rows)
+
+DROP TABLE logs;

  Added: expected/jsonb/contain-v2/array/multiple-elements.out (+26 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/contain-v2/array/multiple-elements.out    2017-05-08 18:32:48 +0900 (06ad8dc)
@@ -0,0 +1,26 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs
+     VALUES (1, '{"body": {"values": [100, "Hello", true]}}');
+INSERT INTO logs
+     VALUES (2, '{"values": [100, "Hello", true]}');
+INSERT INTO logs
+     VALUES (3, '{"body": {"values": [100, "Hello", true, "World"]}}');
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record @> '{"body": {"values": ["Hello", true, 100]}}'::jsonb
+ ORDER BY id;
+ id |                       record                        
+----+-----------------------------------------------------
+  1 | {"body": {"values": [100, "Hello", true]}}
+  3 | {"body": {"values": [100, "Hello", true, "World"]}}
+(2 rows)
+
+DROP TABLE logs;

  Added: expected/jsonb/contain-v2/object/empty.out (+29 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/contain-v2/object/empty.out    2017-05-08 18:32:48 +0900 (afc58f5)
@@ -0,0 +1,29 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{}');
+INSERT INTO logs VALUES (2, '{"key": 100}');
+INSERT INTO logs VALUES (3, '{"key": "hello"}');
+INSERT INTO logs VALUES (4, '{"key": true}');
+INSERT INTO logs VALUES (5, '{"key": []}');
+INSERT INTO logs VALUES (6, '[{}]');
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record @> '{}'::jsonb
+ ORDER BY id;
+ id |      record      
+----+------------------
+  1 | {}
+  2 | {"key": 100}
+  3 | {"key": "hello"}
+  4 | {"key": true}
+  5 | {"key": []}
+(5 rows)
+
+DROP TABLE logs;

  Added: expected/jsonb/script-v2/delete/multiple-values.out (+24 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/delete/multiple-values.out    2017-05-08 18:32:48 +0900 (515f151)
@@ -0,0 +1,24 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+DELETE FROM fruits WHERE id = 1;
+VACUUM;
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+ id |        items        
+----+---------------------
+  2 | ["banana", "apple"]
+(1 row)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/element/boolean/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/element/boolean/bitmapscan.out    2017-05-08 18:32:48 +0900 (4fb3834)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+ id | items  
+----+--------
+  1 | [true]
+  3 | [true]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/element/boolean/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/element/boolean/indexscan.out    2017-05-08 18:32:48 +0900 (c3acc78)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+ id | items  
+----+--------
+  1 | [true]
+  3 | [true]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/element/boolean/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/element/boolean/seqscan.out    2017-05-08 18:32:48 +0900 (483805a)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+ id | items  
+----+--------
+  1 | [true]
+  3 | [true]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/element/number/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/element/number/bitmapscan.out    2017-05-08 18:32:48 +0900 (af3ddbf)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |   items   
+----+-----------
+  1 | [100]
+  2 | [200, 30]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/element/number/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/element/number/indexscan.out    2017-05-08 18:32:48 +0900 (0c20f37)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |   items   
+----+-----------
+  1 | [100]
+  2 | [200, 30]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/element/number/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/element/number/seqscan.out    2017-05-08 18:32:48 +0900 (2adcbf3)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |   items   
+----+-----------
+  1 | [100]
+  2 | [200, 30]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/element/string/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/element/string/bitmapscan.out    2017-05-08 18:32:48 +0900 (e7e072e)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+ id |        items        
+----+---------------------
+  1 | ["apple"]
+  2 | ["banana", "apple"]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/element/string/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/element/string/indexscan.out    2017-05-08 18:32:48 +0900 (d48852b)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+ id |        items        
+----+---------------------
+  1 | ["apple"]
+  2 | ["banana", "apple"]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/element/string/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/element/string/seqscan.out    2017-05-08 18:32:48 +0900 (5aedbca)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+ id |        items        
+----+---------------------
+  1 | ["apple"]
+  2 | ["banana", "apple"]
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/full-text-search/default.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/full-text-search/default.out    2017-05-08 18:32:48 +0900 (e01ecc2)
@@ -0,0 +1,23 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": "Hello World"}');
+INSERT INTO logs VALUES (2, '{"message": "This is a pen"}');
+INSERT INTO logs VALUES (3, '{"message": "Good-by World"}');
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record &` 'string @ "world"'
+ ORDER BY id;
+ id |            record            
+----+------------------------------
+  1 | {"message": "Hello World"}
+  3 | {"message": "Good-by World"}
+(2 rows)
+
+DROP TABLE logs;

  Added: expected/jsonb/script-v2/full-text-search/disable.out (+31 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/full-text-search/disable.out    2017-05-08 18:32:48 +0900 (235a9e0)
@@ -0,0 +1,31 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": "Hello World"}');
+INSERT INTO logs VALUES (2, '{"message": "This is a pen"}');
+INSERT INTO logs VALUES (3, '{"message": "Good-by World"}');
+CREATE INDEX pgroonga_index ON logs
+ USING pgroonga (record pgroonga.jsonb_ops_v2)
+  WITH (tokenizer = '');
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record &` 'string @ "world"'
+ ORDER BY id;
+ id | record 
+----+--------
+(0 rows)
+
+SELECT id, record
+  FROM logs
+ WHERE record &` 'string == "Hello World"'
+ ORDER BY id;
+ id |           record           
+----+----------------------------
+  1 | {"message": "Hello World"}
+(1 row)
+
+DROP TABLE logs;

  Added: expected/jsonb/script-v2/object/bitmapscan.out (+22 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/object/bitmapscan.out    2017-05-08 18:32:48 +0900 (fda8d21)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, record
+  FROM logs
+ WHERE record &` 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+ id |                     record                     
+----+------------------------------------------------
+  1 | {"message": {"code": 100, "content": "hello"}}
+(1 row)
+
+DROP TABLE logs;

  Added: expected/jsonb/script-v2/object/indexscan.out (+22 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/object/indexscan.out    2017-05-08 18:32:48 +0900 (56baf14)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record &` 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+ id |                     record                     
+----+------------------------------------------------
+  1 | {"message": {"code": 100, "content": "hello"}}
+(1 row)
+
+DROP TABLE logs;

  Added: expected/jsonb/script-v2/object/seqscan.out (+20 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/object/seqscan.out    2017-05-08 18:32:48 +0900 (6743d1a)
@@ -0,0 +1,20 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, record
+  FROM logs
+ WHERE record &` 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+ id |                     record                     
+----+------------------------------------------------
+  1 | {"message": {"code": 100, "content": "hello"}}
+(1 row)
+
+DROP TABLE logs;

  Added: expected/jsonb/script-v2/value/boolean/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/value/boolean/bitmapscan.out    2017-05-08 18:32:48 +0900 (87961fb)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+ id |      items      
+----+-----------------
+  1 | {"apple": true}
+  3 | {"peach": true}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/value/boolean/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/value/boolean/indexscan.out    2017-05-08 18:32:48 +0900 (eb79d30)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+ id |      items      
+----+-----------------
+  1 | {"apple": true}
+  3 | {"peach": true}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/value/boolean/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/value/boolean/seqscan.out    2017-05-08 18:32:48 +0900 (e28b27d)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+ id |      items      
+----+-----------------
+  1 | {"apple": true}
+  3 | {"peach": true}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/value/number/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/value/number/bitmapscan.out    2017-05-08 18:32:48 +0900 (6ea4d43)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |     items      
+----+----------------
+  1 | {"apple": 100}
+  2 | {"banana": 30}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/value/number/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/value/number/indexscan.out    2017-05-08 18:32:48 +0900 (93a0bac)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |     items      
+----+----------------
+  1 | {"apple": 100}
+  2 | {"banana": 30}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/value/number/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/value/number/seqscan.out    2017-05-08 18:32:48 +0900 (bd79b2e)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+ id |     items      
+----+----------------
+  1 | {"apple": 100}
+  2 | {"banana": 30}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/value/string/bitmapscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/value/string/bitmapscan.out    2017-05-08 18:32:48 +0900 (8323755)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+ id |       items       
+----+-------------------
+  1 | {"name": "apple"}
+  2 | {"type": "apple"}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/value/string/indexscan.out (+23 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/value/string/indexscan.out    2017-05-08 18:32:48 +0900 (8cdab2f)
@@ -0,0 +1,23 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+ id |       items       
+----+-------------------
+  1 | {"name": "apple"}
+  2 | {"type": "apple"}
+(2 rows)
+
+DROP TABLE fruits;

  Added: expected/jsonb/script-v2/value/string/seqscan.out (+21 -0) 100644
===================================================================
--- /dev/null
+++ expected/jsonb/script-v2/value/string/seqscan.out    2017-05-08 18:32:48 +0900 (5d2de45)
@@ -0,0 +1,21 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+ id |       items       
+----+-------------------
+  1 | {"name": "apple"}
+  2 | {"type": "apple"}
+(2 rows)
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/delete/multiple-values.sql (+24 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/delete/multiple-values.sql    2017-05-08 18:32:48 +0900 (d77d113)
@@ -0,0 +1,24 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+DELETE FROM fruits WHERE id = 1;
+VACUUM;
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/element/boolean/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/element/boolean/bitmapscan.sql    2017-05-08 18:32:48 +0900 (e5dca8d)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/element/boolean/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/element/boolean/indexscan.sql    2017-05-08 18:32:48 +0900 (8907f5b)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/element/boolean/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/element/boolean/seqscan.sql    2017-05-08 18:32:48 +0900 (e322592)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/element/number/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/element/number/bitmapscan.sql    2017-05-08 18:32:48 +0900 (cd900ad)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/element/number/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/element/number/indexscan.sql    2017-05-08 18:32:48 +0900 (e62ee34)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/element/number/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/element/number/seqscan.sql    2017-05-08 18:32:48 +0900 (d81a9af)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/element/string/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/element/string/bitmapscan.sql    2017-05-08 18:32:48 +0900 (a200e13)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/element/string/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/element/string/indexscan.sql    2017-05-08 18:32:48 +0900 (ce05cfb)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/element/string/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/element/string/seqscan.sql    2017-05-08 18:32:48 +0900 (ec09803)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/full-text-search/default.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/full-text-search/default.sql    2017-05-08 18:32:48 +0900 (1c07c12)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": "Hello World"}');
+INSERT INTO logs VALUES (2, '{"message": "This is a pen"}');
+INSERT INTO logs VALUES (3, '{"message": "Good-by World"}');
+
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'string @ "world"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/compatibility/v2/script-v1/full-text-search/disable.sql (+28 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/full-text-search/disable.sql    2017-05-08 18:32:48 +0900 (94bd3e0)
@@ -0,0 +1,28 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": "Hello World"}');
+INSERT INTO logs VALUES (2, '{"message": "This is a pen"}');
+INSERT INTO logs VALUES (3, '{"message": "Good-by World"}');
+
+CREATE INDEX pgroonga_index ON logs
+ USING pgroonga (record pgroonga.jsonb_ops_v2)
+  WITH (tokenizer = '');
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'string @ "world"'
+ ORDER BY id;
+
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'string == "Hello World"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/compatibility/v2/script-v1/object/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/object/bitmapscan.sql    2017-05-08 18:32:48 +0900 (fc02c21)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/compatibility/v2/script-v1/object/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/object/indexscan.sql    2017-05-08 18:32:48 +0900 (731467d)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/compatibility/v2/script-v1/object/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/object/seqscan.sql    2017-05-08 18:32:48 +0900 (3bb69a7)
@@ -0,0 +1,19 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record @@ 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/compatibility/v2/script-v1/value/boolean/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/value/boolean/bitmapscan.sql    2017-05-08 18:32:48 +0900 (cf5cfae)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/value/boolean/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/value/boolean/indexscan.sql    2017-05-08 18:32:48 +0900 (1b0b3f1)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/value/boolean/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/value/boolean/seqscan.sql    2017-05-08 18:32:48 +0900 (44af5d1)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/value/number/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/value/number/bitmapscan.sql    2017-05-08 18:32:48 +0900 (dab9c54)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/value/number/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/value/number/indexscan.sql    2017-05-08 18:32:48 +0900 (23b5a47)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/value/number/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/value/number/seqscan.sql    2017-05-08 18:32:48 +0900 (524c04d)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/value/string/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/value/string/bitmapscan.sql    2017-05-08 18:32:48 +0900 (48eb9e8)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/value/string/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/value/string/indexscan.sql    2017-05-08 18:32:48 +0900 (bb00703)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/compatibility/v2/script-v1/value/string/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/compatibility/v2/script-v1/value/string/seqscan.sql    2017-05-08 18:32:48 +0900 (5ce7528)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items @@ 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/contain-v2/array/empty.sql (+25 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/contain-v2/array/empty.sql    2017-05-08 18:32:48 +0900 (7cc7b16)
@@ -0,0 +1,25 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '[]');
+INSERT INTO logs VALUES (2, '[100]');
+INSERT INTO logs VALUES (3, '["hello"]');
+INSERT INTO logs VALUES (4, '[true]');
+INSERT INTO logs VALUES (5, '[{"object": "value"}]');
+INSERT INTO logs VALUES (6, '{"object": []}');
+
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record @> '[]'::jsonb
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/contain-v2/array/multiple-elements.sql (+25 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/contain-v2/array/multiple-elements.sql    2017-05-08 18:32:48 +0900 (153b3b0)
@@ -0,0 +1,25 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs
+     VALUES (1, '{"body": {"values": [100, "Hello", true]}}');
+INSERT INTO logs
+     VALUES (2, '{"values": [100, "Hello", true]}');
+INSERT INTO logs
+     VALUES (3, '{"body": {"values": [100, "Hello", true, "World"]}}');
+
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record @> '{"body": {"values": ["Hello", true, 100]}}'::jsonb
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/contain-v2/object/empty.sql (+25 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/contain-v2/object/empty.sql    2017-05-08 18:32:48 +0900 (59fd4b5)
@@ -0,0 +1,25 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{}');
+INSERT INTO logs VALUES (2, '{"key": 100}');
+INSERT INTO logs VALUES (3, '{"key": "hello"}');
+INSERT INTO logs VALUES (4, '{"key": true}');
+INSERT INTO logs VALUES (5, '{"key": []}');
+INSERT INTO logs VALUES (6, '[{}]');
+
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record @> '{}'::jsonb
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/script-v2/delete/multiple-values.sql (+24 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/delete/multiple-values.sql    2017-05-08 18:32:48 +0900 (08a0245)
@@ -0,0 +1,24 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+DELETE FROM fruits WHERE id = 1;
+VACUUM;
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/element/boolean/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/element/boolean/bitmapscan.sql    2017-05-08 18:32:48 +0900 (7757924)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/element/boolean/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/element/boolean/indexscan.sql    2017-05-08 18:32:48 +0900 (8a0c344)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/element/boolean/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/element/boolean/seqscan.sql    2017-05-08 18:32:48 +0900 (1eaa3fd)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[true]');
+INSERT INTO fruits VALUES (2, '[false]');
+INSERT INTO fruits VALUES (3, '[true]');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/element/number/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/element/number/bitmapscan.sql    2017-05-08 18:32:48 +0900 (aee3e15)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/element/number/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/element/number/indexscan.sql    2017-05-08 18:32:48 +0900 (0fd48bd)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/element/number/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/element/number/seqscan.sql    2017-05-08 18:32:48 +0900 (84ec76b)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '[100]');
+INSERT INTO fruits VALUES (2, '[200, 30]');
+INSERT INTO fruits VALUES (3, '[150]');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/element/string/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/element/string/bitmapscan.sql    2017-05-08 18:32:48 +0900 (424ba95)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/element/string/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/element/string/indexscan.sql    2017-05-08 18:32:48 +0900 (63744d6)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/element/string/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/element/string/seqscan.sql    2017-05-08 18:32:48 +0900 (f141759)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '["apple"]');
+INSERT INTO fruits VALUES (2, '["banana", "apple"]');
+INSERT INTO fruits VALUES (3, '["peach"]');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/full-text-search/default.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/full-text-search/default.sql    2017-05-08 18:32:48 +0900 (11e4fb3)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": "Hello World"}');
+INSERT INTO logs VALUES (2, '{"message": "This is a pen"}');
+INSERT INTO logs VALUES (3, '{"message": "Good-by World"}');
+
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record &` 'string @ "world"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/script-v2/full-text-search/disable.sql (+28 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/full-text-search/disable.sql    2017-05-08 18:32:48 +0900 (7940178)
@@ -0,0 +1,28 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": "Hello World"}');
+INSERT INTO logs VALUES (2, '{"message": "This is a pen"}');
+INSERT INTO logs VALUES (3, '{"message": "Good-by World"}');
+
+CREATE INDEX pgroonga_index ON logs
+ USING pgroonga (record pgroonga.jsonb_ops_v2)
+  WITH (tokenizer = '');
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record &` 'string @ "world"'
+ ORDER BY id;
+
+SELECT id, record
+  FROM logs
+ WHERE record &` 'string == "Hello World"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/script-v2/object/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/object/bitmapscan.sql    2017-05-08 18:32:48 +0900 (2f68847)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, record
+  FROM logs
+ WHERE record &` 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/script-v2/object/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/object/indexscan.sql    2017-05-08 18:32:48 +0900 (0eac1a7)
@@ -0,0 +1,22 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+
+CREATE INDEX pgroonga_index ON logs
+  USING pgroonga (record pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record &` 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/script-v2/object/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/object/seqscan.sql    2017-05-08 18:32:48 +0900 (fe13ad4)
@@ -0,0 +1,19 @@
+CREATE TABLE logs (
+  id int,
+  record jsonb
+);
+
+INSERT INTO logs VALUES (1, '{"message": {"code": 100, "content": "hello"}}');
+INSERT INTO logs VALUES (1, '{"message": "hello"}');
+INSERT INTO logs VALUES (1, '{"message": ["hello", "world"]}');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, record
+  FROM logs
+ WHERE record &` 'paths @ ".message" && type == "object"'
+ ORDER BY id;
+
+DROP TABLE logs;

  Added: sql/jsonb/script-v2/value/boolean/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/value/boolean/bitmapscan.sql    2017-05-08 18:32:48 +0900 (7318c06)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/value/boolean/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/value/boolean/indexscan.sql    2017-05-08 18:32:48 +0900 (ad3f211)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/value/boolean/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/value/boolean/seqscan.sql    2017-05-08 18:32:48 +0900 (b830c3e)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  true}');
+INSERT INTO fruits VALUES (2, '{"banana": false}');
+INSERT INTO fruits VALUES (3, '{"peach":  true}');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'boolean == true'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/value/number/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/value/number/bitmapscan.sql    2017-05-08 18:32:48 +0900 (0bf6a03)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/value/number/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/value/number/indexscan.sql    2017-05-08 18:32:48 +0900 (8ea1634)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/value/number/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/value/number/seqscan.sql    2017-05-08 18:32:48 +0900 (5cfa1a9)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"apple":  100}');
+INSERT INTO fruits VALUES (2, '{"banana":  30}');
+INSERT INTO fruits VALUES (3, '{"peach":  150}');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'type == "number" && number <= 100'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/value/string/bitmapscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/value/string/bitmapscan.sql    2017-05-08 18:32:48 +0900 (51bd11f)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = off;
+SET enable_bitmapscan = on;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/value/string/indexscan.sql (+22 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/value/string/indexscan.sql    2017-05-08 18:32:48 +0900 (0b17b77)
@@ -0,0 +1,22 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+
+CREATE INDEX pgroonga_index ON fruits
+  USING pgroonga (items pgroonga.jsonb_ops_v2);
+
+SET enable_seqscan = off;
+SET enable_indexscan = on;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Added: sql/jsonb/script-v2/value/string/seqscan.sql (+19 -0) 100644
===================================================================
--- /dev/null
+++ sql/jsonb/script-v2/value/string/seqscan.sql    2017-05-08 18:32:48 +0900 (5962ef4)
@@ -0,0 +1,19 @@
+CREATE TABLE fruits (
+  id int,
+  items jsonb
+);
+
+INSERT INTO fruits VALUES (1, '{"name": "apple"}');
+INSERT INTO fruits VALUES (2, '{"type": "apple"}');
+INSERT INTO fruits VALUES (3, '{"name": "peach"}');
+
+SET enable_seqscan = on;
+SET enable_indexscan = off;
+SET enable_bitmapscan = off;
+
+SELECT id, items
+  FROM fruits
+ WHERE items &` 'string == "apple"'
+ ORDER BY id;
+
+DROP TABLE fruits;

  Modified: src/pgrn-jsonb.c (+48 -17)
===================================================================
--- src/pgrn-jsonb.c    2017-05-08 14:52:03 +0900 (8f7487c)
+++ src/pgrn-jsonb.c    2017-05-08 18:32:48 +0900 (b177bfa)
@@ -21,6 +21,9 @@
 
 #ifdef PGRN_SUPPORT_JSONB
 PGRN_FUNCTION_INFO_V1(pgroonga_match_jsonb);
+
+/* v2 */
+PGRN_FUNCTION_INFO_V1(pgroonga_script_jsonb);
 #endif
 
 #ifdef PGRN_SUPPORT_JSONB
@@ -1037,14 +1040,10 @@ PGrnJSONBDeleteValues(grn_obj *valuesTable, grn_obj *valueIDs)
 	}
 }
 
-/**
- * pgroonga.match_jsonb(jsonb, query) : bool
- */
-Datum
-pgroonga_match_jsonb(PG_FUNCTION_ARGS)
+static bool
+pgroonga_script_jsonb_raw(Jsonb *target,
+						  const char *script, unsigned int scriptSize)
 {
-	Jsonb *jsonb = PG_GETARG_JSONB(0);
-	text *query = PG_GETARG_TEXT_PP(1);
 	grn_obj valueIDs;
 	PGrnJSONBInsertData data;
 	JsonbIterator *iter;
@@ -1059,28 +1058,27 @@ pgroonga_match_jsonb(PG_FUNCTION_ARGS)
 	GRN_PTR_INIT(&valueIDs, GRN_OBJ_VECTOR, grn_obj_id(ctx, data.valuesTable));
 	data.valueIDs = &valueIDs;
 	PGrnJSONBInsertDataInit(&data);
-	iter = JsonbIteratorInit(&(jsonb->root));
+	iter = JsonbIteratorInit(&(target->root));
 	PGrnJSONBInsertContainer(&iter, &data);
 	PGrnJSONBInsertDataFin(&data);
 
 	PG_TRY();
 	{
 		GRN_EXPR_CREATE_FOR_QUERY(ctx, tmpValuesTable, filter, dummy_variable);
-		PGrnCheck("match_jsonb: failed to create expression object");
+		PGrnCheck("jsonb_script: failed to create expression object");
 		grn_expr_parse(ctx, filter,
-					   VARDATA_ANY(query),
-					   VARSIZE_ANY_EXHDR(query),
+					   script, scriptSize,
 					   NULL, GRN_OP_MATCH, GRN_OP_AND,
 					   GRN_EXPR_SYNTAX_SCRIPT);
-		PGrnCheck("match_jsonb: failed to parse query: <%.*s>",
-				  (int)VARSIZE_ANY_EXHDR(query),
-				  VARDATA_ANY(query));
+		PGrnCheck("jsonb_script: failed to parse script: <%.*s>",
+				  (int)scriptSize,
+				  script);
 		result = grn_table_create(ctx, NULL, 0, NULL,
 								  GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC,
 								  tmpValuesTable, NULL);
-		PGrnCheck("match_jsonb: failed to create result table");
+		PGrnCheck("jsonb_script: failed to create result table");
 		grn_table_select(ctx, tmpValuesTable, filter, result, GRN_OP_OR);
-		PGrnCheck("match_jsonb: failed to select");
+		PGrnCheck("jsonb_script: failed to select");
 	}
 	PG_CATCH();
 	{
@@ -1102,6 +1100,38 @@ pgroonga_match_jsonb(PG_FUNCTION_ARGS)
 	PGrnJSONBDeleteValues(tmpValuesTable, &valueIDs);
 	GRN_OBJ_FIN(ctx, &valueIDs);
 
+	return matched;
+}
+
+/**
+ * pgroonga.match_jsonb(jsonb, query) : bool
+ */
+Datum
+pgroonga_match_jsonb(PG_FUNCTION_ARGS)
+{
+	Jsonb *jsonb = PG_GETARG_JSONB(0);
+	text *script = PG_GETARG_TEXT_PP(1);
+	bool matched;
+
+	matched = pgroonga_script_jsonb_raw(jsonb,
+										VARDATA_ANY(script),
+										VARSIZE_ANY_EXHDR(script));
+	PG_RETURN_BOOL(matched);
+}
+
+/**
+ * pgroonga.script_jsonb(target jsonb, script text) : bool
+ */
+Datum
+pgroonga_script_jsonb(PG_FUNCTION_ARGS)
+{
+	Jsonb *jsonb = PG_GETARG_JSONB(0);
+	text *script = PG_GETARG_TEXT_PP(1);
+	bool matched;
+
+	matched = pgroonga_script_jsonb_raw(jsonb,
+										VARDATA_ANY(script),
+										VARSIZE_ANY_EXHDR(script));
 	PG_RETURN_BOOL(matched);
 }
 
@@ -1418,7 +1448,8 @@ PGrnJSONBBuildSearchCondition(PGrnSearchData *data,
 	subFilter = PGrnLookup("sub_filter", ERROR);
 	grn_obj_reinit(ctx, &(buffers->general), GRN_DB_TEXT, 0);
 
-	if (key->sk_strategy == PGrnQueryStrategyNumber)
+	if (key->sk_strategy == PGrnQueryStrategyNumber ||
+		key->sk_strategy == PGrnScriptStrategyV2Number)
 	{
 		unsigned int nthCondition = 0;
 		PGrnConvertFromData(key->sk_argument, TEXTOID, &(buffers->general));




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