I have a query that takes 5 seconds to run in SQL Server Managment Studio, but it takes 33 seconds in PHP to run the same query using $qid=db_query($countQuery);
Has anyone got any idea why this might be?
We are using SQL Server 2000 which I do not believe is the problem.
[edit]
After doing some profiling we noticed that the execution plans were completely different between the analyzer and the query from PHP. This was done on a single machine, web, sql and query analyzer.
Any Ideas?
Thanks
Ok, I found the problem…well, at least in this case. The problem was the mssql_* that ships with PHP. We tested the new sqlsrv_* which ran a 62 second query (mssql_) in 1.4 seconds so it is definitely much faster.
[edit]
The reason for it running slow in the mssql library was because of duplicate data in our table (which only had two id columns without any constraints on so we never noticed it).
Thanks for all the suggestions!