Kouhei Sutou
null+****@clear*****
Wed Jan 29 11:32:43 JST 2014
Kouhei Sutou 2014-01-29 11:32:43 +0900 (Wed, 29 Jan 2014) New Revision: 0f4323ef1a0e55a772684ec7590e5558e06badb9 https://github.com/groonga/groonga/commit/0f4323ef1a0e55a772684ec7590e5558e06badb9 Message: Run cascade delete only for source's range is same as index's domain Cascade delete feature is introduced to avoid dangling references. If source's range is different with index's domain, the case doesn't cause dangling references. So we don't run cascade delete for the case. Not referenced case (This case's behavior is changed. Cascade delete isn't ran.): table_create Users TABLE_HASH_KEY ShortText table_create URLs TABLE_HASH_KEY ShortText column_create Users bookmarks COLUMN_VECTOR ShortText # <- Not URLs type! column_create URLs bookmarks_index COLUMN_INDEX Users bookmarks Referenced case (This case's behavior isn't changed. Cascade delete is ran.): table_create Users TABLE_HASH_KEY ShortText table_create URLs TABLE_HASH_KEY ShortText column_create Users bookmarks COLUMN_VECTOR URLs # <- URLs type! column_create URLs bookmarks_index COLUMN_INDEX Users bookmarks [groonga-dev,02073] Reported by yoku. Thanks!!! Added files: test/command/suite/delete/index/have_tokenizer.expected test/command/suite/delete/index/have_tokenizer.test Modified files: lib/db.c test/command/suite/delete/reference/vector_type.expected Modified: lib/db.c (+26 -6) =================================================================== --- lib/db.c 2014-01-29 11:04:48 +0900 (d601d92) +++ lib/db.c 2014-01-29 11:32:43 +0900 (621c57e) @@ -1537,6 +1537,7 @@ delete_reference_records_in_index(grn_ctx *ctx, grn_obj *table, grn_id id, grn_obj source_ids; unsigned int i, n_ids; grn_obj sources; + grn_bool have_reference_source = GRN_FALSE; GRN_UINT32_INIT(&source_ids, GRN_OBJ_VECTOR); GRN_PTR_INIT(&sources, GRN_OBJ_VECTOR, 0); @@ -1553,7 +1554,17 @@ delete_reference_records_in_index(grn_ctx *ctx, grn_obj *table, grn_id id, source_id = GRN_UINT32_VALUE_AT(&source_ids, i); source = grn_ctx_at(ctx, source_id); - GRN_PTR_PUT(ctx, &sources, source); + if (grn_obj_get_range(ctx, source) == index->header.domain) { + GRN_PTR_PUT(ctx, &sources, source); + have_reference_source = GRN_TRUE; + } else { + grn_obj_unlink(ctx, source); + GRN_PTR_PUT(ctx, &sources, NULL); + } + } + + if (!have_reference_source) { + goto exit; } ii_cursor = grn_ii_cursor_open(ctx, ii, id, GRN_ID_NIL, GRN_ID_MAX, @@ -1564,6 +1575,9 @@ delete_reference_records_in_index(grn_ctx *ctx, grn_obj *table, grn_id id, while ((posting = grn_ii_cursor_next(ctx, ii_cursor))) { grn_obj *source = GRN_PTR_VALUE_AT(&sources, posting->sid - 1); + if (!source) { + continue; + } switch (source->header.type) { case GRN_COLUMN_VAR_SIZE : switch (source->header.flags & GRN_OBJ_COLUMN_TYPE_MASK) { @@ -1655,11 +1669,17 @@ delete_reference_records(grn_ctx *ctx, grn_obj *table, grn_id id) GRN_HASH_EACH(ctx, cols, tid, &key, NULL, NULL, { grn_obj *col = grn_ctx_at(ctx, *key); - if (col && col->header.type == GRN_COLUMN_INDEX) { - delete_reference_records_in_index(ctx, table, id, col); - if (ctx->rc != GRN_SUCCESS) { - break; - } + if (!col) { + continue; + } + if (col->header.type != GRN_COLUMN_INDEX) { + grn_obj_unlink(ctx, col); + continue; + } + delete_reference_records_in_index(ctx, table, id, col); + grn_obj_unlink(ctx, col); + if (ctx->rc != GRN_SUCCESS) { + break; } }); Added: test/command/suite/delete/index/have_tokenizer.expected (+116 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/delete/index/have_tokenizer.expected 2014-01-29 11:32:43 +0900 (956b453) @@ -0,0 +1,116 @@ +table_create Memos TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Memos content COLUMN_SCALAR Text +[[0,0.0,0.0],true] +table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto +[[0,0.0,0.0],true] +column_create Terms memo_content COLUMN_INDEX|WITH_POSITION Memos content +[[0,0.0,0.0],true] +load --table Memos +[ +{"content": "Today is sunny day."}, +{"content": "Today is rainy day."} +] +[[0,0.0,0.0],2] +select Memos --query 'content:@sunny' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "content", + "Text" + ] + ], + [ + 1, + "Today is sunny day." + ] + ] + ] +] +delete Terms --filter '_key == "sunny"' +[[0,0.0,0.0],true] +select Terms --output_columns _key +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 5 + ], + [ + [ + "_key", + "ShortText" + ] + ], + [ + "." + ], + [ + "day" + ], + [ + "is" + ], + [ + "rainy" + ], + [ + "today" + ] + ] + ] +] +select Memos --query 'content:@sunny' +[[0,0.0,0.0],[[[0],[["_id","UInt32"],["content","Text"]]]]] +select Memos +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 2 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "content", + "Text" + ] + ], + [ + 1, + "Today is sunny day." + ], + [ + 2, + "Today is rainy day." + ] + ] + ] +] Added: test/command/suite/delete/index/have_tokenizer.test (+21 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/delete/index/have_tokenizer.test 2014-01-29 11:32:43 +0900 (9570756) @@ -0,0 +1,21 @@ +table_create Memos TABLE_NO_KEY +column_create Memos content COLUMN_SCALAR Text + +table_create Terms TABLE_PAT_KEY ShortText \ + --default_tokenizer TokenBigram \ + --normalizer NormalizerAuto +column_create Terms memo_content COLUMN_INDEX|WITH_POSITION Memos content + +load --table Memos +[ +{"content": "Today is sunny day."}, +{"content": "Today is rainy day."} +] + +select Memos --query 'content:@sunny' + +delete Terms --filter '_key == "sunny"' +select Terms --output_columns _key + +select Memos --query 'content:@sunny' +select Memos Modified: test/command/suite/delete/reference/vector_type.expected (+1 -1) =================================================================== --- test/command/suite/delete/reference/vector_type.expected 2014-01-29 11:04:48 +0900 (01f2624) +++ test/command/suite/delete/reference/vector_type.expected 2014-01-29 11:32:43 +0900 (34195b3) @@ -29,7 +29,7 @@ column_create URLs author COLUMN_SCALAR Users load --table Users [ ["_key","bookmarks"], -["mori",["http://mroonga.org/","http://ranguba.org/"]] +["mori",["http://mroonga.org/","http://groonga.org/","http://ranguba.org/"]] ] load --table URLs [ -------------- next part -------------- HTML����������������������������...Télécharger