Query processing: document-at-a-time and term-at-a-time
Document-at-a-time (DAAT) and term-at-a-time (TAAT) are two standard strategies to process multi-term queries over inverted indexes; they differ in the order of scanning postings lists and in how partial scores (accumulators) are updated, which affects efficiency, memory access pattern, and suitabil
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Search engines and many information-retrieval systems must answer user queries by combining evidence from several index lists (postings). An engineer chooses between document-at-a-time (DAAT) and term-at-a-time (TAAT) processing to optimise speed, memory use and the ability to do early termination for top-k results — for example in a web search backend or a specialised document search service.
Key ideas
Start with definitions and basic assumptions.
- Posting: a pair (docID, payload) stored in a postings list for a term. Payload could be frequency, positions, or an impact value.
- Postings list: a sorted sequence of postings for a term; sorted by increasing docID. Denote the length of the postings list for term t by N_t.
- Query Q: a set or bag of terms {t1, t2, ..., tm} to score and retrieve documents for.
- Accumulator: a memory location (one per candidate doc or in a dense array indexed by docID) used to collect partial scores for a document while processing the query.
- Top-k retrieval: retrieving the k documents with largest scores for a query, according to some scoring function.
Two main processing strategies:
- Term-at-a-time (TAAT)
- Definition: TAAT scans the postings list for one term completely, updates accumulators for all documents in that list, then moves to the next term. The order is: term -> all postings -> next term.
- Assumptions: We assume an accumulator structure that supports random writes indexed by docID (dense array or hash map). Each posting read causes one accumulator update (additive if scoring is additive).
- Behaviour: Reads each postings list sequentially. For each posting (docID, payload) of term t, compute the partial contribution to the score (for example tf-idf weight) and add it to accumulator[docID]. After processing all terms, scan accumulators (or maintain a candidate heap) to select top-k.
- Strengths: Very good locality when scanning a single postings list; simple to implement; useful when there are few queries or when the posting payloads are large. Good fit if accumulators are small or fits in cache.
- Weaknesses: Random writes across accumulators (poor write locality) and must write potentially to many distinct accumulator entries; hard to do early termination since you do not know the final order until all terms processed.
- Document-at-a-time (DAAT)
- Definition: DAAT advances pointers in all (or a subset of) postings lists together to select a document ID, then computes or finalises that document's score combining contributions from the lists. The order is: docID -> combine contributions from terms that mention that docID -> move to next docID.
- Two common DAAT modes: exact merging (to compute full scores for all matching docs) and DAAT for top-k with early termination (WAND, Block-Max WAND (BMW), MaxScore).
- Assumptions: Postings lists are sorted by docID and you can advance a pointer efficiently. Often we maintain a heap or use pointer-advance strategies to find the next candidate docID across m lists.
- Behaviour: Maintain current pointers p_t into each list. Repeatedly choose the smallest current docID among pointers (or use a heuristic upper-bound to skip ranges), compute that document's total score by gathering contributions from every list where the current docID matches, then advance pointers that matched. Optionally use upper bounds on remaining unseen contributions to skip documents that cannot enter top-k.
- Strengths: Good when you want to compute top-k and support early termination since you can compute score bounds and skip many docs. Writes are concentrated (compute a score then decide to keep it) and can avoid touching accumulators for many docs.
- Weaknesses: Requires coordinated pointer movement across lists; random reads across lists if lists differ in length; more complex to implement.
Precise comparison and cost notions (symbols):
- Let m be number of query terms, N_t length of postings list for term t, and P = sum_{t=1..m} N_t the total number of postings read if every list is fully scanned.
- TAAT cost model: reads every posting for each term, so reads ~ P postings; each posting leads to one accumulator update. Candidate selection needs scanning accumulators (O(number of distinct docs seen) at end) or maintaining a min-heap of size k to track the current top-k (O(log k) per update).
- DAAT cost model: in a naïve pointer-advance merge, each list pointer moves forward at most N_t times; the number of pointer-advance comparisons depends on algorithm (pairwise pointer advance, min-heap across current heads, or skipping using upper bounds). For top-k with a heap of size k, maintaining the top-k set adds O(log k) per candidate output; advanced DAAT algorithms add cost for bound checks but reduce number of scored docs.
Describe exactly what to draw (diagram for an exam):
- Draw three vertical columns labelled t1, t2, t3 (these are postings lists). Under each, draw an ordered list of docIDs with their payloads (e.g., docID:tf). Draw pointers p1, p2, p3 at current positions.
- For TAAT: draw an arrow scanning t1 top-to-bottom, writing to a horizontal array labelled accumulators indexed by docID. Then arrows from t2, t3 to the accumulator array.
- For DAAT: draw the three list heads compared (a small box showing current docIDs) and an arrow selecting the minimum docID, then arrows from lists that match the selected docID into a small combine box that outputs the final score for that docID.
Algorithms often taught and theorems/observations:
- Exact statement: For TAAT, worst-case number of accumulator updates = P = sum_t N_t (each posting causes one update). This is a direct count; no further assumptions.
- Exact statement: For DAAT using an m-way min-heap of list heads, the number of heap operations is O(P log m) in the worst case (each time we pop the smallest head and push the next from that list). This assumes heap operations cost O(log m) and each posting is inserted/popped at most once.
- Exact statement: For DAAT top-k with an early-termination algorithm that uses per-list upper bounds U_t on unseen contributions, if current top-k threshold is τ, any document whose potential maximum score ≤ τ can be safely skipped. This correctness depends on monotone scoring (score is sum of non-negative per-term contributions). State the assumption: scoring contributions are non-negative and upper bounds are valid (block- or list-level maxima). Note: BM25's RSJ idf can be negative for very frequent terms; many systems clip idf at 0 to satisfy the non-negativity assumption required by WAND/BMW.
Common DAAT optimisations to know (definitions):
- WAND (Weak-AND): uses a pivoting strategy and per-list upper bounds to skip advancing some lists; correct when scoring is monotonic.
- Block-Max WAND (BMW): stores per-block maximum contributions, allowing tighter bounds than per-list maxima and greater skipping.
- Impact-ordering: postings lists sorted by decreasing impact (contribution) rather than docID; used mainly with TAAT to allow early stopping when remaining impacts are too small.
- MaxScore: a DAAT top-k method that orders terms by decreasing upper bound and skips scoring a document once the current partial score plus the sum of remaining upper bounds is ≤ the threshold τ; cheaper than WAND when m is small.
Formulas
P = sum_{t=1..m} N_t where P is total postings across query terms, N_t is number of postings for term t.
score(d, Q) = sum_{t in Q} w_{t,d} * w_{t,Q} where w_{t,d} is term t's weight in document d and w_{t,Q} is term t's query weight; applies to additive scoring (e.g., TF-IDF; BM25 can be expressed as an additive sum by factoring idf as w_{t,Q}). Units: dimensionless (weights).
TAAT_cost ≈ O(P) reads and accumulator updates proportional to P; applies when each posting is processed once.
DAAT_heap_cost ≈ O(P · log m) when using an m-way min-heap over current list heads. Assumes heap operations cost O(log m) and each posting head enters/exits heap once.
DAAT_with_topk ≈ O(P_scored · log k) where P_scored is number of documents whose full score is computed and k is requested top size.
Worked examples
Example 1 — Exam-style long question (model answer): "Compare TAAT and DAAT and analyse costs for top-k retrieval." Model answer structure (full marks answer includes these points):
- Define TAAT and DAAT precisely (as above). State assumptions (sorted by docID, additive monotone scoring).
- Cost analysis: give P = sum N_t. For TAAT, cost O(P) to read postings plus cost to maintain accumulators; random writes across document-space. For DAAT, describe m-way merge: pointer advances bounded by N_t per list; with min-heap cost O(P log m) and with direct pointer-advance comparisons cost between O(P·m) and O(P log m) depending on implementation (linear scan of m heads vs. heap). Explain top-k behaviour: DAAT with WAND/BMW can reduce P_scored dramatically by using upper bounds. TAAT can use impact-ordered lists to early-terminate, but requires reordering postings lists by impact and is less flexible for mixed query types.
- Practical considerations: memory for accumulators (dense array sized by document collection vs. sparse hashmap), cache effects, I/O patterns and multi-threading.
- Conclude: For simple full scoring TAAT is simple and linear in P; for top-k retrieval with early termination DAAT variants (WAND/BMW) are often faster in practice. Mention tradeoffs and where each is used (TAAT for small collections or impact-ordered systems; DAAT for large-scale web search with top-k and early termination).
Example 2 — Numerical step-by-step (small postings): Given query Q = {t1, t2, t3}, postings lists (docID:tf):
- t1: (2:3), (5:1), (7:2)
- t2: (1:1), (2:2), (7:1), (8:1)
- t3: (2:1), (3:2), (7:3) Assume simple scoring weight w_{t,d} = tf (term frequency) and query weights w_{t,Q} = 1. Compute top-2 by TAAT and DAAT. TAAT steps:
- Initialize empty accumulator map A.
- Scan t1: A[2]+=3 => A[2]=3; A[5]=1; A[7]=2.
- Scan t2: A[1]=1; A[2]+=2 => A[2]=5; A[7]+=1 => A[7]=3; A[8]=1.
- Scan t3: A[2]+=1 => A[2]=6; A[3]=2; A[7]+=3 => A[7]=6. Final accumulators: A[1]=1, A[2]=6, A[3]=2, A[5]=1, A[7]=6, A[8]=1. Top-2 = docs 2 and 7 (tie at 6). Answer: top-2 = {2,7} with score 6 each. DAAT steps (pointer-advance):
- Start heads: t1->2, t2->1, t3->2. Smallest docID is 1 (only in t2), compute score: 1. Advance t2->2.
- Heads: t1->2, t2->2, t3->2. All match docID 2: score = 3+2+1 = 6. Advance each: t1->5, t2->7, t3->3.
- Heads: t1->5, t2->7, t3->3. Smallest is 3 (only t3): score =2. Advance t3->7.
- Heads: t1->5, t2->7, t3->7. Smallest 5 (only t1): score=1. Advance t1->7.
- Heads: t1->7, t2->7, t3->7. All match 7: score=2+1+3=6. Advance: t1 and t3 exhausted; t2->8.
- Heads: t2->8 (only t2 remains): score=1. Advance t2 to end. Final scores same as TAAT. Answer: top-2 = {2,7} with score 6 each. This demonstrates both methods produce same result; DAAT computed document scores when docIDs aligned, TAAT wrote many accumulator updates.
Common mistakes
- Claiming DAAT is always faster — performance depends on scoring, ability to bound and skip, and memory/cache behaviour.
- Ignoring the assumption of monotone, non-negative contributions when stating correctness of WAND/BMW early termination.
- Using the DAAT heap cost O(P log m) as always tight without mentioning that pointer-advance implementations can behave better in practice.
For your exam
Question types you should expect:
- Definitions and short notes: define TAAT and DAAT, accumulator, WAND, BMW.
- Derivations and proofs: prove correctness of skipping using upper bounds (show monotonicity argument), derive worst-case cost for TAAT (P postings) and DAAT with heap (P log m heap ops).
- Numerical trace/diagram: draw postings and show step-by-step TAAT and DAAT execution (as in worked example 2).
- Comparative essay: tradeoffs, when to use which, memory and cache consequences. What full-marks answers include: precise definitions, stated assumptions, step-by-step derivations or traced executions, clear diagrams labelled as requested, and conclusions with tradeoffs.
Quick check
- In TAAT, what does each posting cause at minimum?
- Name two DAAT optimisations that allow early termination.
- If query has m terms with total postings P, what is the basic TAAT cost in terms of P? Answers: 1) An accumulator update (write). 2) WAND and Block-Max WAND (BMW). 3) O(P).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?