Repository navigation
fix(engine): classify a lexical rebuild by the data it discards, so that one of a field that is not stored is a Reindex when it keeps every document's data (#1889) - #1903
Merged
Conversation
…hat one of a field that is not stored is a Reindex when it keeps every document's data (#1889) classify_change reads the options only and calls every lexical change that rebuilds a field that is not stored Destructive. update_field raised a Reindex to Destructive from the data its rebuild discards (#1872), but never lowered a Destructive: turning doc_values on for a field never stored, which keeps every document's terms and points, or an analyzer change of a field that holds no document, was reported as Destructive and recorded in pending_reindex, where it stayed until every document was put again (#1890). update_field now classifies a change between two lexical options by the new classify_lexical_rebuild: Destructive when the rebuild discards a live document's data, a Reindex otherwise, whether the field is stored or not. Turning indexed on for a field that is not stored stays Destructive: a document written while the field was neither indexed nor stored kept nothing of its value, and nothing tells it from a document without the field. An applied call classifies from the rebuild's count, a dry run and a call refused for want of reindex from rebuild_would_discard. A rebuild commits the cached writer first, so a dry run now also reads the writer's documents since the last commit, with the rebuild's own test: the buffered documents and the segments flushed and not yet published, skipping the documents deleted since then. It used to skip them as documents with a stored value, which holds for a stored field only. LexicalIndexWriter gets rebuild_would_discard_uncommitted for it, with a default that fails, and LexicalStore::rebuild_would_discard asks the index and then the writer. Closes #1889
12 tasks done
This was referenced Dec 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Engine::update_fieldnow classifies a change between two lexical options by the data its rebuild discards, whether the field is stored or not:Destructivewhen it discards a live document's data, aReindexotherwise. Before,classify_changecalled every rebuild of a field that is not storedDestructivefrom the options alone, andupdate_fieldcould only raise aReindexfrom the data (#1872), never lower aDestructive. A dry run now also reads the documents written since the last commit, which the rebuild commits first.Closes #1889
The bug
The investigation reproduced it on
de2f1797, with a dry run, the applied call and a commit:doc_valueson for anIntegerfield never stored keeps all 4 documents found, and wasDestructiveand recorded inpending_reindex;Textfield not stored and holding no document wasDestructiveand recorded.Since #1890 such a record stays until every document written before the change is deleted or put again.
The rule
Destructivewhen the rebuild discards the data of a live document: a document with the field's data and no stored value of it, whose data the new option does not index as the old one did (FieldOption::keeps_index_data_under). A document without a stored value has no doc values or stored tokens for highlighting to lose, since the writer builds both from stored values only.indexedon for a field that is not stored staysDestructive, though it discards nothing. A document written while the field was neither indexed nor stored kept nothing of its value, and the index cannot tell it from a document without the field.Reindexotherwise: every document has a stored value to rebuild from, keeps its data, or has none to lose. A new option that does not index the field drops every document's terms and points and counts none, as turningindexedoff does (fix(lexical/index): the whole reader's BKD queries skip the segments that hold a field without its tree, which per-segment views scan #1868): a document put under it would hold none either.classify_changedoes not change. It stays the classification from the options alone, andcheck_lexical_field_records(#1873) reads it only forMetadataOnlyagainst the rest.Changes
laurus/src/engine/schema.rs:classify_lexical_rebuild(old, new, discards), the rule above.FieldChangeKind::Destructiveandclassify_changefollow;classify_change's also names fix(lexical/index): the whole reader's BKD queries skip the segments that hold a field without its tree, which per-segment views scan #1868's exception.laurus/src/engine.rs(update_field): for a change between two lexical options thatclassify_changecallsReindexorDestructive:reindex, classifies withrebuild_would_discard, now for aDestructivetoo;purge, the record inpending_reindexand the warning follow the result. Before, a lexicalDestructivewas recorded, and the warning logged, with a count of 0. Turningindexedon for a field not stored logs its own warning.change_field_kind) is left as it is.LexicalStore::rebuild_would_discardasks the index about the published segments, then the cached writer about its documents since the last commit. It used to skip those as documents with a stored value, which holds for a stored field only.LexicalIndexWriter::rebuild_would_discard_uncommittedis new, with a default that fails, asLexicalIndex::rebuild_would_discard's does.InvertedIndexWriterimplements it with the rebuild's own test, over the buffered documents (with the field's length and no stored value) and the segments flushed and not yet published (MergeEngine::any_document_without_stored_value), skipping the documents deleted since the last commit. It reads nothing when the new option does not index the field or indexes it as the old one did.concepts/schema_and_fields.md, en/ja):ReindexandDestructiveitems.stored: falsefield isDestructive: Boolean, Text (multi_valued,position_increment_gap) and Bytes. A Bytes field holds nothing but its stored values, so turning itsmulti_valuedoff is aReindexwhether it is stored or not.Changes from the plan
InvertedIndex::rebuild_would_discardcall a check handed to it by the store.LexicalIndexis a public trait, so its method keeps its signature: the store asks the index and then the writer. The test and the documents read are the plan's.Reindex. The independent review found it: aTextfield not stored and holding data, changed toBytes, or withindexedturned off together with an analyzer change, drops every document's terms and points, counts none, and is now aReindexrecorded nowhere. Under fix(engine): a lexical change with no stored value to rebuild from is classified Reindex and discards the field's data #1685 it wasDestructive. It is kept, for the reason in "The rule"; turningindexedback on later is caught by the exception. The docs say so, and a test pins it.What a user sees
stored: falselexical field is reported as aReindex, and not recorded inpending_reindex, when no live document loses its data: one that indexes the field as before (doc_values,highlight_offsets,multi_valuedorindexedturned on,term_vectorsoff), one of a field holding no document, one to an option that does not index the field, and turningmulti_valuedoff on a Bytes field. It still needsreindex.reindex, of such a change reads the index (see the measurements).!.Tests
laurus/tests/engine_unstored_documents_rebuild_test.rs(fix(engine): a lexical Reindex drops the terms and points of the documents written while the field was not stored #1872's file). Each case runs a dry run and then the applied call, and checks the record:doc_valueson for a field never stored, for each of the 7 kinds, is aReindexboth ways, records nothing, and keeps the 4 documents found. It replacesa_field_never_stored_keeps_its_data_and_stays_destructive, which pinned the over-report.IntegertoFloat, are aReindex.Textfield never stored, with data, isDestructive, recorded, and finds nothing after.indexedon for a field not stored staysDestructiveand recorded, forIntegerandText, and for a field holding no document.Destructiveas a dry run and applied; deleted before the commit, both areReindex.reindexnames T1's change aReindex.multi_valuedoff on a Bytes field never stored is aReindex.TexttoBytes,indexedoff with an analyzer change, andindexedoff on anIntegerwith the documents not committed, are aReindex.lexical/index/inverted/writer.rs, T7: withmax_buffered_docs: 2, the writer's check finds a document in a flushed, unpublished segment (the test checks that the segment is there and the buffer empty), not once it is deleted, and one in the buffer; a change that keeps the data finds none.lexical/store.rs, T7:rebuild_would_discardagrees with the countrebuild_fieldreturns, with the documents uncommitted (true, 3) and deleted (false, 0).engine/schema.rs, T8: the table ofclassify_lexical_rebuild.In the whole
laurussuite, T1's predecessor was the only existing test whose expectation changed. #1685's and #1890's tests hold data in the field and stayDestructive.RED
Each of these, put in alone, fails the tests named; the code was then restored and the same 18 tests passed again:
DestructiveindexedonMeasurements
A dry run that classifies a lexical rebuild reads the index. On evo-x2 (CPUs 8-15, release,
FileStorage), on an index of 100,000 documents built by 10 commits of 10,000, the median of one dry run, 5 times (the 5 medians of each case lie within 1% of each other):MetadataOnlychange, which reads nothingMetadataOnlyTextfield not stored, with data (stops at the first document)DestructiveReindexReindexReindexstoredwas turned offReindexOn
main, cases 1-3 and 4b return at the floor, sinceclassify_changecalls themDestructiveand the dry run reads nothing. So a dry run of such a change costs up to what a stored field's already does (4a). Case 1's 3.3 ms, though it stops at the first document, looks like the cost of opening a segment and reading its documents' list and stored documents; it was not broken down. An applied call costs the same as before: the rebuild reads every document anyway.Checks
On evo-x2 (Linux x86_64), on the commit of this PR:
cargo fmt --all -- --check;embeddings-all,-D warnings, and onlaurus-wasmforwasm32-unknown-unknown;scripts/check-rustdoc.py,check-ci-filters.py,check-job-timeouts.py(with their tests) andcheck-binding-snippets.py;laurus(embeddings-all,pq-fastscan) 4,298 passed and 28 ignored,laurus-server334,laurus-mcp53,laurus-cli89.The bindings, aarch64, Windows and the index interop are left to CI: a change under
laurus/starts all of them. The mdBook build runs only in Deploy Documentation after the merge; it was not run here, asmdbookis not installed.Out of scope
Destructivechange of a vector field holding no vector (such as its dimension), and a change between a lexical and a vector option of a field holding no document, are recorded though they discard nothing. They are not lexical rebuilds: fix(engine): a change of a vector field holding no vector, or between a lexical and a vector option of a field holding no document, is recorded in pending_reindex though it discards nothing #1902.storedwas turned on later (fix(engine): a lexical Reindex drops the terms and points of the documents written while the field was not stored #1872): turningindexedon is aReindexthere, and the documents written while the field was neither indexed nor stored stay unfound; nothing tells them apart. The docs say so.