<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
    <title>Magento Issue Tracking</title>
    <link>http://www.magentocommerce.com/bug-tracking/</link>
    <description></description>
    <dc:language>en</dc:language>
    <dc:creator>MagentoCommerce</dc:creator>
    <dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
    <dc:date>{gmt_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
    <admin:generatorAgent rdf:resource="http://expressionengine.com/" />
        <item>
        <title>View Issue #10961 / DescribeTable() uses unnecessary queries -- fix in</title>
        <link>http://www.magentocommerce.com/bug-tracking/issue?issue=5222</link>
        <description><![CDATA[<strong>Posted:</strong> 2009-02-13 01:30:14<br/><strong>Category:</strong> Orders<br/><strong>Version:</strong> 1.2.1<br/><strong>Priority:</strong> high<br/><strong>Status:</strong> closed<br/><strong>Reported By:</strong> <a href="http://www.magentocommerce.com/boards/member/49808/">ShopGuy</a></strong><br/><br/>lib/Zend/Db/Adapter/Pdo/MySql.php:describeTable() is called a LOT in magento. In order to decrease db load, query latency, etc this function should be cached. If 2 second old describe query info cannot be trusted, then neither can 1/10 second describe table information, so caching is appropriate. Here is the new function that caches data appropriately:<br />
<br />
public function describeTable($tableName, $schemaName = null)<br />
    {<br />
        // begin changes<br />
        static $cache = array();<br />
        <br />
        // get current connection config<br />
        $config = $this-&gt;getConfig(); <br />
        <br />
        // create database cache if needed<br />
        if (array_key_exists($config['dbname'], $cache) === false) { <br />
            $cache[$config['dbname']] = array();<br />
        }<br />
        <br />
        // IF table cache does not exist then create it<br />
        // ELSE return cache value instead of continuing execution<br />
        $cacheKey = $tableName . '~~' . (string) $schemaName;<br />
        if (array_key_exists($cacheKey, $cache[$config['dbname']]) === false) { <br />
            $cache[$config['dbname']][$cacheKey] = array();<br />
        } elseif ((time() - $cache[$config['dbname']][$cacheKey]['cache_time']) &lt;= 2) {<br />
            return $cache[$config['dbname']][$cacheKey]['value'];<br />
        }<br />
        // end changes<br />
<br />
        // @todo  use INFORMATION_SCHEMA someday when MySQL's<br />
        // implementation has reasonably good performance and<br />
        // the version with this improvement is in wide use.<br />
<br />
        if ($schemaName) {<br />
            $sql = 'DESCRIBE ' . $this-&gt;quoteIdentifier(&quot;$schemaName.$tableName&quot;, true);<br />
        } else {<br />
            $sql = 'DESCRIBE ' . $this-&gt;quoteIdentifier($tableName, true);<br />
        }<br />
        $stmt = $this-&gt;query($sql);<br />
<br />
        // Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection<br />
        $result = $stmt-&gt;fetchAll(Zend_Db::FETCH_NUM);<br />
<br />
        $field   = 0;<br />
        $type    = 1;<br />
        $null    = 2;<br />
        $key     = 3;<br />
        $default = 4;<br />
        $extra   = 5;<br />
<br />
        $desc = array();<br />
        $i = 1;<br />
        $p = 1;<br />
        foreach ($result as $row) {<br />
            list($length, $scale, $precision, $unsigned, $primary, $primaryPosition, $identity)<br />
                = array(null, null, null, null, false, null, false);<br />
            if (preg_match('/unsigned/', $row[$type])) {<br />
                $unsigned = true;<br />
            }<br />
            if (preg_match('/^((?:var)?char)((d+))/', $row[$type], $matches)) {<br />
                $row[$type] = $matches[1];<br />
                $length = $matches[2];<br />
            } else if (preg_match('/^decimal((d+),(d+))/', $row[$type], $matches)) {<br />
                $row[$type] = 'decimal';<br />
                $precision = $matches[1];<br />
                $scale = $matches[2];<br />
            } else if (preg_match('/^((?:big|medium|small|tiny)?int)((d+))/', $row[$type], $matches)) {<br />
                $row[$type] = $matches[1];<br />
                // The optional argument of a MySQL int type is not precision<br />
                // or length; it is only a hint for display width.<br />
            }<br />
            if (strtoupper($row[$key]) == 'PRI') {<br />
                $primary = true;<br />
                $primaryPosition = $p;<br />
                if ($row[$extra] == 'auto_increment') {<br />
                    $identity = true;<br />
                } else {<br />
                    $identity = false;<br />
                }<br />
                ++$p;<br />
            }<br />
            $desc[$this-&gt;foldCase($row[$field])] = array(<br />
                'SCHEMA_NAME'      =&gt; null, // @todo<br />
                'TABLE_NAME'       =&gt; $this-&gt;foldCase($tableName),<br />
                'COLUMN_NAME'      =&gt; $this-&gt;foldCase($row[$field]),<br />
                'COLUMN_POSITION'  =&gt; $i,<br />
                'DATA_TYPE'        =&gt; $row[$type],<br />
                'DEFAULT'          =&gt; $row[$default],<br />
                'NULLABLE'         =&gt; (bool) ($row[$null] == 'YES'),<br />
                'LENGTH'           =&gt; $length,<br />
                'SCALE'            =&gt; $scale,<br />
                'PRECISION'        =&gt; $precision,<br />
                'UNSIGNED'         =&gt; $unsigned,<br />
                'PRIMARY'          =&gt; $primary,<br />
                'PRIMARY_POSITION' =&gt; $primaryPosition,<br />
                'IDENTITY'         =&gt; $identity<br />
            );<br />
            ++$i;<br />
        }<br />
        <br />
        // begin changes<br />
        $cache[$config['dbname']][$cacheKey] = array('cache_time' =&gt; time(), 'value' =&gt; $desc);<br />
        // end changes<br />
        <br />
        return $desc;<br />
    }<br/><br/><hr/>]]></description>
    </item>
    
                    <item>
        <title>RE: DescribeTable() uses unnecessary queries -- fix in</title>
        <description><![CDATA[<em>#1 / Comment by Magento Team</em><br/><br/>Hello ShopGuy,<br />
<br />
This issue was fixed. Please check the latest Magento release at http://www.magentocommerce.com/download/<br />
<br />
Thank you.]]></description>
    </item>
        </channel>
</rss>