Kouhei Sutou
null+****@clear*****
Sun Jan 18 23:52:20 JST 2015
Kouhei Sutou 2015-01-18 23:52:20 +0900 (Sun, 18 Jan 2015) New Revision: 4b4dc99c28791427cb4e29c295d43cc5af338381 https://github.com/pgroonga/pgroonga/commit/4b4dc99c28791427cb4e29c295d43cc5af338381 Message: Support single column search with multiple column index Modified files: expected/text/multiple/contain/bitmapscan.out expected/text/multiple/contain/indexscan.out expected/text/multiple/contain/seqscan.out pgroonga.c sql/text/multiple/contain/bitmapscan.sql sql/text/multiple/contain/indexscan.sql sql/text/multiple/contain/seqscan.sql Modified: expected/text/multiple/contain/bitmapscan.out (+10 -3) =================================================================== --- expected/text/multiple/contain/bitmapscan.out 2015-01-18 23:48:04 +0900 (d680f3d) +++ expected/text/multiple/contain/bitmapscan.out 2015-01-18 23:52:20 +0900 (689add2) @@ -15,11 +15,18 @@ SET enable_indexscan = off; SET enable_bitmapscan = on; SELECT id, title, content FROM memos - WHERE title %% 'Groonga' OR content %% 'Groonga'; + WHERE title %% 'Groonga'; + id | title | content +----+---------+---------------------------------- + 2 | Groonga | is fast full text search engine. +(1 row) + +SELECT id, title, content + FROM memos + WHERE content %% 'Groonga'; id | title | content ----+----------+---------------------------------------------- - 2 | Groonga | is fast full text search engine. 3 | PGroonga | is a PostgreSQL extension that uses Groonga. -(2 rows) +(1 row) DROP TABLE memos; Modified: expected/text/multiple/contain/indexscan.out (+10 -3) =================================================================== --- expected/text/multiple/contain/indexscan.out 2015-01-18 23:48:04 +0900 (e9f88fe) +++ expected/text/multiple/contain/indexscan.out 2015-01-18 23:52:20 +0900 (74473e6) @@ -15,11 +15,18 @@ SET enable_indexscan = on; SET enable_bitmapscan = off; SELECT id, title, content FROM memos - WHERE title %% 'Groonga' OR content %% 'Groonga'; + WHERE title %% 'Groonga'; + id | title | content +----+---------+---------------------------------- + 2 | Groonga | is fast full text search engine. +(1 row) + +SELECT id, title, content + FROM memos + WHERE content %% 'Groonga'; id | title | content ----+----------+---------------------------------------------- - 2 | Groonga | is fast full text search engine. 3 | PGroonga | is a PostgreSQL extension that uses Groonga. -(2 rows) +(1 row) DROP TABLE memos; Modified: expected/text/multiple/contain/seqscan.out (+9 -1) =================================================================== --- expected/text/multiple/contain/seqscan.out 2015-01-18 23:48:04 +0900 (d204be7) +++ expected/text/multiple/contain/seqscan.out 2015-01-18 23:52:20 +0900 (dc6da9e) @@ -15,11 +15,19 @@ SET enable_indexscan = off; SET enable_bitmapscan = off; SELECT id, title, content FROM memos - WHERE title %% 'Groonga' OR content %% 'Groonga'; + WHERE title %% 'Groonga'; id | title | content ----+----------+---------------------------------------------- 2 | Groonga | is fast full text search engine. 3 | PGroonga | is a PostgreSQL extension that uses Groonga. (2 rows) +SELECT id, title, content + FROM memos + WHERE content %% 'Groonga'; + id | title | content +----+----------+---------------------------------------------- + 3 | PGroonga | is a PostgreSQL extension that uses Groonga. +(1 row) + DROP TABLE memos; Modified: pgroonga.c (+29 -6) =================================================================== --- pgroonga.c 2015-01-18 23:48:04 +0900 (b8ba49d) +++ pgroonga.c 2015-01-18 23:52:20 +0900 (7c6c727) @@ -635,17 +635,18 @@ GrnSearch(IndexScanDesc scan) Relation index = scan->indexRelation; GrnScanOpaque so = (GrnScanOpaque) scan->opaque; grn_obj *indexColumn; - grn_obj *matchColumns, *matchColumnsVariable; + grn_obj matchTargets; + grn_obj sectionID; grn_obj *expression, *expressionVariable; int i, nExpressions = 0; if (scan->numberOfKeys == 0) return; - GRN_EXPR_CREATE_FOR_QUERY(ctx, so->idsTable, - matchColumns, matchColumnsVariable); + GRN_PTR_INIT(&matchTargets, GRN_OBJ_VECTOR, GRN_ID_NIL); + GRN_UINT32_INIT(§ionID, 0); + indexColumn = GrnLookupIndexColumn(index, ERROR); - grn_expr_append_obj(ctx, matchColumns, indexColumn, GRN_OP_PUSH, 1); GRN_EXPR_CREATE_FOR_QUERY(ctx, so->idsTable, expression, expressionVariable); @@ -654,15 +655,27 @@ GrnSearch(IndexScanDesc scan) { ScanKey key = &(scan->keyData[i]); grn_bool isValidStrategy = GRN_TRUE; + grn_obj *matchTarget, *matchTargetVariable; /* NULL key is not supported */ if (key->sk_flags & SK_ISNULL) continue; + GRN_EXPR_CREATE_FOR_QUERY(ctx, so->idsTable, + matchTarget, matchTargetVariable); + GRN_PTR_PUT(ctx, &matchTargets, matchTarget); + + grn_expr_append_obj(ctx, matchTarget, indexColumn, GRN_OP_PUSH, 1); + + GRN_UINT32_SET(ctx, §ionID, key->sk_attno - 1); + grn_expr_append_const(ctx, matchTarget, §ionID, GRN_OP_PUSH, 1); + + grn_expr_append_op(ctx, matchTarget, GRN_OP_GET_MEMBER, 2); + grn_obj_reinit(ctx, &buffer, GrnGetType(index, key->sk_attno - 1), 0); GrnGetValue(index, key->sk_attno - 1, key->sk_argument, &buffer); - grn_expr_append_obj(ctx, expression, matchColumns, GRN_OP_PUSH, 1); + grn_expr_append_obj(ctx, expression, matchTarget, GRN_OP_PUSH, 1); grn_expr_append_obj(ctx, expression, &buffer, GRN_OP_PUSH, 1); switch (key->sk_strategy) @@ -709,7 +722,17 @@ GrnSearch(IndexScanDesc scan) so->idsTable, 0); grn_table_select(ctx, so->idsTable, expression, so->searched, GRN_OP_OR); grn_obj_unlink(ctx, expression); - grn_obj_unlink(ctx, matchColumns); + { + unsigned int i, nMatchTargets; + nMatchTargets = GRN_BULK_VSIZE(&matchTargets) / sizeof(grn_obj *); + for (i = 0; i < nMatchTargets; i++) + { + grn_obj *matchTarget = GRN_PTR_VALUE_AT(&matchTargets, i); + grn_obj_unlink(ctx, matchTarget); + } + } + GRN_OBJ_FIN(ctx, &matchTargets); + GRN_OBJ_FIN(ctx, §ionID); } static void Modified: sql/text/multiple/contain/bitmapscan.sql (+5 -1) =================================================================== --- sql/text/multiple/contain/bitmapscan.sql 2015-01-18 23:48:04 +0900 (6513f31) +++ sql/text/multiple/contain/bitmapscan.sql 2015-01-18 23:52:20 +0900 (7a0c38f) @@ -19,6 +19,10 @@ SET enable_bitmapscan = on; SELECT id, title, content FROM memos - WHERE title %% 'Groonga' OR content %% 'Groonga'; + WHERE title %% 'Groonga'; + +SELECT id, title, content + FROM memos + WHERE content %% 'Groonga'; DROP TABLE memos; Modified: sql/text/multiple/contain/indexscan.sql (+5 -1) =================================================================== --- sql/text/multiple/contain/indexscan.sql 2015-01-18 23:48:04 +0900 (6d2f133) +++ sql/text/multiple/contain/indexscan.sql 2015-01-18 23:52:20 +0900 (dc004c8) @@ -19,6 +19,10 @@ SET enable_bitmapscan = off; SELECT id, title, content FROM memos - WHERE title %% 'Groonga' OR content %% 'Groonga'; + WHERE title %% 'Groonga'; + +SELECT id, title, content + FROM memos + WHERE content %% 'Groonga'; DROP TABLE memos; Modified: sql/text/multiple/contain/seqscan.sql (+5 -1) =================================================================== --- sql/text/multiple/contain/seqscan.sql 2015-01-18 23:48:04 +0900 (af71b93) +++ sql/text/multiple/contain/seqscan.sql 2015-01-18 23:52:20 +0900 (ed174c1) @@ -19,6 +19,10 @@ SET enable_bitmapscan = off; SELECT id, title, content FROM memos - WHERE title %% 'Groonga' OR content %% 'Groonga'; + WHERE title %% 'Groonga'; + +SELECT id, title, content + FROM memos + WHERE content %% 'Groonga'; DROP TABLE memos; -------------- next part -------------- HTML����������������������������...ダウンロード