使用Doctrine Cache [useResultCache函数] + Dql Leftjoin会产生更多查询

时间:2011-09-18 09:52:35

标签: performance zend-framework doctrine

我正在努力加速我的Zendframework应用程序+ Doctrine 1.2,使用:

  1. APC
  2. Doctrine [useQueryCache function]
  3. Doctrine [useResultCache function]
  4. 来自学说documentation

      

    使用结果缓存时,事情变得更好。然后你的查询   进程如下(假设找到有效的缓存条目):

         

    初始化新DQL查询

         

    返回结果集

    Bootstrap.php:启用APC缓存

    if (isset($doctrineConfig['cache']) && $doctrineConfig['cache'] == true) {
                $cacheDriver = new Doctrine_Cache_Apc();
                $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
                $manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $cacheDriver);
                $manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE_LIFESPAN, 1800);
            }
    

    当我添加useResultCache("true")时,它将查询计数从11个增加到18个查询 并且从1.8 m.sec14.82 m.sec

    的时间已经过去了

    这是我的dql查询:

       $q->from("Dagho_Model_History h")
              ->where("h.date BETWEEN ? AND ? ", array($start_of_day, $end_of_day))
              ->leftJoin("h.Order o")
              ->leftJoin("o.Personal p")
              ->leftJoin("o.Domain d")
              ->leftjoin("d.Tld t")
              ->useResultCache(true)
              ->useQueryCache(true);
    

    它破坏了在分离的sql中执行的dql连接部分,我将在两种情况下列出生成的sql:

    - 在使用useResultCache(true)之前 SELECT h.id AS h__id, h.order_id AS h__order_id, h.type AS h__type, h.date AS h__date, h.receipt AS h__receipt, h.dollar AS h__dollar, h.payment AS h__payment, h.profit AS h__profit, h.net_profit AS h__net_profit, h.exchange_diff AS h__exchange_diff, o.id AS o__id, o.domain_id AS o__domain_id, o.hosting_id AS o__hosting_id, o.personal_id AS o__personal_id, o.auth_id AS o__auth_id, o.timestamp AS o__timestamp, o.notes AS o__notes, o.price AS o__price, o.type AS o__type, o.expire_at AS o__expire_at, o.hosting_price AS o__hosting_price, o.domain_price AS o__domain_price, o.extra_fee AS o__extra_fee, o.orderid AS o__orderid, o.root_id AS o__root_id, o.lft AS o__lft, o.rgt AS o__rgt, o.level AS o__level, o.created_at AS o__created_at, p.id AS p__id, p.name AS p__name, p.sex AS p__sex, p.email AS p__email, p.landline AS p__landline, p.mobile AS p__mobile, p.address AS p__address, p.city AS p__city, p.national_number AS p__national_number, p.notes AS p__notes, p.credit AS p__credit, p.stopped AS p__stopped, p.root_id AS p__root_id, p.lft AS p__lft, p.rgt AS p__rgt, p.level AS p__level, p.created_at AS p__created_at, p.updated_at AS p__updated_at, d.id AS d__id, d.name AS d__name, d.sld AS d__sld, d.tld AS d__tld, d.personal_id AS d__personal_id, d.hosting_id AS d__hosting_id, d.tld_id AS d__tld_id, d.registartion AS d__registartion, d.expiration AS d__expiration, d.notes AS d__notes, d.status AS d__status, d.provider AS d__provider, d.domainnameid AS d__domainnameid, d.orderid AS d__orderid, d.os_username AS d__os_username, t.id AS t__id, t.tld AS t__tld, t.price AS t__price, t.dollar AS t__dollar FROM history h LEFT JOIN orders o ON h.order_id = o.id LEFT JOIN personal p ON o.personal_id = p.id LEFT JOIN domain d ON o.domain_id = d.id LEFT JOIN tld t ON d.tld_id = t.id WHERE (h.date BETWEEN ? AND ?)

    • 使用useResultCache(true)

    SELECT p.id AS p__id, p.name AS p__name, p.sex AS p__sex, p.email AS p__email, p.landline AS p__landline, p.mobile AS p__mobile, p.address AS p__address, p.city AS p__city, p.national_number AS p__national_number, p.notes AS p__notes, p.credit AS p__credit, p.stopped AS p__stopped, p.root_id AS p__root_id, p.lft AS p__lft, p.rgt AS p__rgt, p.level AS p__level, p.created_at AS p__created_at, p.updated_at AS p__updated_at FROM personal p WHERE (p.id = ?)

    SELECT d.id AS d__id, d.name AS d__name, d.sld AS d__sld, d.tld AS d__tld, d.personal_id AS d__personal_id, d.hosting_id AS d__hosting_id, d.tld_id AS d__tld_id, d.registartion AS d__registartion, d.expiration AS d__expiration, d.notes AS d__notes, d.status AS d__status, d.provider AS d__provider, d.domainnameid AS d__domainnameid, d.orderid AS d__orderid, d.os_username AS d__os_username FROM domain d WHERE (d.id = ?)

    即它为->leftJoin("o.Personal p")创建sql和                        ->leftJoin("o.Domain d")

    但我无法理解它为什么不创造 ->leftjoin("d.Tld t")

    任何人都可以解释为什么它采用了这个14.82 sec ??

0 个答案:

没有答案