 |
|
 |
|
Next: Why no source columns in Transform Data task?
|
| Author |
Message |
External

Since: Dec 07, 2007 Posts: 10
|
(Msg. 1) Posted: Thu Feb 07, 2008 10:49 am
Post subject: I need to optimize this query Archived from groups: microsoft>public>sqlserver>fulltext (more info?)
|
|
|
I have a simple music catalog:
CREATE TABLE [dbo].[Catalog](
[CatalogId] [int] IDENTITY(1,1) NOT NULL,
[Artist] [nvarchar](256) NULL,
[Title] [nvarchar](256) NULL,
[Remix] [nvarchar](256) NULL,
[Album] [nvarchar](256) NULL,
[Label] [nvarchar](256) NULL,
[DateAdded] [datetime] NULL CONSTRAINT [DF_Catalog_DateAdded]
DEFAULT (getdate()),
CONSTRAINT [PK_Catalog] PRIMARY KEY CLUSTERED
(
[CatalogId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
The Full Text index is set on Artist and Title. I wrote the following
Query:
CREATE PROCEDURE [dbo].[CatalogSelectBySearch]
(
@Artist nvarchar(256),
@Title nvarchar(256)
)
AS
SET NOCOUNT ON;
DECLARE @SearchTerms nvarchar(512);
SET @SearchTerms = '("' + @Artist + '") OR
("' + @Title + '")'
SELECT C.CatalogId, C.Artist, C.Title, C.Remix,
C.Album, C.Label,
C.DateAdded
FROM dbo.Catalog AS C
INNER JOIN FREETEXTTABLE(dbo.Catalog, (Artist, Title),
@SearchTerms)
AS KEY_TBL
ON C.CatalogId = KEY_TBL.[KEY]
ORDER BY KEY_TBL.RANK DESC;
I have a feeling that this query can be done better but I am fairly
new to Full-text and don't know where to start. I tried using
CONTAINSTABLE but when I did that the search was very restrictive. For
instance, if the artist is "Shawn Christoper" in the database and
someone typed "Sean Christoper" to search, no results would come up
using the query structure above. FREETEXTTABLE returns is but the
query is very loose and returns alot of irrelevant results.
Please let me know how I can optimize this query.
Thanks >> Stay informed about: I need to optimize this query |
|
| Back to top |
|
 |  |
External

Since: Oct 09, 2005 Posts: 78
|
(Msg. 2) Posted: Fri Feb 08, 2008 6:30 am
Post subject: Re: I need to optimize this query [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Does this offer any better performance:
create unique index CatalogID on Catalog(CatalogID,DateAdded)
include(Artist,Title,Remix,Album,Label)
create unique index CatalogID1 on Catalog(CatalogID)
create fulltext index on catalog(Artist,title) key index CatalogID1
On Feb 7, 1:49 pm, Nightcrawler wrote:
> I have a simple music catalog:
>
> CREATE TABLE [dbo].[Catalog](
> [CatalogId] [int] IDENTITY(1,1) NOT NULL,
> [Artist] [nvarchar](256) NULL,
> [Title] [nvarchar](256) NULL,
> [Remix] [nvarchar](256) NULL,
> [Album] [nvarchar](256) NULL,
> [Label] [nvarchar](256) NULL,
> [DateAdded] [datetime] NULL CONSTRAINT [DF_Catalog_DateAdded]
> DEFAULT (getdate()),
> CONSTRAINT [PK_Catalog] PRIMARY KEY CLUSTERED
> (
> [CatalogId] ASC
> )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
> IGNORE_DUP_KEY
> = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
> ) ON [PRIMARY]
>
> The Full Text index is set on Artist and Title. I wrote the following
> Query:
>
> CREATE PROCEDURE [dbo].[CatalogSelectBySearch]
> (
> @Artist nvarchar(256),
> @Title nvarchar(256)
> )
> AS
> SET NOCOUNT ON;
>
> DECLARE @SearchTerms nvarchar(512);
> SET @SearchTerms = '("' + @Artist + '") OR
> ("' + @Title + '")'
>
> SELECT C.CatalogId, C.Artist, C.Title, C.Remix,
> C.Album, C.Label,
> C.DateAdded
> FROM dbo.Catalog AS C
> INNER JOIN FREETEXTTABLE(dbo.Catalog, (Artist, Title),
> @SearchTerms)
> AS KEY_TBL
> ON C.CatalogId = KEY_TBL.[KEY]
> ORDER BY KEY_TBL.RANK DESC;
>
> I have a feeling that this query can be done better but I am fairly
> new to Full-text and don't know where to start. I tried using
> CONTAINSTABLE but when I did that the search was very restrictive. For
> instance, if the artist is "Shawn Christoper" in the database and
> someone typed "Sean Christoper" to search, no results would come up
> using the query structure above. FREETEXTTABLE returns is but the
> query is very loose and returns alot of irrelevant results.
>
> Please let me know how I can optimize this query.
>
> Thanks >> Stay informed about: I need to optimize this query |
|
| Back to top |
|
 |  |
External

Since: Dec 07, 2007 Posts: 10
|
(Msg. 3) Posted: Fri Feb 08, 2008 2:52 pm
Post subject: Re: I need to optimize this query [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Oct 09, 2005 Posts: 78
|
(Msg. 4) Posted: Mon Feb 11, 2008 7:08 am
Post subject: Re: I need to optimize this query [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Clustered index seeks are in general more expensive than non-clustered
ones.
Putting the unique index on the clustered key should make things
faster for you. You will need to try this out to verify that it will
work for you!
On Feb 8, 5:52 pm, Nightcrawler wrote:
> Hilary,
>
> Please explain what you are suggesting. I am very curious (and eager
> to learn)...
>
> Thanks >> Stay informed about: I need to optimize this query |
|
| Back to top |
|
 |  |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|