Techniquecore
Skip pointers
Also called skip pointers in posting lists.
Adds about sqrt(n) forward pointers to a posting list so an intersection can jump over runs that cannot match.
Skip pointers are extra forward links stored inside a posting list: every -th entry also holds the id and the place of the entry positions further on. During an intersection, when the list is behind the other list, a skip can move it past a run of ids that cannot match without reading them one by one. The usual rule of thumb is about pointers, evenly spaced, for a list of length . Skip pointers are not a skip list: a skip list is a randomized dictionary of linked levels that supports search, insertion and deletion in expected time, while skip pointers are one fixed level of shortcuts, placed when the index is built, on a list that is usually compressed and read forward only. Their main use is on lists coded with gaps, where an entry cannot be reached by its index and a skip lets the reader jump over the gaps it does not need to decode.
In plain words
Think of a long sorted list as a road with a sign every few steps. Each sign tells you which number is at the next sign and where it is.
When you compare two lists and the one you walk on is behind, look at the sign. If the number at the next sign is still not past the number you look for, nothing between here and that sign can match, so you go straight to the sign. If it is past, you walk the short way, one entry at a time.
Signs that are close together let you stop near the place you want, but you must read many signs. Signs far apart are cheap to keep, but each jump lands farther from the target, and you walk more. A common choice spaces the signs by about the square root of the list length.
When it applies
- The query is an AND of terms, so the answer is a posting list intersection. For an OR query the result holds every entry of every list, so there is nothing to skip.
- One list is much longer than the other, so most entries of the long list cannot match.
- The list can be read only forward, as with variable byte codes or other codes of gaps. If the list is a plain array, a galloping search does the same job with no extra space.
- The index does not change often. Skips are placed when the list is built, and an insertion in the middle moves the places that they point to.
The template
The merge of two sorted lists, with a skip test before each single step. The holes to fill are in capitals.
INTERSECT-WITH-SKIPS(A, B) ▷ A and B strictly increasing- 1
i ← 0, j ← 0, R ← () - 2
while i < |A| and j < |B| do - 3
if A[i] = B[j] then append A[i] to R, i ← i + 1, j ← j + 1 - 4
else if A[i] < B[j] then - 5
if HAS-SKIP(A, i) and A[SKIP(A, i)] ≤ B[j] then - 6
while HAS-SKIP(A, i) and A[SKIP(A, i)] ≤ B[j] do i ← SKIP(A, i) - 7
else i ← i + 1 - 8
else the same as lines L5 to L7, with A, i and B, j swapped - 9
return R
The holes. PLACE-SKIPS, at build time, chooses the entries that hold a skip and the spacing . HAS-SKIP tells if entry holds one, and SKIP gives its target. In a compressed list, the skip stores the id at the target and the byte offset where the decoder must restart, so the test of line L5 reads only the skip and not the entries between.
The invariant to prove. Before each test of line L2, every common id that is not in is in and in . A jump of line L6 from to keeps it, because the ids are less than , and every id left in is at least , so none of them is common. The test must be : a jump to an id greater than can pass over itself. Lines L3 and L7 are the steps of the merge, with the same proof.
The cost. Let have length with a skip at every -th entry, pointing entries on, and let have length . The jumps of line L6 move forward by each, so there are at most of them. While stays the same, makes at most single steps to reach an entry with a skip, and after a skip test fails, at most more, because the target of that skip is already past . So makes at most moves, against up to for the merge. With near , this is . The rule of about evenly spaced pointers does not depend on the query, which is not known when the index is built.
A worked example. Let , the 16 even numbers from 2 to 32, with skips of length at the indices 0, 4 and 8, so that they point to , and . Intersect it with , which has no skips.
| state | test | move |
|---|---|---|
| , | is behind; the skip target | single step, |
| , then | no skips at indices 1 and 2 | single steps, |
| output 8, , | ||
| , | , then | two jumps, |
| , then | no skips at indices 12 and 13 | single steps, |
| output 30, , stop |
The result is . The scan reads 9 entries of (the indices 0 to 4, 8 and 12 to 14), where the merge reads 15. The skip at index 0 shows the pitfall of the test: a jump to with the target 8 would pass over the match.
On the toy collection the lists are too short to need skips: the longest one, for the word "a", has 5 entries.
Classic examples
- Merge-based list intersection with skips is the template above. Manning, Raghavan and Schuetze give it for two posting lists.
- Positional intersection. The document level of a positional list is a posting list, so skips move it to the next common document before any position is read.
- Document-at-a-time evaluation. Each term has a cursor with a forward seek to the first id at least ; skips make that seek cheap on compressed lists.
- WAND and block-max WAND. These ranked methods move a cursor to a pivot id that may be far ahead, and use skips or a block index to get there. Block-max WAND also keeps the largest score of each block next to the skip data.
- Small-versus-small intersection on compressed lists seeks in the long list with a block index, the array form of skips.
Variations
- A block index. Keep the first id of each block of compressed entries in a separate small array, and find the block of a target with a binary or galloping search on that array. This is the usual layout for block codes such as PForDelta.
- More than one level. Skips at the spacings , , , and so on give seeks in steps. This is close to a deterministic skip list stored in a static array.
- Spacing for the query. If the lengths of the lists in typical queries are known, the cost suggests a spacing near in place of .
- Codes with built-in skips. Elias-Fano encoding stores the high bits of the ids in a unary bit array, and a select structure on that array jumps to any part of the list with no extra pointers.
- Skips in position lists. A long list of positions in one document can carry its own skips, for proximity queries on long documents.
Pitfalls
- A jump past the target. The skip test must check that the target id is at most the current id of the other list. In the example, a jump from to when the other id is 8 loses the match 8, with no error.
- The wrong spacing. Many short skips cost space and many failed tests; a few long skips are rarely taken. Moffat and Zobel report an index growth of under 20 percent with their skips, so the space is not free.
- Updates. Skips that point a fixed number of entries ahead must be rebuilt when an id is inserted in the middle of a list. They suit a static index; a list that changes often needs a different layout, see dynamic index maintenance.
- Skips where they cannot help. Skips do not speed up a union, and they do not help when the two lists have about the same length and interleave finely, because then almost every skip test fails.
- The hardware. The gain comes from not decoding the entries that are skipped. When the lists are in memory and decoding is fast, the extra tests can cost about as much as they save; measure before tuning.
References
- Christopher D. Manning, Prabhakar Raghavan and Hinrich Schuetze, Introduction to Information Retrieval, Cambridge University Press, 2008, Chapter 2, Section 2.3 (faster postings list intersection via skip pointers, the algorithm with skips, the placement of about sqrt(P) evenly spaced pointers, and the remark on static and updated indexes)
- Alistair Moffat and Justin Zobel, Self-indexing inverted files for fast text retrieval, ACM Transactions on Information Systems 14(4), 1996, 349-379, the skips in compressed inverted lists, their cost in index size (under 20 percent) and the gain for Boolean queries of 5 to 10 terms (under one fifth of the time)
- Justin Zobel and Alistair Moffat, Inverted files for text search engines, ACM Computing Surveys 38(2), Article 6, 2006, the sections on query evaluation with compressed lists and skipping
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag 3KK71T Edit this page History Report an error Markdown