Multiple queries when there should be only one.

Trying to cut down on the number of queries on my site… Why would a single query run as multiple queries? Is there a way to fix this?

For example, from the following line of code (line 43)…

$model = Menu::model()->findAll();

We can see in my query log that 4 seperate queries were fired…

Or am I just reading this wrong?

That looks like 3 queries. The first two are active record pulling back the structure of the ‘menu’ table, the third item is just a log message, and the fourth is the query that actually pulls back data from the menu table.

Active record will always have some small overhead over straight sql, but the two structure queries are going to be very, very quick.

I don’t know if there are settings that allow yii to cache table structure on production servers. Perhaps someone else could speak to that.

Search for ‘schema caching’. You’ll want that turned on in your DB component and you will also need a cache of some kind turned on in your config file.