I'm using fulltext to search words within entities... I created an extra table with all the words the entities have and the fulltext searches that table (fulltext.modulesWords).I was making a search and noticed a "strange", or not, behavior...The 3 queries below are my tests... I used the 2nd one has my first approach... It was slow, 10 secs and 400.000 reads..... I started "breaking" the query and noticed that the fulltext alone was very fast and the query without the fulltext was also very fast.... So I went for the 3rd query posted: created a subset with the fulltext ids and joined with the other query.... But the results were the same... SQL is "smart" and converted the query to the same as the 2nd one...So I went for another try... the first query.... 70ms and 3.000 reads!!!!! Can someone explain why this happens?!? The queries are identical...If I execute the same queries without the wildcard in the search words the 2nd and 3rd queries take 2secs and 130.000 reads.. the first one 20ms and 2.500 reads.Thanks,PedroPS: If with the 2nd query I replace the CONTAINS with a LIKE operator and '%maria%' it takes 200ms and 100.000 reads.[code="SQL"]DECLARE @ids TABLE (id BIGINT)INSERT INTO @ids SELECT id FROM fullText.modulesWords WHERE idModule = 7 AND CONTAINS(words, '"maria*"');WITH e AS ( SELECT [idEntity] , ROW_NUMBER() OVER ( ORDER BY TRY_CONVERT(BIGINT, e.reference), [idEntity]) position FROM realEstate.entities e INNER JOIN entities.GetAgentAccessesByActions(4042,61,1) t1 ON e.idNetwork = t1.idNetwork AND e.idCompany = t1.idCompany AND e.idAgency = t1.idAgency WHERE e.idagent = e.idAgent AND [idEntity] IN (SELECT id FROM @ids))SELECT e.* FROM e GO;WITH e AS ( SELECT [idEntity] , ROW_NUMBER() OVER ( ORDER BY TRY_CONVERT(BIGINT, e.reference), [idEntity]) position FROM realEstate.entities e INNER JOIN entities.GetAgentAccessesByActions(4042,61,1) t1 ON e.idNetwork = t1.idNetwork AND e.idCompany = t1.idCompany AND e.idAgency = t1.idAgency WHERE e.idagent = e.idAgent AND [idEntity] IN (SELECT id FROM fullText.modulesWords WHERE idModule = 7 AND CONTAINS(words, '"maria*"')))SELECT e.* FROM e GO;WITH ids AS (SELECT id FROM fullText.modulesWords WHERE idModule = 7 AND CONTAINS(words, '"maria*"')), e AS ( SELECT [idEntity] , ROW_NUMBER() OVER ( ORDER BY TRY_CONVERT(BIGINT, e.reference), [idEntity]) position FROM realEstate.entities e INNER JOIN entities.GetAgentAccessesByActions(4042,61,1) t1 ON e.idNetwork = t1.idNetwork AND e.idCompany = t1.idCompany AND e.idAgency = t1.idAgency WHERE e.idagent = e.idAgent AND [idEntity] IN (SELECT id FROM ids))SELECT e.* FROM e [/code]
↧