FULL text search

  • Do we get any benefit if we choose to use full text search over like operator.

    see the below queries with the stats

    select top 10000 * from [Person].[Person_BK] where

    contains([Name], 'fsfsfs')

    select top 10000 * from [Person].[Person_BK] where

    [Name] like '%fsfsfs%'

    Stats

    (10000 row(s) affected)

    Table 'Person_BK'. Scan count 0, logical reads 30634, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

    (1 row(s) affected)

    (10000 row(s) affected)

    Table 'Person_BK'. Scan count 1, logical reads 13464, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

    (1 row(s) affected)

    table defintion

    CREATE TABLE [Person].[Person_BK](

    [BusinessEntityID] [int] identity NOT NULL,

    [PersonType] [nchar](2) NOT NULL,

    [NameStyle] [dbo].[NameStyle] NOT NULL,

    [Title] [nvarchar](8) NULL,

    [Name] [nvarchar](max) NULL,

    [Suffix] [nvarchar](10) NULL,

    [EmailPromotion] [int] NOT NULL,

    [AdditionalContactInfo] [xml] NULL,

    [Demographics] [xml] NULL,

    [rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,

    [ModifiedDate] [datetime] NOT NULL,

    CONSTRAINT [PK_Person_BusinessEntityID_bk] PRIMARY KEY CLUSTERED

    (

    [BusinessEntityID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    CREATE FULLTEXT CATALOG catalog_fulltext_test

    WITH ACCENT_SENSITIVITY = OFF

    CREATE FULLTEXT INDEX ON [Person].[Person_BK] (Name LANGUAGE 1033)

    KEY INDEX PK_Person_BusinessEntityID_bk ON catalog_fulltext_test

    WITH STOPLIST = SYSTEM

    i am not sure how we get benefits from full text from performance perspective ? please guide.

    NOte : Everything is on same DISK (index + table + fulltext index )

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Well the second one will use a scan as its not SARG-able due to it being '%...%'

    What is the output with statistics time switched on and also what do the executions plans show.

  • anthony.green (12/12/2012)


    What is the output with statistics time switched on and also what do the executions plans show.

    SQL Server parse and compile time:

    CPU time = 16 ms, elapsed time = 30 ms.

    SQL Server Execution Times:

    CPU time = 0 ms, elapsed time = 0 ms.

    SQL Server Execution Times:

    CPU time = 0 ms, elapsed time = 0 ms.

    full text

    SQL Server Execution Times:

    CPU time = 0 ms, elapsed time = 0 ms.

    Table 'Person_BK'. Scan count 0, logical reads 30634, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

    SQL Server Execution Times:

    CPU time = 500 ms, elapsed time = 1516 ms.

    nomral

    SQL Server Execution Times:

    CPU time = 0 ms, elapsed time = 0 ms.

    Table 'Person_BK'. Scan count 1, logical reads 16216, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

    SQL Server Execution Times:

    CPU time = 1094 ms, elapsed time = 2648 ms.

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Well the full text is faster on time, yes it reads more pages from memory than the like, but doesnt do a scan which the like does, so full text wins on that one for me. Also Full text is less cost than the like so again, that shows it is better.

  • anthony.green (12/12/2012)


    but doesnt do a scan which the like does, so full text wins on that one for me.

    well i think its because there is full text index on name column

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Thats the whole point.

    %...% will cause a table scan no matter what indexes you have on it

    FTS will do the seek and then a match on the FTI

  • anthony.green (12/12/2012)


    Thats the whole point.

    %...% will cause a table scan no matter what indexes you have on it

    FTS will do the seek and then a match on the FTI

    ok so you mean here that we are good with the stats , full text gives us edge ok thanks , have you seen the exec plan too ( attached in my third last post .. capture.png) .

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • yes I saw the execution plan, should upload them as SQLPLAN files as we can then open then in SSMS and naviagte the objects and see the stats, but as they are pretty simple, you can see that full text is the better plan

  • anthony.green (12/12/2012)


    yes I saw the execution plan, should upload them as SQLPLAN files as we can then open then in SSMS and naviagte the objects and see the stats, but as they are pretty simple, you can see that full text is the better plan

    i always do and prefer but today i am using VDI so cant be able to thats y i took the screenshot 🙂

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • during my testing or learning on Full text search , i found below queries are returning different results .can you please guide me why

    select [BusinessEntityID] , [Name] from [Person].[Person_BK]

    where contains([Name], ‘*ASDGDE*’) or contains([Name], ‘*AFASFA*’)

    select [BusinessEntityID] , [Name] from [Person].[Person_BK]

    where [Name] like ‘%ASDGDE%’ or [Name] like ‘%AFASFA%’

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Bhuvnesh (12/13/2012)


    during my testing or learning on Full text search , i found below queries are returning different results .can you please guide me why

    select [BusinessEntityID] , [Name] from [Person].[Person_BK]

    where contains([Name], ‘*ASDGDE*’) or contains([Name], ‘*AFASFA*’)

    select [BusinessEntityID] , [Name] from [Person].[Person_BK]

    where [Name] like ‘%ASDGDE%’ or [Name] like ‘%AFASFA%’

    If your using wildcards, you need to wrap it up into " so it would be '"*ASDGDE*"'. so single quote ' then speach marks ", then search string, speach marks, single quote

    Although if I remember correctly FTS doesnt do preceding wildcards, so the first * might be ignored.

  • i got the correct query

    select * from [Person].[Person_BK] where

    contains([Name], '*ASDGDE* OR *AFASFA*')

    it had happened as i had missed the mandate homework 😀

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • 1 - How does stop lists improve fulltext query performance in SQL Server 2008 (or it does not)? Is it a good idea to have stop lists assign to all catalogs?

    2 - When a catalog uses stop lists, how can a query like this one work? SQL Server is searching for the stop word "of" and it finds all results correctly.

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • As anthony thought Full Text Search doesnt handle Leading wildcards, only trailing wild cards which may explain the differences in the results being returned (Unless this has changed in SQL 2012)

    I think its a corporate/personal decision, in regards to the stop list being mandatory, and I would think that most corporates would expect words that would be stopped by an Email profanity check to be weeded out.

    I dont know the impact it would have on performance, as I'm just getting into using Full Text Search for a bit of R&D.

    _________________________________________________________________________
    SSC Guide to Posting and Best Practices

  • Is "SEARCH PROPERTY LIST " feature available before sql 2012 ? and can it be used in sql table too ?

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

Viewing 15 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic. Login to reply