Groups | Blog | Home
all groups > sql server full text search > march 2006 >

sql server full text search : FTS in SQL2005 and JOINS


Griff
3/14/2006 12:00:00 AM
I've no idea whether this would work, but have you tried to re-order the
query so that the inner join is the other way around?

Griff

johnsolver NO[at]SPAM gmail.com
3/14/2006 4:29:16 AM
Hi, I'm having a slight problem with some of my FTS queries, namely it
seems that in SQL 2005 the execution plans are constructed by first
doing the normal query and then joining with the FTS results.

For instance:

SELECT P.id,P.name
FROM CONTAINSTABLE(prd_Names,phrase,'"hp*"') F
INNER JOIN prd_Names P ON F.[key]=P.id
ORDER BY P.name,F.rank;

Causes a massive index scan on prd_Names table first and only then
joins with the smaller set returned by CONTAINSTABLE. IIRC in 2000 I
didn't have this problem (I think it was the other way around).

Is there any way to make the query behave properly?

The DTD is very simple prd_Names is a table with 3 columns
id (pkey) int
name varchar(100)
phrase varchar(500)
a clustered index on id
and an index on the name column.

BTW the table contains ~400k rows.

Thanks.
johnsolver NO[at]SPAM gmail.com
3/14/2006 5:59:36 AM
[quoted text, click to view]

Yep, tried that with no effect. I also rewrote it without using the
JOIN statement: WHERE CONTAINS(..) etc. and also WHERE P.id IN (SELECT
.... FROM CONTAINSTABLE()) but neither helped.

Thanks.
johnsolver NO[at]SPAM gmail.com
3/14/2006 7:18:45 AM
[quoted text, click to view]
Because CONTAINSTABLE returns a table with [key],[rank] columns which I
need (afaik it's the normal way to use CONTAINSTABLE)
Griff
3/14/2006 3:02:59 PM
I think I've missed something - why are you doing an inner join in the first
place?

Simon Sabin
4/9/2006 9:30:49 AM
This is a feature of full text on SQL 2000, because full text is a remote
oledb source the optimiser doesn't have any statistics on it and so is not
likely to use it as a filtering source for the query.

You can force it by using a query hint

--
Simon Sabin
SQL Server MVP
http://sqljunkies.com/weblog/simons

[quoted text, click to view]

johnsolver NO[at]SPAM gmail.com
4/11/2006 9:35:02 AM

[quoted text, click to view]
Well I'm using SQL 2005, anyways what query hint should I use?

Thanks.
Simon Sabin
4/11/2006 10:11:59 PM
Have a look at join hints in BOL. It depends on the number of rows you
expect to get back in your contains table statement

--
Simon Sabin
SQL Server MVP
http://sqljunkies.com/weblog/simons

[quoted text, click to view]

johnsolver NO[at]SPAM gmail.com
4/12/2006 6:46:59 AM
[quoted text, click to view]
Many thanks, problem partially solved using the INNER LOOP JOINT hint,
which forced the plan to be built based on the set gotten from the
CONTAINSTABLE, thanks.

On the same note, assuming I have several queries I need to run and all
need to be joined to the same result set from the same containstable
statement, would it make sense to at first insert the results of the
CONTAINSTABLE intto a temp table or @table or a normal table with a
session id.

I've tried it small result sets of around 1-2k rows returned from FTS
and it seems to work ok, however if the FTS returns 15k+ results it
starts to lag badly, which seems a bit weird since without the table I
have to requery the FTS several times...

Thanks.
Kevin English
4/17/2006 4:29:42 PM
Did you put an index on your temp table?

[quoted text, click to view]

AddThis Social Bookmark Button