The following query runs very slow when running the sql against a SQL Server CE database, I had hoped to translate it to linq for EF. Can anyone advise on this, I haven’t created any indexes on SQL Server CE yet. Table2 has 100,000 rows.
SELECT
*
FROM
Table1 T1a
WHERE
EXISTS
(
SELECT
NULL
FROM
Table2 T2
JOIN Table1 T1b ON T2.Field1 = T2.Field1
WHERE
T2.SomeID = 12345 AND
T1a.SomeString = T1b.SomeString
)
ORDER BY
T1a.SomeString,
T1a.AnotherString
Considering ONLY the information given.
To me
T2.SomeIDwould be the most obvious place to start with an index. After that you might look atT2.Field1because of it’s use in the join (and possiblyT1.Field1depending on the # of rows inT1). The next one is likely going to beT1.SomeStringboth for it’s comparison usage and because it’s being used in a sort.Other than
T2.SomeIDhowever it kind of depends on the makeup of your data, the cardinality of each value, how many rows are in the tables, how many other queries there are. How many updates vs lookups will be done etc. etc. etc.