Integrated FullText Search i FTS in Microsoft SQL


































- Slides: 34

Integrated Full-Text Search (i. FTS) in Microsoft SQL Server ® 2008 Fernando Azpeitia Lopez SQL Server Engine - Program Manager Microsoft ® Corporation

Session Objectives And Takeaways “What is exactly full-text search in a DB? Which are its main scenarios and how can it provide value to my solution? ” • Cover the main concepts and capabilities of our full-text search solution inside SQL Server. • Realize how i. FTS (SQL Server 2008 integrated FTS) can extract significant value out of unstructured and semi-structured data stored inside the DB. • Demonstrate the usage of i. FTS and how it solves your daily DB Search needs. • Cover i. FTS’ best practices and workarounds. • Evangelize SQL Server FTS and prove it ready for high level production environments • Understanding the future of Search in DBs. Where are we going and why?

Session Details • Searching at Microsoft: Main Players • SQL Server Full-Text Search (FTS) : Overview of Basic Scenarios, Concepts, Features & Architecture (Demo) - The need The Scenario The Solution How do I deploy it? How do I use it? • SQL Server 2008 i. FTS (Integrated FTS) - Why did we need a new Search infrastructure? - SQL FTS Roadmap - The new Architecture - Main Improvements (Demo) - Upgrading to i. FTS - Best Practices and Workarounds - What is not in i. FTS? - Upcoming Future • Q&A 3

Searching at Microsoft: Main Players Ø Bing • • • Search WWW Highly scalable Does not use FTS as provided by SQL Server Ø MS Search • • • Search information on disk Integrated with OS (e. g: Vista Desktop Search) Used by former Share. Point, SQL Server 2000 and 2005 and Desktop Search … Ø FAST • • Search information on your organization (Enterprise Search) Share. Point Server search solution Ø i. FTS in SQL Server 2008 • Provides Full Text Search over data in RDBMS • Completely redesigned search solution to leverage DB robustness and scalability.

Full-Text Search (FTS) in SQL Server: Overview “The Need” “How can I extract value out of vast amounts of non-relational data stored in the DB, by leveraging fast filtering mechanisms to get to the information I need? ”

Full-Text Search (FTS) in SQL Server: Overview “The Scenario” 1. Heterogeneous data (different types and languages) stored and managed in the DB. Mainly unstructured and semi-structured data (e. g: binary documents, emails, XML, HTML, etc. . ) 2. Besides leverage DB capabilities, the ability to Search efficiently over this data arises. 1. The creation of special (non-relational) indexes is needed in order to enable Search over these corpuses. 2. Users need to manage the data and its indexes together and consistently. 3. Main Markets: Compliance/E-Discovery, Government/Law Enforcement, e. Commerce, Customer Support, Vertical Search (Medical, Media, . . Etc…. )

Full-Text Search (FTS) in SQL Server: Overview “The Solution” Ø SQL Server Full-Text Search (FTS) • FTS is a feature integrated into SQL Server that allows fast and flexible querying of significant words and phrases in: • Character-based database columns • Documents stored in an binary typed column; varbinary() and binary(), as well as XML data types • FTS searches for language aware tokens, keywords or phrases inside the database providing scoring and relevance of the result set.

Full-Text Search (FTS) in SQL Server: Overview “How does it work? ” Tokenization Ø • The data is parsed by language aware processes (i. Filters, stemmer, wordbreaker, etc. . ) Indexing Ø • • FTS uses special indexing mechanism: custom FTIndexes stored in FTCatalogs. Each token (word) is indexed keeping metadata related to it. Querying Ø • • Predicates: CONTAINS, FREETEXT Table-valued functions returning relevance base score: CONTAINSTABLE, FREETEXTTABLE • • • Matching semantics: exact or fuzzy Various query options available: i. e : weight, NEAR, Thesaurus, Inflectional, Top_N_by_Rank, prefix, etc. . … Wide language support at indexing and querying time.

Full-Text Search (FTS) in SQL Server: Overview Demo: “How do I deploy it? ” 1. Locate table with textual data (character based or binary raw data). 2. Full-text catalog created in that database. CREATE FULLTEXT CATALOG ft. Catalog AS DEFAULT; 3. Full-text index (associated with the full-text catalog) on the column/s of the table. CREATE FULLTEXT INDEX ON Human. Resources. Job. Candidate(Resume) KEY INDEX PK_Job. Candidate. ID; 4. Population of the index that results in scanning and processing of the textual data. 5. T-SQL Queries that use full-text predicates or table valued constructs. 6. A full set of T-SQL DDL available to perform FTS manageability operations.

Full-Text Search (FTS) in SQL Server: Overview Demo: “How do I use it? ” 1. Populating the FT Index. Keeping up with changes. 2. Querying my data: Understanding CONTAINS and FREETEXT 3. Extending the query to leverage useful features: 1. 2. 3. 4. 5. Thesaurus Prefix search Inflectional Forms Weighted terms TOP_N Etc…


Why a new Search Infrastructure? Ø Possible challenges you might have encountered when using SQL Server 2005 Full-Text Search (FTS) Ø Indexes stored outside SQL Server might lead to manageability challenges Ø E. g: Backup/Restoring your DB with FTCatalogs might require specific actions Ø The Mixed query performance suffers from having to pull over the complete full-text result set Ø E. g: Poor performance when relational side very selective Ø Possible Scaling issues on big boxes Ø Many sustained engineering challenges due lack of technology ownership. Ø E. g: Inability to efficiently support our customers Inability to deliver top features highly requested. Ø Inability to shape our own roadmap targeting our direct customer needs.

Why a new Search Infrastructure? Ø Provide foundation to address future needs Ø Extend the FTS feature set Ø customizable proximity operator Ø property level search Ø snippets with hit-highlighting Ø field weighted relevance Ø customizable tokenizing Ø etc…. . Ø Compelling search platform for others to build on Ø Eventually, offer Search within all data inside the database.

Search: SQL Server Full-Text Search Roadmap Ø FTIndexes into the database Seamless administration, manageability and high availability experience for search indexes Ø Integration with Query Processor Efficient and scalable query processing over search to query continuum Ø Enabling search in semi-structured and unstructured DB storage solutions (e. g: Filestream, Sparse Columns, XML, etc. . ) Ø Feature set comparable to what they see in web and desktop search space Snippets, field scoped search, weighted relevance, customizable NEAR, etc… Ø Massive Scale-up and performance enhancements. Becomes the fast DB search engine in the market. Ø Facilitate Scale-out and manageability enhancements. e. g: Remote indexing, etc. . Ø Enabling finding of ad-hoc information inside the DB without prior knowledge of its schema.

FTS 2008 New Architecture SQL Server process Doc_table id doc_type document SQL Query Procesor SQL Query Execution SQL Query compilation MSFTESQL FTS Engine (FT Search Engine) FTS Query Execution FTS Query compilation Crawl Gatherer Data to be Indexed STOPLIST Full-Text Indexer Keyword and occurrence information Shared Memory Filter Daemon Host (FDHost) Protocol Hander DB Data i. Filters Filtered Text Wordbreaker s Shared Memory

FTS 2008 New Architecture Query SQL Server process SQL Query Procesor SQL Query compilation SQL Query Execution Thesaurus MSFTESQL FTS Engine (FT Search Engine) FTS Query compilation STOPLIST FTS Query Execution Full-Text Index W or db re ak ing of qu er yt er m s Filter Daemon Host (FDHost) Wordbreaker s

Main Improvements Ø Full-Text Indexes are stored and maintained inside SQL Server. Full integration with other unstructured and semi-structured solutions. Ø Manageability features like Backup/Restore, Attach/Detach, Mirroring and Log shipping work for FT indexes just as any other DB objects or regular indexes. Ø Indexing and specific cases of query performance have been improved dramatically Ø (Demo) Access to Full-Text Indexes raw Data. Provides access to search corpus and statistical information. Useful for troubleshooting scenarios. sys. dm_fts_index_keywords() sys. dm_fts_index_keywords_by_document() Keyword Display_term Col_id Doc_id Occ_count

Main Improvements Ø (Demo) Query Input Parser : sys. dm_fts_parser Ø Better supportability: understanding a given WB behavior. SELECT * FROM sys. dm_fts_parser('"This is test“ AND “This also"', 1033, 0, 0) Group_id keyword occurrence Special_term Display_ term Expansion_ty pe Source_term 1 0 x 00740068006 90073 1 Noise Word This 0 This is test 1 0 x 00690073 2 Noise Word is 0 This is test 1 0 x 00740065007 30074 3 Exact Match test 0 This is test 2 0 x 00740068006 90073 1 Noise Word this 0 This also 2 0 x 0061006 C 007 3006 F 2 Noise Word also 0 This also

Main Improvements Ø Full-Text Query is integrated with SQL Query Processor Ø Mixed query performance has been improved for significantly different cardinality scenarios Ø Overall Query performance scales better in most scenarios Ø Resource utilization is managed (mostly) as part of SQL Server

Main Improvements Ø Thesaurus improvements Ø Stored in internal tables (in tempdb) in XML form instead of being parsed from external files Ø Instance level thesaurus sys. sp_fulltext_load_thesaurus_file (lcid) Loads all the data specified in the Thesaurus XML corresponding to the language with specified lcid.

Main Improvements Ø (Demo) New STOPLIST support: Simplified noise words utilization and manageability. DB object associated with the FT index. CREATE FULLTEXT STOPLIST stoplist_name [ FROM {[database_name. ] source_stoplist_name} | SYSTEM STOPLIST] [AUTHORIZATION owner_name] ALTER FULLTEXT STOPLIST stoplist_name { | ADD <keyword> LANGUAGE language_term | DROP { | <keyword> LANGUAGE language_term | ALL }

Main Improvements Ø New family of Word-Breakers (WB): Ø WBs are components responsible of parse the textual data in a given language and pass the tokenized result to the Full-Text Index. Ø 51 languages/WBs out of the box Ø Improved quality and supportability in most word- breakers

Main Improvements Ø WBs available in SQL Server 2008: Arabic German Bengali Gujarati Brazilian Hebrew Bulgarian Hindi Canadian Icelandic Catalan Indonesian Chinese (Simplified) Italian Chinese (Traditional) Japanese Chinese (Hong Kong)Korean Chinese (Macau) Latvian Chinese (Singapore) Lithuanian Croatian Malay Cyrillic Malayalam Danish Marathi Dutch Neutral English Norwegian English UK Polish French Portuguese Punjabi Romanian Russian Serbian Latin Slovak Slovenian Spanish Swedish Tamil Telugu Thai Turkish Ukrainian Urdu Vietnamese Languages present but disabled by default New languages supported in SQL Server 2008 Existing in SQL Server 2005, and being replaced by new WBs in SQL Server 2008 Unchanged language/WB from SQL Server 2005

Main Improvements Ø The indexing performance has improved in most scenarios 2005 Crawl 2005 Total IFTS Crawl IFTS Total 20 M rows 1 k text data 02: 06 02: 25 01: 22 01: 28 5 M rows 8 k text data 02: 10 02: 41 02: 22 02: 32 20 M rows 1 k nvarchar data 01: 37 01: 55 01: 20 01: 26 Measured on 4 processor AMD 64 2793 MHz, 8 G RAM. Numbers are in HH: MM format. Total time is combining time to crawl and time of merge into index For some HW configuration and data types, specific best practices are recommended to improve indexing performance (i. e: capping SQL Server’s memory, etc…)

Upgrading to i. FTS Ø Due a new Full-Text Index architecture, former Full-Text Indexes are not compatible in SQL Server 2008 anymore. Solution…: The Full-Text Catalog Upgrade Option Ø Import: (default) Faster method although performance and semantic implications are possible. Ø Rebuild: Slower method although ideal final state of new FTCatalogs guaranteed. Ø Reset : Faster Upgrade method although your Search app will not have the FTCatalogs available afterwards. You need to rebuild them when possible. Ø Possible Upgrade methods: Ø In place Upgrade: User will be prompted for what Upgrade Option to choose for existing FTCatalogs. Ø Restore/Attach : Instance level setting will be applied to former Full-Text Catalogs brought up with the former DB.

Best Practices and Workarounds Ø Full-Text key type: Use Integer. . When so, no internal mapping table required we avoid an extra internal JOIN at query time. Ø To limit results and increase performance, use the top_n_by_rank option with FREETEXTTABLE and CONTAINSTABLE. Ø Use CONTAINSTABLE or FREETEXTTABLE when you only require Full-Text Key or rank information. Ø Keep your FTIndexes de-fragmentated when possible Reorganize the Full-Text catalog by using ALTER FULLTEXT CATALOG REORGANIZE.

Best Practices and Workarounds Ø Prefix queries Issues? The issue Possible Query perf degradation with non-deterministic enough prefix queries (i. e: ‘a*’). Recommended best practice/s -Try to narrow down your search when possible. - If the query plan has a nested loop with the fulltext STVF, you should try hinting a merge join.

Best Practices and Workarounds Issues with Complex queries? A. Several ANDs + ORs within a single CONTAINS() The issue Ø QO plan and compilation complexity might cause blocking Ø Multiple FT logical operators adds extra cost when relational predicate is pushed into the FTIndex Ø When kept as relational, the QO chosen plan might be not ideal, causing costly executions. Recommended best practice Ø Implement app. level max # of terms. Ø Leverage Thesaurus capabilities when possible. B. Several CONTAINS linked by ORs conditions The issue Ø QO plan and compilation complexity might cause blocking Recommended best practice Ø Combine multiple CONTAINS predicates into one CONTAINS predicate

Best Practices and Workarounds Ø Blocking issues due high DML + FT query workloads The issue Ø …High DML workload (+100 DMLs/sec) + Ø …Plus AUTO being specified as the change tracking mechanism for the Full-text index …. might cause the query load to suffer blocking. Recommended best practice/s Ø A Trace Flag exist to solve this issue (7646) Ø There are documented best practices in the SQL Server 2008 White Paper to mitigate this issue. (e. g: manual change tracking, REORGANIZE, etc. . ) Ø Install latest PCU for latest fixes in this area.

Best Practices and Workarounds Ø Best resources for additional information: • SQL Server 2008 BOL • SQL Server 2008 i. FTS Internals and Enhcancements (White • Fernando Azpeitia Lopez : fernlope@microsoft. com Paper): http: //msdn. microsoft. com/en-us/library/cc 721269. aspx Program Manager. SQL Server Full-Text Search.

What is not yet in IFTS? Ø No document property level search (i. e: search ‘foo’ on doc. ’title’) Ø Some of the customer wish list items: Snippets, column weights, language detection, customizable wordbreakers and proximity operators, etc. . Ø Non support for remote FTIndexing. Currently, i. FTS can only index da stored directly in the DB or in the file system using Filestream integration. Ø No partitioned full-text indexes. No support for SWITCH partition on tables that are FT indexed. Ø Non support for remote FTIndexing. Currently, i. FTS can only index da stored directly in the DB or in the file system using Filestream integration.

Upcoming Future Ø What are we working on for our next major release/s? Ø Improve dramatically our overall query performance by reengineering key components in our architecture. Ø i. e: Early estimations point we will become the fastest DB Engine in the market. Ø Address as many developer features as time permits (e. g: customizable NEAR, property search, etc. . ) Ø Improve our overall scale story to support large corpuses under an impressive query performance.

Summary Ø i. FTS adds significant value ØImplementation -> straightforward ØManagement -> straightforward ØImproved overall Performance, Integration and Robustness i. FTS 2008 is the beginning of an ambitious upcoming plan to become the fastest and easier to use DB Search solution in the world. Ø

Thank you