I have the following query that performs left join between 3 tables. The problem is that it takes 20 seconds to run, even if only few rows are returned. If I leave out the "largefields" from the offer table the query executes almost instantly. So it appears that the problem is that for some reason the sqlserver fetches the values of those fields before it applies the where statement. Is there any way to make this query execute faster?
SELECT N0."OID"
,N1."FirstName"
,N1."LastName"
,N0."SmallField"
,N0."LargeField1"
,N0."LargeField2"
FROM (
(
"dbo"."Offer" N0 LEFT JOIN "dbo"."Address" N1 ON (N0."OfferDeliveryAddress" = N1."OID")
) LEFT JOIN "dbo"."Customer" N2 ON (N0."Customer" = N2."OID")
)
WHERE (
N0."GCRecord" IS NULL
AND (
(isnull(CharIndex('John Smith', N2."FirstName" + ' ' + N2."LastName"), 0) > 0)
OR (isnull(CharIndex('John Smith', N2."LastName" + ' ' + N2."FirstName"), 0) > 0)
OR (isnull(CharIndex('John Smith', N2."FirstName"), 0) > 0)
OR (isnull(CharIndex('John Smith', N2."LastName"), 0) > 0)
)
)
Aucun commentaire:
Enregistrer un commentaire