CS194-3/CS16x Introduction to Systems Lecture 26 Elementary Information Retrieval: Scalable Boolean Text Search December 3, 2007 Prof. Anthony D. Joseph.

Slides:



Advertisements
Similar presentations
CPSC 404 Laks V.S. Lakshmanan1 Introduction to IR Systems: Supporting Boolean Text Search Ramakrishnan & Gehrke: Chapter 27, Sections 27.1—27.2.
Advertisements

Database Management Systems, R. Ramakrishnan and J. Gehrke1 Evaluation of Relational Operations Chapter 12, Part A.
Implementation of relational operations
Introduction to Information Retrieval
Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 14, Part B.
Implementation of Other Relational Algebra Operators, R. Ramakrishnan and J. Gehrke1 Implementation of other Relational Algebra Operators Chapter 12.
Database Management Systems, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
Database Management Systems, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
Query Evaluation. An SQL query and its RA equiv. Employees (sin INT, ename VARCHAR(20), rating INT, age REAL) Maintenances (sin INT, planeId INT, day.
Query Evaluation. SQL to ERA SQL queries are translated into extended relational algebra. Query evaluation plans are represented as trees of relational.
1 Relational Query Optimization Module 5, Lecture 2.
Information Retrieval in Practice
I NTRODUCTION TO IR S YSTEMS : S EARCH E NGINES Chapter 27.
Elementary IR Systems: Supporting Boolean Text Search.
Introduction to IR Systems: Supporting Boolean Text Search
Midterm Review Spring Overview Sorting Hashing Selections Joins.
1 Implementation of Relational Operations Module 5, Lecture 1.
Evaluation of Relational Operators 198:541. Relational Operations  We will consider how to implement: Selection ( ) Selects a subset of rows from relation.
1  Simple Nested Loops Join:  Block Nested Loops Join  Index Nested Loops Join  Sort Merge Join  Hash Join  Hybrid Hash Join Evaluation of Relational.
SPRING 2004CENG 3521 Join Algorithms Chapter 14. SPRING 2004CENG 3522 Schema for Examples Similar to old schema; rname added for variations. Reserves:
Elementary IR Systems: Supporting Boolean Text Search.
1 Optimization Recap and examples. 2 Optimization introduction For every SQL expression, there are many possible ways of implementation. The different.
Database Management Systems, R. Ramakrishnan1 Introduction to IR Systems: Supporting Boolean Text Search Chapter 27, Part A.
Elementary IR: Scalable Boolean Text Search (Compare with R & G )
Query Optimization 3 Cost Estimation R&G, Chapters 12, 13, 14 Lecture 15.
Implementation of Relational Operations R&G - Chapters 12 and 14.
1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Query Optimization Chapter 15.
Evaluation of Relational Operations. Relational Operations v We will consider how to implement: – Selection ( ) Selects a subset of rows from relation.
Overview of Search Engines
1 Implementation of Relational Operations: Joins.
Query Optimization, part 2 CS634 Lecture 13, Mar Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Query Evaluation Chapter 12: Overview.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
CSE 6331 © Leonidas Fegaras Information Retrieval 1 Information Retrieval and Web Search Engines Leonidas Fegaras.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
CPSC 404, Laks V.S. Lakshmanan1 Evaluation of Relational Operations: Other Operations Chapter 14 Ramakrishnan & Gehrke (Sections ; )
Relational Operator Evaluation. Overview Index Nested Loops Join If there is an index on the join column of one relation (say S), can make it the inner.
Implementing Natural Joins, R. Ramakrishnan and J. Gehrke with corrections by Christoph F. Eick 1 Implementing Natural Joins.
Introduction to Query Optimization, R. Ramakrishnan and J. Gehrke 1 Introduction to Query Optimization Chapter 13.
CS4432: Database Systems II Query Processing- Part 2.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Introduction to Query Optimization Chapter 13.
Relational Operator Evaluation. Overview Application Programmer (e.g., business analyst, Data architect) Sophisticated Application Programmer (e.g.,
CPSC 404, Laks V.S. Lakshmanan1 Overview of Query Evaluation Chapter 12 Ramakrishnan & Gehrke (Sections )
CPSC 404, Laks V.S. Lakshmanan1 Evaluation of Relational Operations – Join Chapter 14 Ramakrishnan and Gehrke (Section 14.4)
Query Processing CS 405G Introduction to Database Systems.
Query Execution. Where are we? File organizations: sorted, hashed, heaps. Indexes: hash index, B+-tree Indexes can be clustered or not. Data can be stored.
Relational Operator Evaluation. overview Projection Two steps –Remove unwanted attributes –Eliminate any duplicate tuples The expensive part is removing.
Implementation of Database Systems, Jarek Gryz1 Evaluation of Relational Operations Chapter 12, Part A.
Query Execution Query compiler Execution engine Index/record mgr. Buffer manager Storage manager storage User/ Application Query update Query execution.
Alon Levy 1 Relational Operations v We will consider how to implement: – Selection ( ) Selects a subset of rows from relation. – Projection ( ) Deletes.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Evaluation of Relational Operations Chapter 14, Part A (Joins)
1 Overview of Query Evaluation Chapter Outline  Query Optimization Overview  Algorithm for Relational Operations.
1 Introduction to IR Systems: Supporting Boolean Text Search.
Implementation of Relational Operations Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein, Mike Franklin, and etc for.
Introduction to Query Optimization
Relational Algebra Chapter 4, Part A
Evaluation of Relational Operations
Elementary IR: Scalable Boolean Text Search
Evaluation of Relational Operations: Other Operations
Examples of Physical Query Plan Alternatives
Relational Operations
Implementation of Relational Operations
Implementation of Relational Operations
Relational Query Optimization
CS222P: Principles of Data Management Notes #13 Set operations, Aggregation, Query Plans Instructor: Chen Li.
Evaluation of Relational Operations: Other Techniques
Implementation of Relational Operations
Evaluation of Relational Operations: Other Techniques
Presentation transcript:

CS194-3/CS16x Introduction to Systems Lecture 26 Elementary Information Retrieval: Scalable Boolean Text Search December 3, 2007 Prof. Anthony D. Joseph

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Goals for Today Join techniques –Nested-loops join –Sort-merge join Boolean text search –You’ve already seen a parallel version of this in Project 2 (from the systems view) Note: Some slides and/or pictures in the following are adapted from slides ©2005 Silberschatz, Galvin, and Gagne. Slides courtesy of Kubiatowicz, AJ Shankar, George Necula, Alex Aiken, Eric Brewer, Ras Bodik, Ion Stoica, Doug Tygar, and David Wagner.

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Schema for Examples Sailors: –Each tuple is 50 bytes long, 80 tuples per page, 500 pages. –|S|=500, p S =80. Reserves: –Each tuple is 40 bytes, 100 tuples per page, 1000 pages. –|R|=1000, p R =100. Sailors (sid: integer, sname: string, rating: integer, age: real) Reserves (sid: integer, bid: integer, day: dates, rname: string)

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Joins Joins are very common R  S is large; so, R  S followed by a selection is inefficient Many approaches to reduce join cost Join techniques we will cover today: 1.Nested-loops join 2.Sort-merge join SELECT * FROM Reserves R1, Sailors S1 WHERE R1.sid=S1.sid

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 foreach tuple r in R do foreach tuple s in S do if r i == s j then add to result Simple Nested Loops Join Cost = (p R *|R|)*(p S *|S|)+|R| = 100*1000*80* IOs –At 10ms/IO, Total time: ??? What if smaller relation (S) was “outer”? –Cost = (p S *|S|)*|R| + |S| = 80*500* IOs What assumptions are being made here? What is cost if one relation can fit entirely in memory? R S:

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Page-Oriented Nested Loops Join Cost = |R|*|S| + |R| = 1000* If smaller relation (S) is outer, cost = 500* Much better than naïve per-tuple approach! foreach page b R in R do foreach page b S in S do foreach tuple r in b R do foreach tuple s in b S do if r i == s j then add to result R S:

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Sort-Merge Join Example: SELECT * FROM Reserves R1, Sailors S1 WHERE R1.sid=S1.sid 1.Sort R on join attr(s) 2.Sort S on join attr(s) 3.Scan sorted-R and sorted-S in tandem, to find matches

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Cost of Sort-Merge Join Cost: Sort R + Sort S + (|R|+|S|) –But in worst case, last term could be |R|*|S| (very unlikely!) –Q: what is worst case? Suppose B = 35 buffer pages: Both R and S can be sorted in 2 passes Total join cost = 4* *500 + ( ) = 7500 Suppose B = 300 buffer pages: Again, both R and S sorted in 2 passes Total join cost = 7500

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Other Considerations … 1. An important refinement: Do the join during the final merging pass of sort ! If have enough memory, can do: 1. Read R and write out sorted runs 2. Read S and write out sorted runs 3. Merge R-runs and S-runs, and find R S matches Cost = 3*|R| + 3*|S|  2. Sort-merge join an especially good choice if: – One or both inputs are already sorted on join attribute(s) – Output is required to be sorted on join attributes(s) Q: how to take these savings into account? (stay tuned …)

BREAK

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 A research field traditionally separate from Databases –Hans P. Luhn, IBM, 1959: “Keyword in Context (KWIC)” –G. Salton at Cornell in the 60’s/70’s: SMART »Around the same time as relational DB revolution –Tons of research since then »Especially in the web era Products traditionally separate –Originally, document management systems for libraries, government, law, etc. –Gained prominence in recent years due to web search »Still used for non-web document management – “Enterprise search” and “Desktop search” Information Retrieval: History

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Boolean Search on keywords Goal: –See how IR relates to the tools we use in relational DBs We’ll skip: –Text-oriented storage formats –Intelligent result ranking –Parallelism (you’ve seen this already in Project 2) »Critical for modern relational DBs too –Various bells and whistles (lots of little ones!) »Engineering the specifics of (written) human language E.g., dealing with tense and plurals E.g., identifying synonyms and related words E.g., disambiguating multiple meanings of a word E.g., clustering output Today: Simple (naïve!) IR

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Information Retrieval vs. DBMS Seem like very different beasts Under the hood, not as different as they might seem –But in practice, you have to choose between the two today Information RetrievalDBMS Imprecise SemanticsPrecise Semantics Keyword searchSQL Unstructured data formatStructured data Read-Mostly. Add docs occasionally Expect reasonable number of updates Page through top k resultsGenerate full answer

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Typical IR data model: –Each document is just a bag of words (“terms”) Detail 1: “Stop Words” –Certain words are not helpful, so not placed in the bag –e.g., real words like “the” –e.g., HTML tags like Detail 2: “Stemming” –Using language-specific rules, convert words to basic form –e.g., “surfing”, “surfed” –> “surf” –Unfortunately have to do this for each language »Yuck! IR’s “Bag of Words” Model

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Boolean Text Search Find all documents that match a Boolean containment expression: –“Windows” AND (“Glass” OR “Door”) AND NOT “Microsoft” Note: query terms may also be filtered via stemming and stop words When web search engines say “10,000 documents found”, that’s the Boolean search result size –More or less ;-)

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Text “Indexes” When IR folks say “text index”… –Usually mean more than what DB people mean In DB terms, both “tables” and indexes –Really a logical schema (i.e., tables) –With a physical schema (i.e., indexes) –Usually not stored in a DBMS »Tables implemented as files in a file system »We’ll talk more about this decision soon

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 A Simple Relational Text Index (non-Parallel Project 2) Given: a corpus of text files Files(docID string, content string) Create and populate a table InvertedFile(term string, docID string) Build a B+-tree or Hash index on InvertedFile.term –Keep lists of dup keys sorted by docID »Will provide “interesting orders” later on! –Fancy list compression important, too –Typically called a postings list by IR people Often called an “inverted file” or “inverted index” –Maps words -> docs, rather than docs -> words Given this, you can now do single-word text search queries!

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 An Inverted File Snippets from: –Old CS186 class web page –Old microsoft.com home page Search for –databases –microsoft TermdocID

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 IR Buzzwords to Know Learning this in the context of relational foundations is fine, but you need to know the IR lingo! –Corpus: a collection of documents –Term: an isolated string (searchable unit) –Index: a mechanism mapping terms to documents –Inverted File (= Postings File): a file containing terms and associated postings lists –Postings List: a list of pointers (“postings”) to documents

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 How to do “term1” OR “term2”? –Union of two postings lists (docID sets)! How to do “term1” AND “term2”? –Intersection of two postings lists! »Can be done via merge-join over postings lists »Remember: postings list per key sorted by docID in index Handling Boolean Logic

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 How to do “term1” AND NOT “term2”? –Set subtraction »Also easy because sorted (basically merge join logic again) How to do “term1” OR NOT “term2” –Union of “term1” and “NOT term2” »“Not term2” = all docs not containing term2. Yuck! –Usually not allowed! Query Optimization: what order to handle terms if you have many ANDs? Handling Boolean Logic (cont’d)

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Boolean Search in SQL (SELECT docID FROM InvertedFile WHERE word = “window” INTERSECT SELECT docID FROM InvertedFile WHERE word = “glass” OR word = “door”) EXCEPT SELECT docID FROM InvertedFile WHERE word=“Microsoft” ORDER BY magic_rank() There’s only one SQL query template in Boolean Search –Single-table selects, UNION, INTERSECT, EXCEPT magic_rank() is the “secret sauce” in the search engines –Combos of statistics, linguistics, and graph theory (“page rank”) tricks! –Why isn’t this a static function (i.e., why do companies change it)? “Windows” AND (“Glass” OR “Door”) AND NOT “Microsoft ”

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 One Step Fancier: Phrases and “Near” Suppose you want a phrase –E.g. “Happy Days” Different schema: –InvertedFile (term string, position int, docID string) –Use index on term –Postings lists sorted by (docID, position) Post-process the results –Find “Happy” AND “Days” –Keep results where positions are 1 off »Can be done during merge-join to AND the 2 lists! Can do a similar thing for “term1” NEAR “term2” –Position < k off –Think about refinement to merge-join…

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Administrivia Project 3 code due Thursday 12/6 Midterm 3 Exam is Monday 12/10 Optional topics?

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Generating Web Search Results Pages Data structures: –InvertedFile (term string, position int, docID int) –Files(docID int, docID string, snippet string, …) –Btree on InvertedFile.term –Btree on Docs.docID Page generation requires a final join step between typical query result and Files.docID –Can do this lazily: use cursor to generate a web page full of results

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Text search engines are designed to be query-mostly –Deletes and modifications are rare –Can postpone updates (nobody notices, no transactions!) »Can work off a union of indexes »Merge them in batch (typically re-bulk-load a new index) Can’t afford to go offline for an update? –Create a 2nd index on a separate machine –Replace the 1st index with the 2nd! So, no concurrency control problems –Can compress to search-friendly, update-unfriendly format –Can keep postings lists sorted Updates and Text Search

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 What if updates are not rare? –Web search on news/sports, blogs, frequently updated pages? –Challenge is real-time updating of index For all these reasons, text search engines and DBMSs are usually separate products –Also, text-search engines tune that one SQL query to death! –The benefits of a special-case workload Updates and Text Search (cont’d)

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 How to “rank” the output? –A mix of simple tricks works well –Some fancier tricks can help (use hyperlink graph) Other ways to help users paw through the output? –Document “clustering” (e.g. Clusty.com) –Document visualization How to use compression for better I/O performance? –E.g. making postings lists smaller –Try to make things fit in RAM (or in processor caches) How to deal with synonyms, misspelling,abbreviations? How to write a good web crawler? Read the book Managing Gigabytes –By Ian H. Witten, Alistair Moffat, Timothy C. Bell Lots more tricks in IR

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 The Basics of IR “Inverted files” are the workhorses of all text search engines –Just B+-tree or Hash indexes on bag-of-words Intersect, Union and Set Difference (Except) –Usually implemented via sorting –Or can be done with hash or index joins Most of the other stuff is not “systems” work –A lot of it is cleverness in dealing with language –Both linguistics and statistics (more the latter!)

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 Semantic Guarantees on Storage Data Modeling & Query Complexity Performance goals For each one, is the difference reasonable and acceptable? Revisiting Our IR/DBMS Distinctions

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 DBMS guarantees transactional semantics –If an inserting transaction commits, a subsequent query will see the update –Handles multiple concurrent updates correctly IR systems do not do this; nobody notices! –Postpone insertions until convenient –No model of correct concurrency –Can even return incorrect answers for various reasons! Is the difference reasonable and acceptable? Semantic Guarantees on Storage

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 DBMS supports any schema & queries –But requires you to define schema –And SQL is hard to figure out for the average citizen IR supports only one schema & query –No schema design required (unstructured text) –Trivial (natural?) query language for simple tasks –No data correlation or analysis capabilities -- “search” only Is the difference reasonable and acceptable? Data Modeling & Query Complexity

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 DBMS supports general SELECT –plus mix of INSERT, UPDATE, DELETE –general purpose engine must always perform “well” IR systems expect only one stylized SELECT –plus delayed INSERT, unusual DELETE, no UPDATE. –special purpose, must run super-fast on “The Query” –users rarely look at the full answer in Boolean Search »Postpone any work you can to subsequent index joins »But make sure you can rank! Is the difference reasonable and acceptable? Performance Goals

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 IR & Relational systems share basic building blocks for scalability –IR internal representation is relational! –Equality indexes (B-trees) –Iterators –“Join” algorithms, esp. merge-join –“Join” ordering and selectivity estimation IR constrains queries, schema, promises on semantics –Affects storage format, indexing and concurrency control –Affects join algorithms & selectivity estimation Summary

Lec /3/07Joseph CS194-3/16x ©UCB Fall 2007 IR has different performance goals –Ranking and best answers fast Many challenges in IR related to “text engineering” –But don’t tend to change the scalability infrastructure Summary (cont’d)