Kouhei Sutou
null+****@clear*****
Mon May 8 20:40:53 JST 2017
Kouhei Sutou 2017-05-08 20:40:53 +0900 (Mon, 08 May 2017) New Revision: 0561cd15354be7761da78fd77763f12e4379236f https://github.com/pgroonga/pgroonga/commit/0561cd15354be7761da78fd77763f12e4379236f Message: Add deleted record check for index scan GitHub: #36 Reported by peter-schmitz. Thanks!!! Modified files: src/pgroonga.c Modified: src/pgroonga.c (+35 -23) =================================================================== --- src/pgroonga.c 2017-05-08 20:33:18 +0900 (8468a57) +++ src/pgroonga.c 2017-05-08 20:40:53 +0900 (a4a3a1f) @@ -4020,6 +4020,7 @@ pgroonga_gettuple_raw(IndexScanDesc scan, ScanDirection direction) { PGrnScanOpaque so = (PGrnScanOpaque) scan->opaque; + bool found = false; PGrnEnsureCursorOpened(scan, direction, true); @@ -4031,38 +4032,49 @@ pgroonga_gettuple_raw(IndexScanDesc scan, grn_table_delete_by_id(ctx, so->sourcesTable, recordID); } - if (so->indexCursor) - { - grn_posting *posting; - grn_id termID; - grn_id id = GRN_ID_NIL; - posting = grn_index_cursor_next(ctx, so->indexCursor, &termID); - if (posting) - id = posting->rid; - so->currentID = id; - } - else + while (!found) { - so->currentID = grn_table_cursor_next(ctx, so->tableCursor); - } + if (so->indexCursor) + { + grn_posting *posting; + grn_id termID; + grn_id id = GRN_ID_NIL; + posting = grn_index_cursor_next(ctx, so->indexCursor, &termID); + if (posting) + id = posting->rid; + so->currentID = id; + } + else + { + so->currentID = grn_table_cursor_next(ctx, so->tableCursor); + } - if (so->currentID == GRN_ID_NIL) - { - return false; - } - else - { - GRN_BULK_REWIND(&(buffers->ctid)); - grn_obj_get_value(ctx, so->ctidAccessor, so->currentID, &(buffers->ctid)); - scan->xs_ctup.t_self = PGrnCtidUnpack(GRN_UINT64_VALUE(&(buffers->ctid))); + if (so->currentID == GRN_ID_NIL) + break; + + { + ItemPointerData ctid; + GRN_BULK_REWIND(&(buffers->ctid)); + grn_obj_get_value(ctx, + so->ctidAccessor, + so->currentID, + &(buffers->ctid)); + ctid = PGrnCtidUnpack(GRN_UINT64_VALUE(&(buffers->ctid))); + if (!ItemPointerIsValid(&ctid)) + continue; + + scan->xs_ctup.t_self = ctid; + } #ifdef PGRN_SUPPORT_INDEX_ONLY_SCAN if (scan->xs_want_itup) PGrnGetTupleFillIndexTuple(so, scan); #endif - return true; + found = true; } + + return found; } /** -------------- next part -------------- HTML����������������������������...Download