D
D
Daniil Kostin2015-10-21 10:33:03
Yii
Daniil Kostin, 2015-10-21 10:33:03

Why does SQL query in Yii 1.1.17 slow down hundreds of times compared to direct query?

request:

Yii::app()->getDb()->CreateCommand('
SELECT
  COUNT(DISTINCT `t`.`user_id`)
FROM
  `tbl_profile_profile` `t`
LEFT OUTER JOIN `tbl_user_user` `user` ON (`t`.`user_id` = `user`.`id`)
WHERE
  (
    (
      t.`type` = 0
      AND (`user`.access_level <= 2)
    )
    AND (t.`status` = 2)
  )'
)->execute();

I'm using Yupe 9.3 and Yii 1.1.17
in a table of 200,000 records
Yii Debugger shows time 1882.7 ms - 2177.2 ms
explain:
5b4d4146931845c5b09047c8b7ab1bb5.jpg
MySQL executes it in 0.088s = 88.0 ms
and then the error crept in.
88.0 ms is an EXPLAIN request in the database, not the request itself.
The request itself is completed in about the same time.
Main expense item: Sending data 1.7279970s 93.697%
But it's still a lot.
It turns out only to speed up caching ...
Maybe I missed something else?
Most requests are performed comparable to direct ones, the rest spoil everything.
How to speed up Yii?
Answer: everything is fine with Yii, look for the problem elsewhere.
In this case, the database did not cache some requests, everything was accelerated by tuning the database.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-10-21
Protko @Fesor

because yii should map the results to entities. Although he does it quickly, but taking into account the left outer join and the number of rows ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question