Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lots of DESCRIBE queries in Zend Framework

I just set up FirePHP in Zend and I'm noticing a huge number of DESCRIBE queries. Some pages have 50 or more identical queries all on the same table. e.g.

0.00198     connect      NULL
0.00449 DESCRIBE `nodes`    NULL
0.00041 SELECT `nodes`.* FROM `nodes` WHERE (((`nodes`.`id` = 111)))    NULL
0.0037  DESCRIBE `nodes`    NULL
0.00155 SELECT `nodes`.* FROM `nodes` WHERE (((`nodes`.`id` = 111)))    NULL
0.00059 SELECT `nodes`.* FROM `nodes` WHERE (parent_id = '111') ORDER BY `order` ASC, `id` ASC  NULL
0.00366 DESCRIBE `nodes`    NULL
0.0054  DESCRIBE `nodes`    NULL
0.0049  DESCRIBE `nodes`    NULL
0.00519 DESCRIBE `nodes`    NULL
0.00492 DESCRIBE `nodes`    NULL
0.00691 DESCRIBE `nodes`    NULL
0.00741 DESCRIBE `nodes`    NULL
0.0048  DESCRIBE `nodes`    NULL
0.00556 DESCRIBE `nodes`    NULL
0.00516 DESCRIBE `nodes`    NULL
0.00487 DESCRIBE `nodes`    NULL

...and it goes on.

Are all those DESCRIBE queries generated by the framework (I'm using Zend_DbTable)? Are they all necessary? Should I be worried about them or are they not likely to be impacting performance?

like image 786
Tamlyn Avatar asked Feb 09 '10 15:02

Tamlyn


2 Answers

Those queries are executed by Zend_Db_Table to detect the schema of the tables. You can ask Zend_Db_Table to cache the results using a Zend_Cache to prevent constant calls, but bare that in mind if you change the schema.

You can do so by using:

Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
like image 67
Johnco Avatar answered Sep 23 '22 06:09

Johnco


Zend_Db_Adapter_Abstract::describeTable() does these queries to get the Metadata of your tables when using Zend_Db_Table This is used for instance when you do not specify a primary key explicitly. You can enable the MetaData cache or just use Zend_Db instead of Zend_Db_Table.

I think you should not have this many describe queries though. Once a Zend_Db_Table instance is set up, it will store the metadata after the first query for the remaining request. Try to use Zend_Debugger or Xdebug to find out what's causing this.

See

  • ZF API entry for Zend_Db_Adapter_Abstact::describeTable()
  • ZF manual entry for List and Describe Tables in Zend_Db_Adapter
  • ZF manual entry for Zend_Db_Table with additional background info on metadata
like image 32
Gordon Avatar answered Sep 25 '22 06:09

Gordon